Skip to content

Commit

Permalink
[libFuzzer] make shmem more robust in the presence of signals
Browse files Browse the repository at this point in the history
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293339 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
kcc committed Jan 27, 2017
1 parent 4512044 commit 001f567
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/Fuzzer/FuzzerShmemPosix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,13 @@ void SharedMemoryRegion::Post(int Idx) {

void SharedMemoryRegion::Wait(int Idx) {
assert(Idx == 0 || Idx == 1);
if (sem_wait((sem_t*)Semaphore[Idx])) {
Printf("ERROR: sem_wait failed\n");
exit(1);
for (int i = 0; i < 10 && sem_wait((sem_t*)Semaphore[Idx]); i++) {
// sem_wait may fail if interrupted by a signal.
sleep(i);
if (i)
Printf("%s: sem_wait[%d] failed %s\n", i < 9 ? "WARNING" : "ERROR", i,
strerror(errno));
if (i == 9) abort();
}
}

Expand Down
10 changes: 10 additions & 0 deletions lib/Fuzzer/test/equivalence.test
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,13 @@ RUN: not LLVMFuzzer-EquivalenceBTest -use_equivalence_server=EQUIV_TEST 2>&1 | F
CHECK: ERROR: libFuzzer: equivalence-mismatch. Sizes: {{.*}}; offset 2
CHECK: SUMMARY: libFuzzer: equivalence-mismatch
RUN: kill -9 $APID


# Run EquivalenceATest against itself with a small timeout
# to stress the signal handling and ensure that shmem doesn't mind
# the signals.

RUN: LLVMFuzzer-EquivalenceATest -timeout=1 -run_equivalence_server=EQUIV_TEST & export APID=$!
RUN: sleep 3
RUN: LLVMFuzzer-EquivalenceATest -timeout=1 -use_equivalence_server=EQUIV_TEST -runs=500000 2>&1
RUN: kill -9 $APID

0 comments on commit 001f567

Please sign in to comment.