Refresh of ndpi_netbios_name_interpret

This commit is contained in:
Luca Deri
2020-03-24 12:18:15 +01:00
parent 7b2f89ef25
commit e4512dbcb9
2 changed files with 8 additions and 9 deletions
+1 -1
View File
@@ -132,7 +132,7 @@ extern "C" {
u_int16_t** tcp_master_proto, u_int16_t** tcp_master_proto,
u_int16_t** udp_master_proto); u_int16_t** udp_master_proto);
#/* NDPI_PROTOCOL_NETBIOS */ #/* NDPI_PROTOCOL_NETBIOS */
int ndpi_netbios_name_interpret(char *in, char *out, u_int out_len); int ndpi_netbios_name_interpret(char *in, size_t inlen, char *out, u_int out_len);
#ifdef NDPI_ENABLE_DEBUG_MESSAGES #ifdef NDPI_ENABLE_DEBUG_MESSAGES
void ndpi_debug_get_last_log_function_line(struct ndpi_detection_module_struct *ndpi_struct, void ndpi_debug_get_last_log_function_line(struct ndpi_detection_module_struct *ndpi_struct,
+7 -8
View File
@@ -35,17 +35,17 @@ struct netbios_header {
}; };
/* The function below has been inherited by tcpdump */ /* The function below has been inherited by tcpdump */
int ndpi_netbios_name_interpret(char *in, char *out, u_int out_len) { int ndpi_netbios_name_interpret(char *in, size_t inlen, char *out, u_int out_len) {
int ret = 0, len; int ret = 0, len;
char *b; char *b;
len = (*in++)/2; len = (*in++)/2;
b = out; b = out;
*out = 0; *out = 0;
if(len > (out_len-1) || len < 1) if(len > (out_len-1) || len < 1 || 2*len > inlen)
return(-1); return(-1);
while (len--) { while (len--) {
if(in[0] < 'A' || in[0] > 'P' || in[1] < 'A' || in[1] > 'P') { if(in[0] < 'A' || in[0] > 'P' || in[1] < 'A' || in[1] > 'P') {
*out = 0; *out = 0;
@@ -53,7 +53,7 @@ int ndpi_netbios_name_interpret(char *in, char *out, u_int out_len) {
} }
*out = ((in[0]-'A')<<4) + (in[1]-'A'); *out = ((in[0]-'A')<<4) + (in[1]-'A');
in += 2; in += 2;
if(isprint(*out)) if(isprint(*out))
@@ -69,13 +69,12 @@ int ndpi_netbios_name_interpret(char *in, char *out, u_int out_len) {
return(ret); return(ret);
} }
static void ndpi_int_netbios_add_connection(struct ndpi_detection_module_struct static void ndpi_int_netbios_add_connection(struct ndpi_detection_module_struct
*ndpi_struct, struct ndpi_flow_struct *flow) { *ndpi_struct, struct ndpi_flow_struct *flow) {
char name[64]; char name[64];
u_int off = flow->packet.payload[12] == 0x20 ? 12 : 14; u_int off = flow->packet.payload[12] == 0x20 ? 12 : 14;
if(ndpi_netbios_name_interpret((char*)&flow->packet.payload[off], name, sizeof(name)) > 0) if(ndpi_netbios_name_interpret((char*)&flow->packet.payload[off], flow->packet.payload_packet_len - off, name, sizeof(name)) > 0)
snprintf((char*)flow->host_server_name, sizeof(flow->host_server_name)-1, "%s", name); snprintf((char*)flow->host_server_name, sizeof(flow->host_server_name)-1, "%s", name);
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_NETBIOS, NDPI_PROTOCOL_UNKNOWN); ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_NETBIOS, NDPI_PROTOCOL_UNKNOWN);