[llvm] r262757 - [libfuzzer] adding std:string to allowed adaptable argument.
Mike Aizatsky via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 4 15:18:01 PST 2016
Author: aizatsky
Date: Fri Mar 4 17:18:01 2016
New Revision: 262757
URL: http://llvm.org/viewvc/llvm-project?rev=262757&view=rev
Log:
[libfuzzer] adding std:string to allowed adaptable argument.
Modified:
llvm/trunk/lib/Fuzzer/FuzzerFnAdapter.h
llvm/trunk/lib/Fuzzer/test/FuzzerFnAdapterUnittest.cpp
Modified: llvm/trunk/lib/Fuzzer/FuzzerFnAdapter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/FuzzerFnAdapter.h?rev=262757&r1=262756&r2=262757&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/FuzzerFnAdapter.h (original)
+++ llvm/trunk/lib/Fuzzer/FuzzerFnAdapter.h Fri Mar 4 17:18:01 2016
@@ -92,6 +92,17 @@ size_t UnpackSingle<std::vector<uint8_t>
return Size - Len - 1;
}
+template <>
+size_t UnpackSingle<std::string>(const uint8_t *Data, size_t Size,
+ std::string *Value) {
+ if (Size < 1)
+ return Size;
+ size_t Len = std::min(static_cast<size_t>(*Data), Size - 1);
+ std::string S(Data + 1, Data + 1 + Len);
+ Value->swap(S);
+ return Size - Len - 1;
+}
+
// Unpacking into arbitrary tuple.
// Recursion guard.
Modified: llvm/trunk/lib/Fuzzer/test/FuzzerFnAdapterUnittest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/test/FuzzerFnAdapterUnittest.cpp?rev=262757&r1=262756&r2=262757&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/test/FuzzerFnAdapterUnittest.cpp (original)
+++ llvm/trunk/lib/Fuzzer/test/FuzzerFnAdapterUnittest.cpp Fri Mar 4 17:18:01 2016
@@ -70,6 +70,15 @@ TEST(Unpack, Vector) {
EXPECT_EQ(8, V[1]);
}
+TEST(Unpack, String) {
+ std::tuple<std::string> T;
+ const auto &S = std::get<0>(T);
+
+ EXPECT_TRUE(Unpack(&T, {2, 3}));
+ EXPECT_EQ(1ul, S.size());
+ EXPECT_EQ(3, S[0]);
+}
+
template <typename Fn>
bool UnpackAndApply(Fn F, std::initializer_list<uint8_t> Data) {
std::vector<uint8_t> V(Data);
More information about the llvm-commits
mailing list