From 37856ab4d2fc998dbad0bf0cc7949dea84aef50b Mon Sep 17 00:00:00 2001 From: Max Lv Date: Mon, 18 Dec 2017 22:32:42 -0800 Subject: [PATCH] Catch IOExpections when reading ACLs --- .../main/java/com/github/shadowsocks/acl/Acl.kt | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/mobile/src/main/java/com/github/shadowsocks/acl/Acl.kt b/mobile/src/main/java/com/github/shadowsocks/acl/Acl.kt index 156723a7..a8107947 100644 --- a/mobile/src/main/java/com/github/shadowsocks/acl/Acl.kt +++ b/mobile/src/main/java/com/github/shadowsocks/acl/Acl.kt @@ -50,7 +50,11 @@ class Acl { get() { val acl = Acl() val str = DataStore.publicStore.getString(CUSTOM_RULES) ?: return acl - acl.fromReader(str.reader()) + try { + acl.fromReader(str.reader()) + } catch (_: Exception) { + // Ignore + } if (!acl.bypass) { acl.subnets.clear() acl.hostnames.clear() @@ -148,11 +152,15 @@ class Acl { return this } - fun fromId(id: String): Acl = fromReader(Acl.getFile(id).bufferedReader()) + fun fromId(id: String): Acl = try { fromReader(Acl.getFile(id).bufferedReader()) } catch (_: Exception) { Acl() } fun flatten(depth: Int): Acl { if (depth > 0) for (url in urls.asIterable()) { - val child = Acl().fromReader(url.openStream().bufferedReader(), bypass).flatten(depth - 1) + val child = try { + Acl().fromReader(url.openStream().bufferedReader(), bypass).flatten(depth - 1) + } catch (_: Exception) { + Acl() + } if (bypass != child.bypass) { Log.w(TAG, "Imported network ACL has a conflicting mode set. " + "This will probably not work as intended. URL: $url")