Add some fuzzers to test other data structures. (#1870)
Start using a dictionary for fuzzing (see: https://llvm.org/docs/LibFuzzer.html#dictionaries). Remove some dead code. Fuzzing with debug enabled is not usually a great idea (from performance POV). Keep the code since it might be useful while debugging.
This commit is contained in:
@@ -488,16 +488,12 @@ u_int64_t ndpi_get_bin_value(struct ndpi_bin *b, u_int16_t slot_id) {
|
||||
switch(b->family) {
|
||||
case ndpi_bin_family8:
|
||||
return(b->u.bins8[slot_id]);
|
||||
break;
|
||||
case ndpi_bin_family16:
|
||||
return(b->u.bins16[slot_id]);
|
||||
break;
|
||||
case ndpi_bin_family32:
|
||||
return(b->u.bins32[slot_id]);
|
||||
break;
|
||||
case ndpi_bin_family64:
|
||||
return(b->u.bins64[slot_id]);
|
||||
break;
|
||||
}
|
||||
|
||||
return(0);
|
||||
|
||||
+3
-21
@@ -3470,16 +3470,12 @@ u_int16_t ndpi_guess_protocol_id(struct ndpi_detection_module_struct *ndpi_str,
|
||||
case NDPI_IPSEC_PROTOCOL_ESP:
|
||||
case NDPI_IPSEC_PROTOCOL_AH:
|
||||
return(NDPI_PROTOCOL_IPSEC);
|
||||
break;
|
||||
case NDPI_GRE_PROTOCOL_TYPE:
|
||||
return(NDPI_PROTOCOL_IP_GRE);
|
||||
break;
|
||||
case NDPI_PGM_PROTOCOL_TYPE:
|
||||
return(NDPI_PROTOCOL_IP_PGM);
|
||||
break;
|
||||
case NDPI_PIM_PROTOCOL_TYPE:
|
||||
return(NDPI_PROTOCOL_IP_PIM);
|
||||
break;
|
||||
case NDPI_ICMP_PROTOCOL_TYPE:
|
||||
if(flow) {
|
||||
flow->entropy = 0.0f;
|
||||
@@ -3515,22 +3511,16 @@ u_int16_t ndpi_guess_protocol_id(struct ndpi_detection_module_struct *ndpi_str,
|
||||
}
|
||||
}
|
||||
return(NDPI_PROTOCOL_IP_ICMP);
|
||||
break;
|
||||
case NDPI_IGMP_PROTOCOL_TYPE:
|
||||
return(NDPI_PROTOCOL_IP_IGMP);
|
||||
break;
|
||||
case NDPI_EGP_PROTOCOL_TYPE:
|
||||
return(NDPI_PROTOCOL_IP_EGP);
|
||||
break;
|
||||
case NDPI_SCTP_PROTOCOL_TYPE:
|
||||
return(NDPI_PROTOCOL_IP_SCTP);
|
||||
break;
|
||||
case NDPI_OSPF_PROTOCOL_TYPE:
|
||||
return(NDPI_PROTOCOL_IP_OSPF);
|
||||
break;
|
||||
case NDPI_IPIP_PROTOCOL_TYPE:
|
||||
return(NDPI_PROTOCOL_IP_IP_IN_IP);
|
||||
break;
|
||||
case NDPI_ICMPV6_PROTOCOL_TYPE:
|
||||
if(flow) {
|
||||
/* Run some basic consistency tests */
|
||||
@@ -3548,10 +3538,8 @@ u_int16_t ndpi_guess_protocol_id(struct ndpi_detection_module_struct *ndpi_str,
|
||||
}
|
||||
}
|
||||
return(NDPI_PROTOCOL_IP_ICMPV6);
|
||||
break;
|
||||
case 112:
|
||||
return(NDPI_PROTOCOL_IP_VRRP);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7698,6 +7686,9 @@ ndpi_protocol ndpi_guess_undetected_protocol(struct ndpi_detection_module_struct
|
||||
ndpi_protocol ret = NDPI_PROTOCOL_NULL;
|
||||
u_int8_t user_defined_proto;
|
||||
|
||||
if(!ndpi_str)
|
||||
return ret;
|
||||
|
||||
#ifdef BITTORRENT_CACHE_DEBUG
|
||||
printf("[%s:%u] ndpi_guess_undetected_protocol(%08X, %u, %08X, %u) [flow: %p]\n",
|
||||
__FILE__, __LINE__, shost, sport, dhost, dport, flow);
|
||||
@@ -7994,31 +7985,22 @@ char *ndpi_get_proto_breed_name(struct ndpi_detection_module_struct *ndpi_str,
|
||||
switch(breed_id) {
|
||||
case NDPI_PROTOCOL_SAFE:
|
||||
return("Safe");
|
||||
break;
|
||||
case NDPI_PROTOCOL_ACCEPTABLE:
|
||||
return("Acceptable");
|
||||
break;
|
||||
case NDPI_PROTOCOL_FUN:
|
||||
return("Fun");
|
||||
break;
|
||||
case NDPI_PROTOCOL_UNSAFE:
|
||||
return("Unsafe");
|
||||
break;
|
||||
case NDPI_PROTOCOL_POTENTIALLY_DANGEROUS:
|
||||
return("Potentially Dangerous");
|
||||
break;
|
||||
case NDPI_PROTOCOL_TRACKER_ADS:
|
||||
return("Tracker/Ads");
|
||||
break;
|
||||
case NDPI_PROTOCOL_DANGEROUS:
|
||||
return("Dangerous");
|
||||
break;
|
||||
case NDPI_PROTOCOL_UNRATED:
|
||||
return("Unrated");
|
||||
break;
|
||||
default:
|
||||
return("???");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+10
-2
@@ -23,15 +23,19 @@ SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef __DESELMO_LIBCACHE_H__
|
||||
#define __DESELMO_LIBCACHE_H__
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct cache_entry *cache_entry;
|
||||
typedef struct cache_entry_ *cache_entry;
|
||||
|
||||
typedef struct cache_entry_map *cache_entry_map;
|
||||
typedef struct cache_entry_map_ *cache_entry_map;
|
||||
|
||||
/**
|
||||
* @brief Codes representing the result of some functions
|
||||
@@ -107,3 +111,7 @@ cache_entry cache_entry_new(void);
|
||||
cache_entry_map cache_entry_map_new(void);
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
Vendored
+5
-5
@@ -58,12 +58,12 @@ struct cache {
|
||||
cache_entry_map *map;
|
||||
};
|
||||
|
||||
struct cache_entry_map {
|
||||
struct cache_entry_map_ {
|
||||
cache_entry entry;
|
||||
cache_entry_map next;
|
||||
};
|
||||
|
||||
struct cache_entry {
|
||||
struct cache_entry_ {
|
||||
void *item;
|
||||
uint32_t item_size;
|
||||
cache_entry prev;
|
||||
@@ -89,10 +89,10 @@ void cache_touch_entry(cache_t cache, cache_entry entry) {
|
||||
|
||||
|
||||
cache_entry cache_entry_new(void) {
|
||||
return (cache_entry) ndpi_calloc(sizeof(struct cache_entry), 1);
|
||||
return (cache_entry) ndpi_calloc(sizeof(struct cache_entry_), 1);
|
||||
}
|
||||
cache_entry_map cache_entry_map_new(void) {
|
||||
return (cache_entry_map) ndpi_calloc(sizeof(struct cache_entry_map), 1);
|
||||
return (cache_entry_map) ndpi_calloc(sizeof(struct cache_entry_map_), 1);
|
||||
}
|
||||
|
||||
cache_t cache_new(uint32_t cache_max_size) {
|
||||
@@ -192,7 +192,7 @@ cache_result cache_add(cache_t cache, void *item, uint32_t item_size) {
|
||||
cache_entry_map hash_entry_map = cache->map[hash];
|
||||
while(hash_entry_map) {
|
||||
if(tail->item_size == hash_entry_map->entry->item_size &&
|
||||
!memcmp(tail->item, hash_entry_map->entry->item, item_size)) {
|
||||
!memcmp(tail->item, hash_entry_map->entry->item, tail->item_size)) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user