From 083c8c6801967a29f0105e76fc79e4589df5caa1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20R=C3=BChsen?= Date: Thu, 13 Jul 2017 16:30:52 +0200 Subject: [PATCH] Fix a few C89 issues --- fuzz/libpsl_fuzzer.c | 14 +++++++------- fuzz/libpsl_load_dafsa_fuzzer.c | 13 +++++++------ fuzz/libpsl_load_fuzzer.c | 13 +++++++------ fuzz/main.c | 8 +++++--- 4 files changed, 26 insertions(+), 22 deletions(-) diff --git a/fuzz/libpsl_fuzzer.c b/fuzz/libpsl_fuzzer.c index fdf3a40..ef6a6ef 100644 --- a/fuzz/libpsl_fuzzer.c +++ b/fuzz/libpsl_fuzzer.c @@ -24,10 +24,10 @@ #include -#include // assert -#include // uint8_t -#include // malloc, free -#include // memcpy +#include /* assert */ +#include /* uint8_t */ +#include /* malloc, free */ +#include /* memcpy */ #if defined(WITH_LIBICU) #include @@ -39,16 +39,16 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { static int first_run = 1; + psl_ctx_t *psl; char *domain = (char *) malloc(size + 1), *res; int rc; assert(domain != NULL); - // 0 terminate + /* 0 terminate */ memcpy(domain, data, size); domain[size] = 0; - psl_ctx_t *psl; psl = (psl_ctx_t *) psl_builtin(); psl_is_public_suffix(psl, domain); @@ -84,7 +84,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) free(domain); #if defined(WITH_LIBICU) - u_cleanup(); // free all library internal memory to avoid memory leaks being reported + u_cleanup(); /* free all library internal memory to avoid memory leaks being reported */ #endif return 0; diff --git a/fuzz/libpsl_load_dafsa_fuzzer.c b/fuzz/libpsl_load_dafsa_fuzzer.c index b14d5cd..b50d006 100644 --- a/fuzz/libpsl_load_dafsa_fuzzer.c +++ b/fuzz/libpsl_load_dafsa_fuzzer.c @@ -24,16 +24,18 @@ #include -#include // assert -#include // uint8_t -#include // malloc, free -#include // memcpy +#include /* assert */ +#include /* uint8_t */ +#include /* malloc, free */ +#include /* memcpy */ #include "libpsl.h" #include "fuzzer.h" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { + FILE *fp; + psl_ctx_t *psl; char *in = (char *) malloc(size + 16); assert(in != NULL); @@ -42,10 +44,9 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) memcpy(in, ".DAFSA@PSL_0 \n", 16); memcpy(in + 16, data, size); - FILE *fp = fmemopen(in, size + 16, "r"); + fp = fmemopen(in, size + 16, "r"); assert(fp != NULL); - psl_ctx_t *psl; psl = psl_load_fp(fp); psl_is_public_suffix(NULL, NULL); diff --git a/fuzz/libpsl_load_fuzzer.c b/fuzz/libpsl_load_fuzzer.c index 56d96c6..4bce23a 100644 --- a/fuzz/libpsl_load_fuzzer.c +++ b/fuzz/libpsl_load_fuzzer.c @@ -24,20 +24,21 @@ #include -#include // assert -#include // uint8_t -#include // malloc, free -#include // memcpy +#include /* assert */ +#include /* uint8_t */ +#include /* malloc, free */ +#include /* memcpy */ #include "libpsl.h" #include "fuzzer.h" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { + FILE *fp; psl_ctx_t *psl; - FILE *fp = fmemopen((void *)data, size, "r"); - if (!fp && size) // libc6 < 2.22 return NULL when size == 0 + fp = fmemopen((void *)data, size, "r"); + if (!fp && size) /* libc6 < 2.22 return NULL when size == 0 */ assert(1); psl = psl_load_fp(fp); diff --git a/fuzz/main.c b/fuzz/main.c index ac4caaf..345b330 100644 --- a/fuzz/main.c +++ b/fuzz/main.c @@ -81,6 +81,9 @@ static void test_all_from(const char *dirname) int main(int argc, char **argv) { + const char *target; + char corporadir[sizeof(SRCDIR) + 1 + strlen(argv[0]) + 8]; + /* if VALGRIND testing is enabled, we have to call ourselves with valgrind checking */ if (argc == 1) { const char *valgrind = getenv("TESTS_VALGRIND"); @@ -94,10 +97,9 @@ int main(int argc, char **argv) } } - const char *target = strrchr(argv[0], '/'); + target = strrchr(argv[0], '/'); target = target ? target + 1 : argv[0]; - char corporadir[sizeof(SRCDIR) + 1 + strlen(target) + 8]; snprintf(corporadir, sizeof(corporadir), SRCDIR "/%s.in", target); test_all_from(corporadir); @@ -130,7 +132,7 @@ int main(int argc, char **argv) int ret; unsigned char buf[64 * 1024]; - while (__AFL_LOOP(10000)) { // only works with afl-clang-fast + while (__AFL_LOOP(10000)) { /* only works with afl-clang-fast */ ret = fread(buf, 1, sizeof(buf), stdin); if (ret < 0) return 0;