[PATCH] D46622: wrong usages of sem_open in the libFuzzer
Yang Zheng via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue May 8 19:27:43 PDT 2018
tomsun.0.7 created this revision.
tomsun.0.7 added reviewers: vitalybuka, krytarowski.
Herald added a subscriber: llvm-commits.
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 page <http://pubs.opengroup.org/onlinepubs/9699919799/functions/sem_open.html>). Actually, SEM_FAILED != (void *)-1 holds in NetBSD.
- The SharedMemoryRegion::SecName function should return name starting with slash. Because the behaviour of name which does not start with slash is unspecified as the "DESCRIPTION" section <http://pubs.opengroup.org/onlinepubs/9699919799/functions/sem_open.html> 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.
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,8 @@
std::string SharedMemoryRegion::SemName(const char *Name, int Idx) {
std::string Res(Name);
+ if (!Res.empty() && Res[0] != '/')
+ Res.insert(Res.begin(), '/');
return Res + (char)('0' + Idx);
}
@@ -52,7 +54,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 +72,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.145839.patch
Type: text/x-patch
Size: 1650 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180509/3fca5057/attachment-0001.bin>
More information about the llvm-commits
mailing list