Minor cleanup
This commit is contained in:
+22
-10
@@ -94,11 +94,14 @@ static void ndpi_int_ssh_add_connection(struct ndpi_detection_module_struct
|
|||||||
/* ************************************************************************ */
|
/* ************************************************************************ */
|
||||||
|
|
||||||
static u_int16_t concat_hash_string(struct ndpi_packet_struct *packet,
|
static u_int16_t concat_hash_string(struct ndpi_packet_struct *packet,
|
||||||
char *buf, u_int8_t client_hash) {
|
char *buf, u_int8_t client_hash) {
|
||||||
u_int32_t offset = 22, buf_out_len = 0;
|
u_int32_t offset = 22, buf_out_len = 0;
|
||||||
|
int len;
|
||||||
|
|
||||||
if(offset+sizeof(u_int32_t) >= packet->payload_packet_len)
|
if(offset+sizeof(u_int32_t) >= packet->payload_packet_len)
|
||||||
goto invalid_payload;
|
goto invalid_payload;
|
||||||
u_int32_t len = ntohl(*(u_int32_t*)&packet->payload[offset]);
|
|
||||||
|
len = ntohl(*(u_int32_t*)&packet->payload[offset]);
|
||||||
offset += 4;
|
offset += 4;
|
||||||
|
|
||||||
/* -1 for ';' */
|
/* -1 for ';' */
|
||||||
@@ -112,14 +115,17 @@ static u_int16_t concat_hash_string(struct ndpi_packet_struct *packet,
|
|||||||
|
|
||||||
if(offset+sizeof(u_int32_t) >= packet->payload_packet_len)
|
if(offset+sizeof(u_int32_t) >= packet->payload_packet_len)
|
||||||
goto invalid_payload;
|
goto invalid_payload;
|
||||||
|
|
||||||
/* ssh.server_host_key_algorithms [None] */
|
/* ssh.server_host_key_algorithms [None] */
|
||||||
len = ntohl(*(u_int32_t*)&packet->payload[offset]);
|
len = ntohl(*(u_int32_t*)&packet->payload[offset]);
|
||||||
if (len > UINT32_MAX - 8 - offset)
|
|
||||||
|
if(len > UINT32_MAX - 8 - offset)
|
||||||
goto invalid_payload;
|
goto invalid_payload;
|
||||||
offset += 4 + len;
|
offset += 4 + len;
|
||||||
|
|
||||||
if(offset+sizeof(u_int32_t) >= packet->payload_packet_len)
|
if(offset+sizeof(u_int32_t) >= packet->payload_packet_len)
|
||||||
goto invalid_payload;
|
goto invalid_payload;
|
||||||
|
|
||||||
/* ssh.encryption_algorithms_client_to_server [C] */
|
/* ssh.encryption_algorithms_client_to_server [C] */
|
||||||
len = ntohl(*(u_int32_t*)&packet->payload[offset]);
|
len = ntohl(*(u_int32_t*)&packet->payload[offset]);
|
||||||
|
|
||||||
@@ -132,12 +138,14 @@ static u_int16_t concat_hash_string(struct ndpi_packet_struct *packet,
|
|||||||
buf_out_len += len;
|
buf_out_len += len;
|
||||||
buf[buf_out_len++] = ';';
|
buf[buf_out_len++] = ';';
|
||||||
}
|
}
|
||||||
if (len > UINT32_MAX - 4 - offset)
|
|
||||||
|
if(len > UINT32_MAX - 4 - offset)
|
||||||
goto invalid_payload;
|
goto invalid_payload;
|
||||||
offset += len;
|
offset += len;
|
||||||
|
|
||||||
if(offset+sizeof(u_int32_t) >= packet->payload_packet_len)
|
if(offset+sizeof(u_int32_t) >= packet->payload_packet_len)
|
||||||
goto invalid_payload;
|
goto invalid_payload;
|
||||||
|
|
||||||
/* ssh.encryption_algorithms_server_to_client [S] */
|
/* ssh.encryption_algorithms_server_to_client [S] */
|
||||||
len = ntohl(*(u_int32_t*)&packet->payload[offset]);
|
len = ntohl(*(u_int32_t*)&packet->payload[offset]);
|
||||||
|
|
||||||
@@ -150,7 +158,8 @@ static u_int16_t concat_hash_string(struct ndpi_packet_struct *packet,
|
|||||||
buf_out_len += len;
|
buf_out_len += len;
|
||||||
buf[buf_out_len++] = ';';
|
buf[buf_out_len++] = ';';
|
||||||
}
|
}
|
||||||
if (len > UINT32_MAX - 4 - offset)
|
|
||||||
|
if(len > UINT32_MAX - 4 - offset)
|
||||||
goto invalid_payload;
|
goto invalid_payload;
|
||||||
offset += len;
|
offset += len;
|
||||||
|
|
||||||
@@ -168,7 +177,7 @@ static u_int16_t concat_hash_string(struct ndpi_packet_struct *packet,
|
|||||||
buf_out_len += len;
|
buf_out_len += len;
|
||||||
buf[buf_out_len++] = ';';
|
buf[buf_out_len++] = ';';
|
||||||
}
|
}
|
||||||
if (len > UINT32_MAX - 4 - offset)
|
if(len > UINT32_MAX - 4 - offset)
|
||||||
goto invalid_payload;
|
goto invalid_payload;
|
||||||
offset += len;
|
offset += len;
|
||||||
|
|
||||||
@@ -186,7 +195,8 @@ static u_int16_t concat_hash_string(struct ndpi_packet_struct *packet,
|
|||||||
buf_out_len += len;
|
buf_out_len += len;
|
||||||
buf[buf_out_len++] = ';';
|
buf[buf_out_len++] = ';';
|
||||||
}
|
}
|
||||||
if (len > UINT32_MAX - 4 - offset)
|
|
||||||
|
if(len > UINT32_MAX - 4 - offset)
|
||||||
goto invalid_payload;
|
goto invalid_payload;
|
||||||
offset += len;
|
offset += len;
|
||||||
|
|
||||||
@@ -203,7 +213,8 @@ static u_int16_t concat_hash_string(struct ndpi_packet_struct *packet,
|
|||||||
strncpy(&buf[buf_out_len], (const char *)&packet->payload[offset], len);
|
strncpy(&buf[buf_out_len], (const char *)&packet->payload[offset], len);
|
||||||
buf_out_len += len;
|
buf_out_len += len;
|
||||||
}
|
}
|
||||||
if (len > UINT32_MAX - 4 - offset)
|
|
||||||
|
if(len > UINT32_MAX - 4 - offset)
|
||||||
goto invalid_payload;
|
goto invalid_payload;
|
||||||
offset += len;
|
offset += len;
|
||||||
|
|
||||||
@@ -220,7 +231,8 @@ static u_int16_t concat_hash_string(struct ndpi_packet_struct *packet,
|
|||||||
strncpy(&buf[buf_out_len], (const char *)&packet->payload[offset], len);
|
strncpy(&buf[buf_out_len], (const char *)&packet->payload[offset], len);
|
||||||
buf_out_len += len;
|
buf_out_len += len;
|
||||||
}
|
}
|
||||||
if (len > UINT32_MAX - offset)
|
|
||||||
|
if(len > UINT32_MAX - offset)
|
||||||
goto invalid_payload;
|
goto invalid_payload;
|
||||||
offset += len;
|
offset += len;
|
||||||
|
|
||||||
@@ -234,7 +246,7 @@ static u_int16_t concat_hash_string(struct ndpi_packet_struct *packet,
|
|||||||
|
|
||||||
return(buf_out_len);
|
return(buf_out_len);
|
||||||
|
|
||||||
invalid_payload:
|
invalid_payload:
|
||||||
|
|
||||||
#ifdef SSH_DEBUG
|
#ifdef SSH_DEBUG
|
||||||
printf("[SSH] Invalid packet payload\n");
|
printf("[SSH] Invalid packet payload\n");
|
||||||
|
|||||||
Reference in New Issue
Block a user