You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by as...@apache.org on 2018/12/11 05:25:01 UTC

qpid-proton git commit: PROTON-1983, PROTON-1805: Allow fuzzer regression tests to use response files - Fixed bugs which make the standalone regression runner fail on Windows and Mac - Allow fuzz tests to build under VS12 & VS10

Repository: qpid-proton
Updated Branches:
  refs/heads/master 5ba471d97 -> 3b1edb510


PROTON-1983, PROTON-1805: Allow fuzzer regression tests to use response files
- Fixed bugs which make the standalone regression runner fail on Windows and Mac
- Allow fuzz tests to build under VS12 & VS10


Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/3b1edb51
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/3b1edb51
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/3b1edb51

Branch: refs/heads/master
Commit: 3b1edb510290d771c3c554ab634031c840a45691
Parents: 5ba471d
Author: Andrew Stitcher <as...@apache.org>
Authored: Fri Dec 7 15:28:02 2018 -0500
Committer: Andrew Stitcher <as...@apache.org>
Committed: Mon Dec 10 23:51:23 2018 -0500

----------------------------------------------------------------------
 CMakeLists.txt                          |  8 ----
 c/src/core/autodetect.h                 |  8 ++++
 c/tests/fuzz/CMakeLists.txt             | 19 +++++++-
 c/tests/fuzz/StandaloneFuzzTargetInit.c | 70 ++++++++++++++++++++++++++++
 c/tests/fuzz/StandaloneFuzzTargetMain.c |  6 +--
 c/tests/fuzz/fuzz-connection-driver.c   |  2 +-
 6 files changed, 100 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/3b1edb51/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 04b0ed2..83c24e8 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -114,16 +114,8 @@ endif()
 if (APPLE)
   set (NOENABLE_WARNING_ERROR ON)
   set (NOENABLE_UNDEFINED_ERROR ON)
-  # TODO: Currently segfaults on MacOS - fix bug and re-enable
-  set (NOENABLE_FUZZ_TESTING ON)
 endif (APPLE)
 
-# TODO: Can't build fuzz tests/or run regression tests on MSVC currently
-# (due to limit on command line length)
-if (MSVC)
-  set (NOENABLE_FUZZ_TESTING ON)
-endif (MSVC)
-
 # Make LTO default to off until we can figure out the valgrind issues
 set (NOENABLE_LINKTIME_OPTIMIZATION ON)
 

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/3b1edb51/c/src/core/autodetect.h
----------------------------------------------------------------------
diff --git a/c/src/core/autodetect.h b/c/src/core/autodetect.h
index 12cb7d8..17879db 100644
--- a/c/src/core/autodetect.h
+++ b/c/src/core/autodetect.h
@@ -34,7 +34,15 @@ typedef enum {
   PNI_PROTOCOL_AMQP_OTHER
 } pni_protocol_type_t;
 
