Skip to content

Commit

Permalink
Fix invalid categories labels array length and add check
Browse files Browse the repository at this point in the history
  • Loading branch information
emanuele-f committed Mar 18, 2019
1 parent 7237f70 commit 6c9fbc2
Showing 1 changed file with 116 additions and 107 deletions.
223 changes: 116 additions & 107 deletions src/lib/ndpi_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,116 @@ int strncasecmp(s1, s2, n)

/* ****************************************** */

/* Keep it in order and in sync with ndpi_protocol_category_t in ndpi_typedefs.h */
static const char* categories[] = {
"Unspecified",
"Media",
"VPN",
"Email",
"DataTransfer",
"Web",
"SocialNetwork",
"Download-FileTransfer-FileSharing",
"Game",
"Chat",
"VoIP",
"Database",
"RemoteAccess",
"Cloud",
"Network",
"Collaborative",
"RPC",
"Streaming",
"System",
"SoftwareUpdate",
"",
"",
"",
"",
"",
"Music",
"Video",
"Shopping",
"Productivity",
"FileSharing",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"Mining", /* 99 */
"Malware",
"Advertisement",
"Banned_Site",
"Site_Unavailable"
};

/* ****************************************** */

/* Forward */
static void addDefaultPort(struct ndpi_detection_module_struct *ndpi_mod,
ndpi_port_range *range,
Expand Down Expand Up @@ -2239,6 +2349,12 @@ struct ndpi_detection_module_struct *ndpi_init_detection_module(void) {
ndpi_str->bigrams_automa.ac_automa = ac_automata_init(ac_match_handler);
ndpi_str->impossible_bigrams_automa.ac_automa = ac_automata_init(ac_match_handler);

if((sizeof(categories)/sizeof(char*)) != NDPI_PROTOCOL_NUM_CATEGORIES) {
NDPI_LOG_ERR(ndpi_str, "[NDPI] invalid categories length: expected %u, got %u\n",
NDPI_PROTOCOL_NUM_CATEGORIES, (sizeof(categories)/sizeof(char*)));
return(NULL);
}

#ifdef HAVE_HYPERSCAN
ndpi_str->custom_categories.num_to_load = 0, ndpi_str->custom_categories.to_load = NULL;
ndpi_str->custom_categories.hostnames = NULL;
Expand Down Expand Up @@ -5671,113 +5787,6 @@ void ndpi_category_set_name(struct ndpi_detection_module_struct *ndpi_mod,

/* ****************************************************** */

/* Keep it in order and in sync with ndpi_protocol_category_t in ndpi_typedefs.h */
static const char* categories[] = {
"Unspecified",
"Media",
"VPN",
"Email",
"DataTransfer",
"Web",
"SocialNetwork",
"Download-FileTransfer-FileSharing",
"Game",
"Chat",
"VoIP",
"Database",
"RemoteAccess",
"Cloud",
"Network",
"Collaborative",
"RPC",
"Streaming",
"System",
"SoftwareUpdate",
"",
"",
"",
"",
"",
"Music",
"Video",
"Shopping",
"Productivity",
"FileSharing",
"",
"",
"",

"",
"",
"",
"",
"",
"",
"",
"",
"",
"",

"",
"",
"",
"",
"",
"",
"",
"",
"",
"",

"",
"",
"",
"",
"",
"",
"",
"",
"",
"",

"",
"",
"",
"",
"",
"",
"",
"",
"",
"",

"",
"",
"",
"",
"",
"",
"",
"",
"",
"",

"",
"",
"",
"",
"",
"",
"",
"",

"Mining", /* 99 */
"Malware",
"Advertisement",
"Banned_Site",
"Site_Unavailable"
};

const char* ndpi_category_get_name(struct ndpi_detection_module_struct *ndpi_mod,
ndpi_protocol_category_t category) {
if((!ndpi_mod) || (category >= NDPI_PROTOCOL_NUM_CATEGORIES))
Expand Down

0 comments on commit 6c9fbc2

Please sign in to comment.