From ef811796a56445b332f7d09364f9b01e61e381e2 Mon Sep 17 00:00:00 2001 From: M66B Date: Sun, 6 Mar 2016 10:24:28 +0100 Subject: [PATCH] Extra checks --- app/src/main/jni/netguard/ip.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/src/main/jni/netguard/ip.c b/app/src/main/jni/netguard/ip.c index 4ac3338d..fd7b8f1b 100644 --- a/app/src/main/jni/netguard/ip.c +++ b/app/src/main/jni/netguard/ip.c @@ -425,6 +425,9 @@ jint get_uid(const int version, const int protocol, int i = 0; while (fgets(line, sizeof(line), fd) != NULL) { if (i++) { + *hex = 0; + port = -1; + u = -1; if (version == 4) fields = sscanf( line, @@ -435,7 +438,8 @@ jint get_uid(const int version, const int protocol, line, "%*d: %32s:%X %*X:%*X %*X %*lX:%*lX %*X:%*X %*X %d %*d %*ld", hex, &port, &u); - if (fields == 3) { + if (fields == 3 && + (version == 4 ? strlen(hex) == 8 : strlen(hex) == 32) && port >= 0 && u >= 0) { hex2bytes(hex, version == 4 ? addr4 : addr6); if (version == 4) ((uint32_t *) addr4)[0] = htonl(((uint32_t *) addr4)[0]);