[PATCH] D46622: wrong usages of sem_open in the libFuzzer

Yang Zheng via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed May 9 23:47:29 PDT 2018


tomsun.0.7 updated this revision to Diff 146072.

Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D46622

Files:
  lib/fuzzer/FuzzerShmemPosix.cpp
  test/fuzzer/equivalence-signals.test


Index: test/fuzzer/equivalence-signals.test
===================================================================
--- test/fuzzer/equivalence-signals.test
+++ test/fuzzer/equivalence-signals.test
@@ -7,7 +7,7 @@
 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
Index: lib/fuzzer/FuzzerShmemPosix.cpp
===================================================================
--- lib/fuzzer/FuzzerShmemPosix.cpp
+++ lib/fuzzer/FuzzerShmemPosix.cpp
@@ -32,6 +32,11 @@
 
 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 @@
   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 @@
     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;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D46622.146072.patch
Type: text/x-patch
Size: 1847 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180510/4db1380b/attachment.bin>


More information about the llvm-commits mailing list