[compiler-rt] r332003 - wrong usages of sem_open in the libFuzzer

Kamil Rytarowski via llvm-commits llvm-commits at lists.llvm.org
Thu May 10 10:31:06 PDT 2018


Author: kamil
Date: Thu May 10 10:31:06 2018
New Revision: 332003

URL: http://llvm.org/viewvc/llvm-project?rev=332003&view=rev
Log:
wrong usages of sem_open in the libFuzzer

Summary:
Fixed two non-standard usages of sem_open in the libFuzzer library and
one NetBSD-related modification with test script.


  - The return value to indicate error should be SEM_FAILED instead of
    (void *)-1 (please refer to "RETURN VALUE" section in this [[
    http://pubs.opengroup.org/onlinepubs/9699919799/functions/sem_open.html
    | page ]]). Actually, SEM_FAILED != (void *)-1 holds in NetBSD.

  - The SharedMemoryRegion::SemName function should return name
    starting with slash. Because the behaviour of name which does not
    start with slash is unspecified as the [[
    http://pubs.opengroup.org/onlinepubs/9699919799/functions/sem_open.html
    | "DESCRIPTION" section ]] specified:

> If name does not begin with the <slash> character, the effect is implementation-defined.

  - The length of name is limited to 14 in NetBSD, it is suggested to
    reduce the length of equivalence server name in the test script.

Patch by: Yang Zheng

Reviewers: vitalybuka, krytarowski, kcc

Reviewed By: kcc

Subscribers: kcc, #sanitizers, llvm-commits, joerg

Differential Revision: https://reviews.llvm.org/D46622


Modified:
    compiler-rt/trunk/lib/fuzzer/FuzzerShmemPosix.cpp
    compiler-rt/trunk/test/fuzzer/equivalence-signals.test

Modified: compiler-rt/trunk/lib/fuzzer/FuzzerShmemPosix.cpp
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/fuzzer/FuzzerShmemPosix.cpp?rev=332003&r1=332002&r2=332003&view=diff
==============================================================================
--- compiler-rt/trunk/lib/fuzzer/FuzzerShmemPosix.cpp (original)
+++ compiler-rt/trunk/lib/fuzzer/FuzzerShmemPosix.cpp Thu May 10 10:31:06 2018
@@ -32,6 +32,11 @@ std::string SharedMemoryRegion::Path(con
 
 std::string SharedMemoryRegion::SemName(const char *Name, int Idx) {
   std::string Res(Name);
+  // When passing a name without a leading <slash> character to
+  // sem_open, the behaviour is unspecified in POSIX. Add a leading
+  // <slash> character for the name if there is no such one.
+  if (!Res.empty() && Res[0] != '/')
+    Res.insert(Res.begin(), '/');
   return Res + (char)('0' + Idx);
 }
 
@@ -52,7 +57,7 @@ bool SharedMemoryRegion::Create(const ch
   for (int i = 0; i < 2; i++) {
     sem_unlink(SemName(Name, i).c_str());
     Semaphore[i] = sem_open(SemName(Name, i).c_str(), O_CREAT, 0644, 0);
-    if (Semaphore[i] == (void *)-1)
+    if (Semaphore[i] == SEM_FAILED)
       return false;
   }
   IAmServer = true;
@@ -70,7 +75,7 @@ bool SharedMemoryRegion::Open(const char
     return false;
   for (int i = 0; i < 2; i++) {
     Semaphore[i] = sem_open(SemName(Name, i).c_str(), 0);
-    if (Semaphore[i] == (void *)-1)
+    if (Semaphore[i] == SEM_FAILED)
       return false;
   }
   IAmServer = false;

Modified: compiler-rt/trunk/test/fuzzer/equivalence-signals.test
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/fuzzer/equivalence-signals.test?rev=332003&r1=332002&r2=332003&view=diff
==============================================================================
--- compiler-rt/trunk/test/fuzzer/equivalence-signals.test (original)
+++ compiler-rt/trunk/test/fuzzer/equivalence-signals.test Thu May 10 10:31:06 2018
@@ -7,7 +7,7 @@ UNSUPPORTED: freebsd
 UNSUPPORTED: darwin
 
 RUN: %cpp_compiler %S/EquivalenceATest.cpp -o %t-EquivalenceATest
-RUN: %t-EquivalenceATest -timeout=1 -run_equivalence_server=EQUIV_SIG_TEST & export APID=$!
+RUN: %t-EquivalenceATest -timeout=1 -run_equivalence_server=EQ_SIG_TEST & export APID=$!
 RUN: sleep 3
-RUN: %t-EquivalenceATest -timeout=1 -use_equivalence_server=EQUIV_SIG_TEST -runs=500000 2>&1
+RUN: %t-EquivalenceATest -timeout=1 -use_equivalence_server=EQ_SIG_TEST -runs=500000 2>&1
 RUN: kill -9 $APID




More information about the llvm-commits mailing list