From cf1263c309b55ecc89f91c1b0ef4b67b1ce54344 Mon Sep 17 00:00:00 2001 From: M66B Date: Mon, 25 Jan 2016 09:44:17 +0100 Subject: [PATCH] Native allow unknown uids from Java --- .../main/java/eu/faircode/netguard/SinkholeService.java | 7 ++++--- app/src/main/jni/netguard/netguard.c | 6 +++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/eu/faircode/netguard/SinkholeService.java b/app/src/main/java/eu/faircode/netguard/SinkholeService.java index ef847805..3fa135fa 100644 --- a/app/src/main/java/eu/faircode/netguard/SinkholeService.java +++ b/app/src/main/java/eu/faircode/netguard/SinkholeService.java @@ -798,10 +798,11 @@ public class SinkholeService extends VpnService implements SharedPreferences.OnS } private int[] getAllowedUids(List listAllowed) { - int[] uid = new int[listAllowed.size() + 1]; - uid[0] = 0; // Allow root (DNS, etc) + int[] uid = new int[listAllowed.size() + 2]; + uid[0] = -1; // Allow unknown + uid[1] = 0; // Allow root (DNS, etc) for (int i = 0; i < listAllowed.size(); i++) - uid[i + 1] = listAllowed.get(i).info.applicationInfo.uid; + uid[i + 2] = listAllowed.get(i).info.applicationInfo.uid; return uid; } diff --git a/app/src/main/jni/netguard/netguard.c b/app/src/main/jni/netguard/netguard.c index 7c83c05c..81c608ec 100644 --- a/app/src/main/jni/netguard/netguard.c +++ b/app/src/main/jni/netguard/netguard.c @@ -256,7 +256,7 @@ void check_allowed(const struct arguments *args) { if (!u->stop) { int found = 0; for (int i = 0; i < args->ucount; i++) - if (u->uid < 0 || u->uid == args->uids[i]) { + if (u->uid == args->uids[i]) { found = 1; break; } @@ -273,7 +273,7 @@ void check_allowed(const struct arguments *args) { if (t->state != TCP_TIME_WAIT && t->state != TCP_CLOSE) { int found = 0; for (int i = 0; i < args->ucount; i++) - if (t->uid < 0 || t->uid == args->uids[i]) { + if (t->uid == args->uids[i]) { found = 1; break; } @@ -1020,7 +1020,7 @@ void handle_ip(const struct arguments *args, const uint8_t *buffer, const size_t jboolean allowed = (jboolean) !syn; if (syn && args->filter) { for (int i = 0; i < args->ucount; i++) - if (uid < 0 || uid == args->uids[i]) { + if (uid == args->uids[i]) { allowed = 1; break; }