aboutsummaryrefslogtreecommitdiff
path: root/src/lib/ndpi_utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/ndpi_utils.c')
-rw-r--r--src/lib/ndpi_utils.c43
1 files changed, 38 insertions, 5 deletions
diff --git a/src/lib/ndpi_utils.c b/src/lib/ndpi_utils.c
index efb7d26f2..878f40d88 100644
--- a/src/lib/ndpi_utils.c
+++ b/src/lib/ndpi_utils.c
@@ -733,7 +733,7 @@ const char* ndpi_cipher2str(u_int32_t cipher) {
{
static char buf[8];
- snprintf(buf, sizeof(buf), "0X%04X", cipher);
+ ndpi_snprintf(buf, sizeof(buf), "0X%04X", cipher);
return(buf);
}
}
@@ -778,7 +778,7 @@ static int ndpi_find_non_eng_bigrams(struct ndpi_detection_module_struct *ndpi_s
char *str) {
char s[3];
- if((isdigit(str[0]) && isdigit(str[1]))
+ if((isdigit((int)str[0]) && isdigit((int)str[1]))
|| ndpi_is_other_char(str[0])
|| ndpi_is_other_char(str[1])
)
@@ -935,7 +935,7 @@ char* ndpi_ssl_version2str(char *buf, int buf_len,
if(unknown_tls_version)
*unknown_tls_version = 1;
- snprintf(buf, buf_len, "TLS (%04X)", version);
+ ndpi_snprintf(buf, buf_len, "TLS (%04X)", version);
return buf;
}
@@ -1415,7 +1415,7 @@ int ndpi_dpi2json(struct ndpi_detection_module_struct *ndpi_struct,
if(flow->protos.tls_quic.sha1_certificate_fingerprint[0] != '\0') {
for(i=0, off=0; i<20; i++) {
- int rc = snprintf(&buf[off], sizeof(buf)-off,"%s%02X", (i > 0) ? ":" : "",
+ int rc = ndpi_snprintf(&buf[off], sizeof(buf)-off,"%s%02X", (i > 0) ? ":" : "",
flow->protos.tls_quic.sha1_certificate_fingerprint[i] & 0xFF);
if(rc <= 0) break; else off += rc;
@@ -1905,7 +1905,7 @@ const char* ndpi_risk2str(ndpi_risk_enum risk) {
break;
default:
- snprintf(buf, sizeof(buf), "%d", (int)risk);
+ ndpi_snprintf(buf, sizeof(buf), "%d", (int)risk);
return(buf);
}
}
@@ -2433,3 +2433,36 @@ void ndpi_set_tls_cert_expire_days(struct ndpi_detection_module_struct *ndpi_str
u_int8_t num_days) {
ndpi_str->tls_certificate_expire_in_x_days = num_days;
}
+
+/* ******************************************* */
+
+int ndpi_vsnprintf(char * str, size_t size, char const * format, va_list va_args)
+{
+#ifdef WIN32
+ if (str == NULL || size == 0 || format == NULL)
+ {
+ return -1;
+ }
+
+ int ret = vsnprintf_s(str, size, _TRUNCATE, format, va_args);
+
+ if (ret < 0)
+ {
+ return size;
+ } else {
+ return ret;
+ }
+#else
+ return vsnprintf(str, size, format, va_args);
+#endif
+}
+
+int ndpi_snprintf(char * str, size_t size, char const * format, ...)
+{
+ va_list va_args;
+
+ va_start(va_args, format);
+ int ret = ndpi_vsnprintf(str, size, format, va_args);
+ va_end(va_args);
+ return ret;
+}