Added snprintf() return code check
This commit is contained in:
@@ -104,16 +104,12 @@ void ndpi_search_dhcp_udp(struct ndpi_detection_module_struct *ndpi_struct, stru
|
|||||||
u_int idx, offset = 0;
|
u_int idx, offset = 0;
|
||||||
|
|
||||||
for(idx = 0; idx < len && offset < sizeof(flow->protos.dhcp.fingerprint) - 2; idx++) {
|
for(idx = 0; idx < len && offset < sizeof(flow->protos.dhcp.fingerprint) - 2; idx++) {
|
||||||
#if 1
|
int rc = snprintf((char*)&flow->protos.dhcp.fingerprint[offset],
|
||||||
offset += snprintf((char*)&flow->protos.dhcp.fingerprint[offset],
|
|
||||||
sizeof(flow->protos.dhcp.fingerprint) - offset,
|
sizeof(flow->protos.dhcp.fingerprint) - offset,
|
||||||
"%s%u", (idx > 0) ? "," : "",
|
"%s%u", (idx > 0) ? "," : "",
|
||||||
(unsigned int)dhcp->options[i+2+idx] & 0xFF);
|
(unsigned int)dhcp->options[i+2+idx] & 0xFF);
|
||||||
#else
|
|
||||||
offset += snprintf((char*)&flow->protos.dhcp.fingerprint[offset],
|
if(rc < 0) break; else offset += rc;
|
||||||
sizeof(flow->protos.dhcp.fingerprint) - offset,
|
|
||||||
"%02X", dhcp->options[i+2+idx] & 0xFF);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
flow->protos.dhcp.fingerprint[sizeof(flow->protos.dhcp.fingerprint) - 1] = '\0';
|
flow->protos.dhcp.fingerprint[sizeof(flow->protos.dhcp.fingerprint) - 1] = '\0';
|
||||||
|
|||||||
+34
-20
@@ -271,7 +271,7 @@ int getTLScertificate(struct ndpi_detection_module_struct *ndpi_struct,
|
|||||||
|| (handshake_protocol == 0x0b) /* Server Hello and Certificate message types are interesting for us */) {
|
|| (handshake_protocol == 0x0b) /* Server Hello and Certificate message types are interesting for us */) {
|
||||||
u_int num_found = 0;
|
u_int num_found = 0;
|
||||||
u_int16_t tls_version;
|
u_int16_t tls_version;
|
||||||
int i;
|
int i, rc;
|
||||||
|
|
||||||
if(packet->tcp)
|
if(packet->tcp)
|
||||||
tls_version = ntohs(*((u_int16_t*)&packet->payload[header_len+4]));
|
tls_version = ntohs(*((u_int16_t*)&packet->payload[header_len+4]));
|
||||||
@@ -355,12 +355,13 @@ int getTLScertificate(struct ndpi_detection_module_struct *ndpi_struct,
|
|||||||
ja3_str_len = snprintf(ja3_str, sizeof(ja3_str), "%u,", ja3.tls_handshake_version);
|
ja3_str_len = snprintf(ja3_str, sizeof(ja3_str), "%u,", ja3.tls_handshake_version);
|
||||||
|
|
||||||
for(i=0; i<ja3.num_cipher; i++) {
|
for(i=0; i<ja3.num_cipher; i++) {
|
||||||
int rc = snprintf(&ja3_str[ja3_str_len], sizeof(ja3_str)-ja3_str_len, "%s%u", (i > 0) ? "-" : "", ja3.cipher[i]);
|
rc = snprintf(&ja3_str[ja3_str_len], sizeof(ja3_str)-ja3_str_len, "%s%u", (i > 0) ? "-" : "", ja3.cipher[i]);
|
||||||
|
|
||||||
if(rc <= 0) break; else ja3_str_len += rc;
|
if(rc <= 0) break; else ja3_str_len += rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
ja3_str_len += snprintf(&ja3_str[ja3_str_len], sizeof(ja3_str)-ja3_str_len, ",");
|
rc = snprintf(&ja3_str[ja3_str_len], sizeof(ja3_str)-ja3_str_len, ",");
|
||||||
|
if(rc > 0) ja3_str_len += rc;
|
||||||
|
|
||||||
/* ********** */
|
/* ********** */
|
||||||
|
|
||||||
@@ -699,35 +700,47 @@ int getTLScertificate(struct ndpi_detection_module_struct *ndpi_struct,
|
|||||||
} /* while */
|
} /* while */
|
||||||
|
|
||||||
if(!invalid_ja3) {
|
if(!invalid_ja3) {
|
||||||
|
int rc;
|
||||||
|
|
||||||
compute_ja3c:
|
compute_ja3c:
|
||||||
ja3_str_len = snprintf(ja3_str, sizeof(ja3_str), "%u,", ja3.tls_handshake_version);
|
ja3_str_len = snprintf(ja3_str, sizeof(ja3_str), "%u,", ja3.tls_handshake_version);
|
||||||
|
|
||||||
for(i=0; i<ja3.num_cipher; i++) {
|
for(i=0; i<ja3.num_cipher; i++) {
|
||||||
ja3_str_len += snprintf(&ja3_str[ja3_str_len], sizeof(ja3_str)-ja3_str_len, "%s%u",
|
rc = snprintf(&ja3_str[ja3_str_len], sizeof(ja3_str)-ja3_str_len, "%s%u",
|
||||||
(i > 0) ? "-" : "", ja3.cipher[i]);
|
(i > 0) ? "-" : "", ja3.cipher[i]);
|
||||||
|
if(rc > 0) ja3_str_len += rc; else break;
|
||||||
}
|
}
|
||||||
|
|
||||||
ja3_str_len += snprintf(&ja3_str[ja3_str_len], sizeof(ja3_str)-ja3_str_len, ",");
|
rc = snprintf(&ja3_str[ja3_str_len], sizeof(ja3_str)-ja3_str_len, ",");
|
||||||
|
if(rc > 0) ja3_str_len += rc;
|
||||||
|
|
||||||
/* ********** */
|
/* ********** */
|
||||||
|
|
||||||
for(i=0; i<ja3.num_tls_extension; i++)
|
for(i=0; i<ja3.num_tls_extension; i++) {
|
||||||
ja3_str_len += snprintf(&ja3_str[ja3_str_len], sizeof(ja3_str)-ja3_str_len, "%s%u",
|
rc = snprintf(&ja3_str[ja3_str_len], sizeof(ja3_str)-ja3_str_len, "%s%u",
|
||||||
(i > 0) ? "-" : "", ja3.tls_extension[i]);
|
(i > 0) ? "-" : "", ja3.tls_extension[i]);
|
||||||
|
if(rc > 0) ja3_str_len += rc; else break;
|
||||||
|
}
|
||||||
|
|
||||||
ja3_str_len += snprintf(&ja3_str[ja3_str_len], sizeof(ja3_str)-ja3_str_len, ",");
|
rc = snprintf(&ja3_str[ja3_str_len], sizeof(ja3_str)-ja3_str_len, ",");
|
||||||
|
if(rc > 0) ja3_str_len += rc;
|
||||||
|
|
||||||
/* ********** */
|
/* ********** */
|
||||||
|
|
||||||
for(i=0; i<ja3.num_elliptic_curve; i++)
|
for(i=0; i<ja3.num_elliptic_curve; i++) {
|
||||||
ja3_str_len += snprintf(&ja3_str[ja3_str_len], sizeof(ja3_str)-ja3_str_len, "%s%u",
|
rc = snprintf(&ja3_str[ja3_str_len], sizeof(ja3_str)-ja3_str_len, "%s%u",
|
||||||
(i > 0) ? "-" : "", ja3.elliptic_curve[i]);
|
(i > 0) ? "-" : "", ja3.elliptic_curve[i]);
|
||||||
|
if(rc > 0) ja3_str_len += rc; else break;
|
||||||
|
}
|
||||||
|
|
||||||
ja3_str_len += snprintf(&ja3_str[ja3_str_len], sizeof(ja3_str)-ja3_str_len, ",");
|
rc = snprintf(&ja3_str[ja3_str_len], sizeof(ja3_str)-ja3_str_len, ",");
|
||||||
|
if(rc > 0) ja3_str_len += rc;
|
||||||
|
|
||||||
for(i=0; i<ja3.num_elliptic_curve_point_format; i++)
|
for(i=0; i<ja3.num_elliptic_curve_point_format; i++) {
|
||||||
ja3_str_len += snprintf(&ja3_str[ja3_str_len], sizeof(ja3_str)-ja3_str_len, "%s%u",
|
rc = snprintf(&ja3_str[ja3_str_len], sizeof(ja3_str)-ja3_str_len, "%s%u",
|
||||||
(i > 0) ? "-" : "", ja3.elliptic_curve_point_format[i]);
|
(i > 0) ? "-" : "", ja3.elliptic_curve_point_format[i]);
|
||||||
|
if(rc > 0) ja3_str_len += rc; else break;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef DEBUG_TLS
|
#ifdef DEBUG_TLS
|
||||||
printf("[JA3] Client: %s \n", ja3_str);
|
printf("[JA3] Client: %s \n", ja3_str);
|
||||||
@@ -737,11 +750,12 @@ int getTLScertificate(struct ndpi_detection_module_struct *ndpi_struct,
|
|||||||
ndpi_MD5Update(&ctx, (const unsigned char *)ja3_str, strlen(ja3_str));
|
ndpi_MD5Update(&ctx, (const unsigned char *)ja3_str, strlen(ja3_str));
|
||||||
ndpi_MD5Final(md5_hash, &ctx);
|
ndpi_MD5Final(md5_hash, &ctx);
|
||||||
|
|
||||||
for(i=0, j=0; i<16; i++)
|
for(i=0, j=0; i<16; i++) {
|
||||||
j += snprintf(&flow->protos.stun_ssl.ssl.ja3_client[j],
|
rc = snprintf(&flow->protos.stun_ssl.ssl.ja3_client[j],
|
||||||
sizeof(flow->protos.stun_ssl.ssl.ja3_client)-j, "%02x",
|
sizeof(flow->protos.stun_ssl.ssl.ja3_client)-j, "%02x",
|
||||||
md5_hash[i]);
|
md5_hash[i]);
|
||||||
|
if(rc > 0) j += rc; else break;
|
||||||
|
}
|
||||||
#ifdef DEBUG_TLS
|
#ifdef DEBUG_TLS
|
||||||
printf("[JA3] Client: %s \n", flow->protos.stun_ssl.ssl.ja3_client);
|
printf("[JA3] Client: %s \n", flow->protos.stun_ssl.ssl.ja3_client);
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user