aboutsummaryrefslogtreecommitdiff
path: root/src/lib/ndpi_utils.c
diff options
context:
space:
mode:
authorIvan Nardi <12729895+IvanNardi@users.noreply.github.com>2022-07-08 12:50:46 +0200
committerGitHub <noreply@github.com>2022-07-08 12:50:46 +0200
commit510517126a63f828754826b5bcfc4b4d1d3791d4 (patch)
treedde2ceb664d81a87770c1b669ec36c89ee2c0e26 /src/lib/ndpi_utils.c
parent9b958769738c2b63f195d1ee2d112206704cce7e (diff)
LDAP: rewrite dissection (#1649)
Diffstat (limited to 'src/lib/ndpi_utils.c')
-rw-r--r--src/lib/ndpi_utils.c36
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;
+}