diff options
-rw-r--r-- | configure.seed | 20 | ||||
-rw-r--r-- | example/ndpiReader.c | 21 | ||||
-rw-r--r-- | fuzz/fuzz_ndpi_reader.c | 5 | ||||
-rw-r--r-- | src/lib/ndpi_analyze.c | 6 | ||||
-rwxr-xr-x | tests/do.sh | 2 |
5 files changed, 44 insertions, 10 deletions
diff --git a/configure.seed b/configure.seed index 44305cf8b..dd7720b9d 100644 --- a/configure.seed +++ b/configure.seed @@ -13,10 +13,18 @@ AS_IF([test "${with_sanitizer+set}" = set],[ LT_INIT -AC_PROG_CC(clang gcc) -AM_PROG_CC_C_O(clang gcc) -AC_PROG_CXX(clang++ g++) -AC_PROG_CC_STDC(clang gcc) +SYSTEM=`uname -s` +if test $SYSTEM = "Darwin"; then + AC_PROG_CC(clang gcc) + AM_PROG_CC_C_O(clang gcc) + AC_PROG_CXX(clang++ g++) + AC_PROG_CC_STDC(clang gcc) +else + AC_PROG_CC + AM_PROG_CC_C_O + AC_PROG_CXX + AC_PROG_CC_STDC +fi AC_LANG_WERROR AX_PTHREAD @@ -78,10 +86,6 @@ else fi MACHINE=`uname -m` -SYSTEM=`uname -s` -if test $SYSTEM = "Darwin"; then - CC=clang -fi CUSTOM_NDPI= diff --git a/example/ndpiReader.c b/example/ndpiReader.c index 8f0219caf..e4745990c 100644 --- a/example/ndpiReader.c +++ b/example/ndpiReader.c @@ -3498,6 +3498,25 @@ void bpf_filter_port_array_add(int filter_array[], int size, int port) { /* *********************************************** */ +void analysisUnitTest() { + struct ndpi_analyze_struct *s = ndpi_alloc_data_analysis(32); + u_int32_t i; + + for(i=0; i<256; i++) + ndpi_data_add_value(s, i); + + if(0) { + ndpi_data_print_window_values(s); + printf("Average: [all: %f][window: %f]\n", ndpi_data_average(s), ndpi_data_window_average(s)); + printf("Entropy: %f\n", ndpi_data_entropy(s)); + printf("StdDev: %f\n", ndpi_data_stddev(s)); + printf("Min/Max: %u/%u\n", ndpi_data_min(s), ndpi_data_max(s)); + } + + ndpi_free_data_analysis(s); +} + +/* *********************************************** */ /** @brief MAIN FUNCTION @@ -3528,7 +3547,7 @@ int orginal_main(int argc, char **argv) { serializerUnitTest(); analyzeUnitTest(); ndpi_self_check_host_match(); - + analysisUnitTest(); memset(ndpi_thread_info, 0, sizeof(ndpi_thread_info)); parseOptions(argc, argv); diff --git a/fuzz/fuzz_ndpi_reader.c b/fuzz/fuzz_ndpi_reader.c index 32318718f..3d35cf89b 100644 --- a/fuzz/fuzz_ndpi_reader.c +++ b/fuzz/fuzz_ndpi_reader.c @@ -118,28 +118,33 @@ int main(int argc, char ** argv) if (fseek(pcap_file, 0, SEEK_END) != 0) { perror("fseek(SEEK_END) failed"); + fclose(pcap_file); return 1; } pcap_file_size = ftell(pcap_file); if (pcap_file_size < 0) { perror("ftell failed"); + fclose(pcap_file); return 1; } if (fseek(pcap_file, 0, SEEK_SET) != 0) { perror("fseek(0, SEEK_SET) failed"); + fclose(pcap_file); return 1; } pcap_buffer = malloc(pcap_file_size); if (pcap_buffer == NULL) { perror("malloc failed"); + fclose(pcap_file); return 1; } if (fread(pcap_buffer, sizeof(*pcap_buffer), pcap_file_size, pcap_file) != pcap_file_size) { perror("fread failed"); + fclose(pcap_file); return 1; } diff --git a/src/lib/ndpi_analyze.c b/src/lib/ndpi_analyze.c index eaa0d30c2..4ca3ac25a 100644 --- a/src/lib/ndpi_analyze.c +++ b/src/lib/ndpi_analyze.c @@ -125,6 +125,12 @@ float ndpi_data_variance(struct ndpi_analyze_struct *s) { /* ********************************************************************************* */ +/* + See the link below for "Population and sample standard deviation review" + https://www.khanacademy.org/math/statistics-probability/summarizing-quantitative-data/variance-standard-deviation-sample/a/population-and-sample-standard-deviation-review + + In nDPI we use an approximate stddev calculation to avoid storing all data in memory +*/ /* Compute the standard deviation on all values */ float ndpi_data_stddev(struct ndpi_analyze_struct *s) { return(sqrt(ndpi_data_variance(s))); diff --git a/tests/do.sh b/tests/do.sh index bb187d40a..13014a7aa 100755 --- a/tests/do.sh +++ b/tests/do.sh @@ -9,7 +9,7 @@ PCAPS=`cd pcap; /bin/ls *.pcap` fuzzy_testing() { if [ -f ../fuzz/fuzz_ndpi_reader ]; then - ../fuzz/fuzz_ndpi_reader -max_total_time=${MAX_TOTAL_TIME:-592} -print_pcs=1 -workers=${FUZZY_WORKERS:-0} -jobs=${FUZZY_JOBS:-0} pcap/ + ../fuzz/fuzz_ndpi_reader -max_total_time="${MAX_TOTAL_TIME:-592}" -print_pcs=1 -workers="${FUZZY_WORKERS:-0}" -jobs="${FUZZY_JOBS:-0}" pcap/ fi } |