diff options
author | Vitaly Lavrov <vel21ripn@gmail.com> | 2021-07-07 12:32:57 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-07 14:32:57 +0200 |
commit | 398ad8e5ffc69640d5a41ef73d0c2f146bc94f06 (patch) | |
tree | dbf759f35d3a7af0e741a2ed14e47c31794c5224 | |
parent | 34d0718bca499bafef5786577a25173ef20f18f3 (diff) |
Fix for #1230 (#1235)
* Revert "Fix return value of ndpi_match_string_subprotocol() (#1230)"
This reverts commit 58665e93a98d014b53d131b2481ccab074efc9ff.
* Checking the return code after calling ndpi_match_string_subprotocol()
ndpi_api.h: Description of the returned error codes for
the ndpi_match_string_subprotocol() function.
If the ndpi_match_string_subprotocol() function returned an error,
then return NDPI_PROTOCOL_UNKNOWN.
http: The "Content-type" header is only checked if it is not empty.
-rw-r--r-- | src/include/ndpi_api.h.in | 4 | ||||
-rw-r--r-- | src/lib/ndpi_main.c | 7 | ||||
-rw-r--r-- | src/lib/protocols/http.c | 2 |
3 files changed, 9 insertions, 4 deletions
diff --git a/src/include/ndpi_api.h.in b/src/include/ndpi_api.h.in index d30e923b9..df545a165 100644 --- a/src/include/ndpi_api.h.in +++ b/src/include/ndpi_api.h.in @@ -425,7 +425,9 @@ extern "C" { * @par string_to_match_len = the length of the string * @par ret_match = completed returned match information * @par is_host_match = value of the second field of struct ndpi_automa - * @return the ID of the matched subprotocol + * @return the ID of the matched subprotocol; + * -1 if automa is not finalized; + * -2 if automa==NULL or string_to_match==NULL or empty string_to_match * */ int ndpi_match_string_subprotocol(struct ndpi_detection_module_struct *ndpi_struct, diff --git a/src/lib/ndpi_main.c b/src/lib/ndpi_main.c index d014da328..43c1c489f 100644 --- a/src/lib/ndpi_main.c +++ b/src/lib/ndpi_main.c @@ -6682,7 +6682,7 @@ int ndpi_match_string_subprotocol(struct ndpi_detection_module_struct *ndpi_str, rc = ndpi_match_string_common(((AC_AUTOMATA_t *) automa->ac_automa), string_to_match,string_to_match_len, &ret_match->protocol_id, &ret_match->protocol_category, &ret_match->protocol_breed); - return rc < 0 ? NDPI_PROTOCOL_UNKNOWN : ret_match->protocol_id; + return rc < 0 ? rc : ret_match->protocol_id; } /* **************************************** */ @@ -6709,12 +6709,15 @@ static u_int16_t ndpi_automa_match_string_subprotocol(struct ndpi_detection_modu struct ndpi_flow_struct *flow, char *string_to_match, u_int string_to_match_len, u_int16_t master_protocol_id, ndpi_protocol_match_result *ret_match, u_int8_t is_host_match) { - uint16_t matching_protocol_id; + int matching_protocol_id; struct ndpi_packet_struct *packet = &flow->packet; matching_protocol_id = ndpi_match_string_subprotocol(ndpi_str, string_to_match, string_to_match_len, ret_match, is_host_match); + if(matching_protocol_id < 0) + return NDPI_PROTOCOL_UNKNOWN; + #ifdef DEBUG { char m[256]; diff --git a/src/lib/protocols/http.c b/src/lib/protocols/http.c index 6a3df8e26..79110a531 100644 --- a/src/lib/protocols/http.c +++ b/src/lib/protocols/http.c @@ -656,7 +656,7 @@ static void check_content_type_and_change_protocol(struct ndpi_detection_module_ } } - if(flow->http_detected) { + if(flow->http_detected && packet->content_line.ptr && *(char*)packet->content_line.ptr) { ndpi_protocol_match_result ret_match; ndpi_match_content_subprotocol(ndpi_struct, flow, |