telnet: fix heap-overflow error

There is some boilerplate since I removed an if branch and I had to reindent
the code
This commit is contained in:
Nardi Ivan
2020-03-27 11:09:53 +01:00
parent 97fc94c7e8
commit 817aa54214
+43 -46
View File
@@ -36,72 +36,69 @@
static int search_telnet_again(struct ndpi_detection_module_struct *ndpi_struct, static int search_telnet_again(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow) { struct ndpi_flow_struct *flow) {
struct ndpi_packet_struct *packet = &flow->packet; struct ndpi_packet_struct *packet = &flow->packet;
int i;
#ifdef TELNET_DEBUG #ifdef TELNET_DEBUG
printf("==> %s() [%s][direction: %u]\n", __FUNCTION__, packet->payload, packet->packet_direction); printf("==> %s() [%s][direction: %u]\n", __FUNCTION__, packet->payload, packet->packet_direction);
#endif #endif
if (packet->payload == NULL) if (packet->payload == NULL || packet->payload_packet_len == 0)
return(1); return(1);
if(packet->payload[0] == 0xFF) if(packet->payload[0] == 0xFF)
return(1); return(1);
if(packet->payload_packet_len > 0) { if(flow->protos.telnet.username_detected) {
int i; if((!flow->protos.telnet.password_found)
&& (packet->payload_packet_len > 6)) {
if(flow->protos.telnet.username_detected) { if(strncasecmp((char*)packet->payload, "password:", 9) == 0) {
if((!flow->protos.telnet.password_found) flow->protos.telnet.password_found = 1;
&& (packet->payload_packet_len > 6)) {
if(strncasecmp((char*)packet->payload, "password:", 9) == 0) {
flow->protos.telnet.password_found = 1;
}
return(1);
}
if(packet->payload[0] == '\r') {
if(!flow->protos.telnet.password_found)
return(1);
flow->protos.telnet.password_detected = 1;
flow->protos.telnet.password[flow->protos.telnet.character_id] = '\0';
return(0);
}
if(packet->packet_direction == 0) /* client -> server */ {
for(i=0; i<packet->payload_packet_len; i++) {
if(flow->protos.telnet.character_id < (sizeof(flow->protos.telnet.password)-1))
flow->protos.telnet.password[flow->protos.telnet.character_id++] = packet->payload[i];
}
}
return(1);
}
if((!flow->protos.telnet.username_found)
&& (packet->payload_packet_len > 6)) {
if(strncasecmp((char*)packet->payload, "login:", 6) == 0) {
flow->protos.telnet.username_found = 1;
} }
return(1); return(1);
} }
if(packet->payload[0] == '\r') { if(packet->payload[0] == '\r') {
flow->protos.telnet.username_detected = 1; if(!flow->protos.telnet.password_found)
flow->protos.telnet.username[flow->protos.telnet.character_id] = '\0'; return(1);
flow->protos.telnet.character_id = 0;
return(1); flow->protos.telnet.password_detected = 1;
flow->protos.telnet.password[flow->protos.telnet.character_id] = '\0';
return(0);
} }
for(i=0; i<packet->payload_packet_len; i++) { if(packet->packet_direction == 0) /* client -> server */ {
if(packet->packet_direction == 0) /* client -> server */ { for(i=0; i<packet->payload_packet_len; i++) {
if(flow->protos.telnet.character_id < (sizeof(flow->protos.telnet.username)-1)) if(flow->protos.telnet.character_id < (sizeof(flow->protos.telnet.password)-1))
flow->protos.telnet.username[flow->protos.telnet.character_id++] = packet->payload[i]; flow->protos.telnet.password[flow->protos.telnet.character_id++] = packet->payload[i];
} }
} }
return(1);
}
if((!flow->protos.telnet.username_found)
&& (packet->payload_packet_len > 6)) {
if(strncasecmp((char*)packet->payload, "login:", 6) == 0) {
flow->protos.telnet.username_found = 1;
}
return(1);
}
if(packet->payload[0] == '\r') {
flow->protos.telnet.username_detected = 1;
flow->protos.telnet.username[flow->protos.telnet.character_id] = '\0';
flow->protos.telnet.character_id = 0;
return(1);
}
for(i=0; i<packet->payload_packet_len; i++) {
if(packet->packet_direction == 0) /* client -> server */ {
if(flow->protos.telnet.character_id < (sizeof(flow->protos.telnet.username)-1))
flow->protos.telnet.username[flow->protos.telnet.character_id++] = packet->payload[i];
}
} }
/* Possibly more processing */ /* Possibly more processing */