예제 #1
0
int
main()
{
        long pagesize = sysconf(_SC_PAGESIZE);
        CHECK_NE(-1, pagesize);

        const struct sigaction sa = {
                .sa_sigaction = sigsegv,
                .sa_flags = SA_SIGINFO,
        };
        CHECK_EQ(0, sigaction(SIGSEGV, &sa, NULL));
        CHECK_EQ(0, sigaction(SIGBUS, &sa, NULL));

        volatile char *p = mmap(NULL, pagesize, PROT_READ,
	    MAP_PRIVATE|MAP_ANON, -1, 0);
        CHECK_NE(MAP_FAILED, p);

        if (sigsetjmp(env, 1) == 0) {
		p[0] = 1;
                FAIL();
        }
	checksig(SIGSEGV, SEGV_ACCERR, p);

	CHECK_EQ(0, mprotect((void *)p, pagesize, PROT_NONE));
        if (sigsetjmp(env, 1) == 0) {
		(void)p[1];
                FAIL();
        }
	checksig(SIGSEGV, SEGV_ACCERR, p + 1);

	CHECK_EQ(0, munmap((void *)p, pagesize));
        if (sigsetjmp(env, 1) == 0) {
		(void)p[2];
                FAIL();
        }
	checksig(SIGSEGV, SEGV_MAPERR, p + 2);

	char filename[] = "/tmp/siginfo-fault.XXXXXXXX";
	int fd = mkstemp(filename);
	CHECK_GE(fd, 0);
	CHECK_EQ(0, unlink(filename));
	CHECK_EQ(0, ftruncate(fd, 0));  /* just in case */
	p = mmap(NULL, pagesize, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
	CHECK_NE(MAP_FAILED, p);
	CHECK_EQ(0, close(fd));

	if (sigsetjmp(env, 1) == 0) {
		p[3] = 1;
		FAIL();
	}
	checksig(SIGBUS, BUS_ADRERR, p + 3);

        return (0);
}
예제 #2
0
int
downloadchecksig(struct repoinfo *cinfo, FILE *fp, const char *sigurl, Pool **sigpool)
{
  FILE *sigfp;
  sigfp = curlfopen(cinfo, sigurl, 0, 0, 0, 0); 
  if (!sigfp)
    {    
      printf(" unsigned, skipped\n");
      return 0;
    }    
  if (!*sigpool)
    *sigpool = read_sigs();
  if (!checksig(*sigpool, fp, sigfp))
    {    
      printf(" checksig failed, skipped\n");
      fclose(sigfp);
      return 0;
    }    
  fclose(sigfp);
  return 1;
}