diff options
Diffstat (limited to 'src/lib/ndpi_utils.c')
-rw-r--r-- | src/lib/ndpi_utils.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/lib/ndpi_utils.c b/src/lib/ndpi_utils.c index 15b71caf1..ce1911743 100644 --- a/src/lib/ndpi_utils.c +++ b/src/lib/ndpi_utils.c @@ -2704,3 +2704,39 @@ u_int8_t ndpi_check_flow_risk_exceptions(struct ndpi_detection_module_struct *nd return(0); } + +/* ******************************************* */ + +int ndpi_asn1_ber_decode_length(const unsigned char *payload, int payload_len, u_int16_t *value_len) +{ + unsigned int value, i; + + if(payload_len <= 0) + return -1; + + /* Malformed */ + if(payload[0] == 0xFF) + return -1; + + /* Definite, short */ + if(payload[0] <= 0x80) { + *value_len = 1; + return payload[0]; + } + /* Indefinite, unsupported */ + if((payload[0] & 0x7F) == 0) + return -1; + + *value_len = payload[0] & 0x7F; + /* We support only 4 additional length octets */ + if(*value_len > 4 || + payload_len <= *value_len + 1) + return -1; + + value = 0; + for (i = 1; i <= *value_len; i++) { + value |= (unsigned int)payload[i] << ((*value_len) - i) * 8; + } + (*value_len) += 1; + return value; +} |