+#if __cplusplus
+extern "C" {
+#endif
+
 pni_protocol_type_t pni_sniff_header(const char *data, size_t len);
 const char* pni_protocol_name(pni_protocol_type_t p);
 
+#if __cplusplus
+}
+#endif
+
 #endif

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/3b1edb51/c/tests/fuzz/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/c/tests/fuzz/CMakeLists.txt b/c/tests/fuzz/CMakeLists.txt
index 9880bdc..b4470d5 100644
--- a/c/tests/fuzz/CMakeLists.txt
+++ b/c/tests/fuzz/CMakeLists.txt
@@ -33,16 +33,24 @@ add_library (StandaloneFuzzTargetMain STATIC StandaloneFuzzTargetMain.c Standalo
 macro (pn_add_fuzz_test test)
   add_executable (${test} ${ARGN})
   target_link_libraries (${test} qpid-proton-core ${FUZZING_LIBRARY})
+  list(APPEND fuzz_test_src ${ARGN})
 
   if (FUZZ_REGRESSION_TESTS)
     # StandaloneFuzzTargetMain cannot walk directory trees
     file(GLOB_RECURSE files ${CMAKE_CURRENT_SOURCE_DIR}/${test}/*)
-    add_test (NAME ${test} COMMAND ${TEST_EXE_PREFIX_CMD} $<TARGET_FILE:${test}> ${files})
+    unset(file_lines)
+    foreach(f IN LISTS files)
+      set(file_lines "${file_lines}${f}\n")
+    endforeach()
+    file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/${test}-files" "${file_lines}")
+    add_test (NAME ${test} COMMAND ${test_env} ${TEST_EXE_PREFIX_CMD} $<TARGET_FILE:${test}> "@${CMAKE_CURRENT_BINARY_DIR}/${test}-files")
   else ()
     add_test (NAME ${test} COMMAND $<TARGET_FILE:${test}> -runs=1 ${CMAKE_CURRENT_SOURCE_DIR}/${test}>)
   endif ()
 endmacro(pn_add_fuzz_test)
 
+unset(fuzz_test_src)
+
 # Fuzz tests at the User API level
 pn_add_fuzz_test (fuzz-connection-driver fuzz-connection-driver.c)
 pn_add_fuzz_test (fuzz-message-decode fuzz-message-decode.c)
@@ -60,3 +68,12 @@ endif()
 
 # pni_sniff_header is internal so it has to be compiled specially
 pn_add_fuzz_test (fuzz-sniff-header fuzz-sniff-header.c ${PN_C_SOURCE_DIR}/core/autodetect.c)
+
+if (BUILD_WITH_CXX)
+  set_source_files_properties (
+    StandaloneFuzzTargetMain.c
+    StandaloneFuzzTargetInit.c
+    ${fuzz_test_src}
+    PROPERTIES LANGUAGE CXX
+  )
+endif (BUILD_WITH_CXX)

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/3b1edb51/c/tests/fuzz/StandaloneFuzzTargetInit.c
----------------------------------------------------------------------
diff --git a/c/tests/fuzz/StandaloneFuzzTargetInit.c b/c/tests/fuzz/StandaloneFuzzTargetInit.c
index 4c6293c..e1bd6bd 100644
--- a/c/tests/fuzz/StandaloneFuzzTargetInit.c
+++ b/c/tests/fuzz/StandaloneFuzzTargetInit.c
@@ -19,8 +19,78 @@
  *
  */
 
+#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "libFuzzingEngine.h"
+
+/*
+ * Use this to implement response file:
+ * - Check if there is one file mentioned and its name starts with '@'
+ * - If so then read the file line by line making up the new argv
+ * - Modify argc/argv then return.
+ *
+ * Problem: Somehow need to free buf and nargv to avoid sanitizer warnings
+ */
+
+/* Free allocated memory at program exit to avoid the leak sanitizer complaining  */
+static char *buf = 0;
+static char **nargv = 0;
+
+static void freeall(void)
+{
+  free(buf);
+  free(nargv);
+}
+
 int LLVMFuzzerInitialize(int *argc, char ***argv)
 {
+  if (*argc==2 && (*argv)[1][0]=='@') {
+    const char* rfilename = (*argv)[1]+1;
+
+    /* Read entire file into memory */
+    fprintf(stderr, "Reading response file: %s\n", rfilename);
+    FILE *f = fopen(rfilename, "rb");
+    assert(f);
+    fseek(f, 0, SEEK_END);
+    size_t len = ftell(f);
+    fseek(f, 0, SEEK_SET);
+    buf = (char*)malloc(len+1);
+    size_t n_read = fread(buf, 1, len, f);
+    fclose(f);
+    assert(n_read == len);
+    buf[len] = '\0';
+
+    /* scan file counting lines and replacing line ends with \0 */
+    int line = 0;
+    char *p = buf;
+    while (p<&buf[len]) {
+      p += strcspn(p, "\n\r ");
+      *p++ = '\0';
+      line +=1;
+    };
+
+    fprintf(stderr, "        response file: (%zd bytes, %d lines)\n", n_read, line);
+
+    /* scan again putting each line into the argv array */
+    nargv = (char**) calloc(line+1, sizeof(p));
+
+    p = buf;
+    line = 1;
+    do {
+        char* s = p;
+        int l = strlen(p);
+        p += l+1;
+        if (l>0) nargv[line++] = s;
+    } while (p<&buf[len]);
+
+    int nargc = line;
+    *argc = nargc;
+    *argv = nargv;
+    atexit(&freeall);
+  }
   return 0;
 }
 

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/3b1edb51/c/tests/fuzz/StandaloneFuzzTargetMain.c
----------------------------------------------------------------------
diff --git a/c/tests/fuzz/StandaloneFuzzTargetMain.c b/c/tests/fuzz/StandaloneFuzzTargetMain.c
index 0138745..38d007e 100644
--- a/c/tests/fuzz/StandaloneFuzzTargetMain.c
+++ b/c/tests/fuzz/StandaloneFuzzTargetMain.c
@@ -18,8 +18,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 
-extern int LLVMFuzzerInitialize(int *argc, char ***argv);
-extern int LLVMFuzzerTestOneInput(const unsigned char *data, size_t size);
+#include "libFuzzingEngine.h"
 
 int main(int argc, char **argv) {
   fprintf(stderr, "StandaloneFuzzTargetMain: running %d inputs\n", argc - 1);
@@ -27,13 +26,14 @@ int main(int argc, char **argv) {
 
   for (int i = 1; i < argc; i++) {
     fprintf(stderr, "Running: %s\n", argv[i]);
-    FILE *f = fopen(argv[i], "r");
+    FILE *f = fopen(argv[i], "rb");
     assert(f);
     fseek(f, 0, SEEK_END);
     size_t len = ftell(f);
     fseek(f, 0, SEEK_SET);
     unsigned char *buf = (unsigned char*)malloc(len);
     size_t n_read = fread(buf, 1, len, f);
+    fclose(f);
     assert(n_read == len);
     LLVMFuzzerTestOneInput(buf, len);
     free(buf);

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/3b1edb51/c/tests/fuzz/fuzz-connection-driver.c
----------------------------------------------------------------------
diff --git a/c/tests/fuzz/fuzz-connection-driver.c b/c/tests/fuzz/fuzz-connection-driver.c
index dcc5757..506a83b 100644
--- a/c/tests/fuzz/fuzz-connection-driver.c
+++ b/c/tests/fuzz/fuzz-connection-driver.c
@@ -62,7 +62,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
   if (VERBOSE)
     printf("BEGIN LLVMFuzzerTestOneInput\n");
   app_data_t app = {{0}};
-  snprintf(app.container_id, sizeof(app.container_id), "%s:%06x",
+  sprintf(app.container_id, "%s:%06x",
            "fuzz_connection_driver", rand() & 0xffffff);
 
   pn_connection_driver_t driver;


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org