Commit 37856ab4 authored by Max Lv's avatar Max Lv

Catch IOExpections when reading ACLs

parent 3f30fc7b
...@@ -50,7 +50,11 @@ class Acl { ...@@ -50,7 +50,11 @@ class Acl {
get() { get() {
val acl = Acl() val acl = Acl()
val str = DataStore.publicStore.getString(CUSTOM_RULES) ?: return acl val str = DataStore.publicStore.getString(CUSTOM_RULES) ?: return acl
try {
acl.fromReader(str.reader()) acl.fromReader(str.reader())
} catch (_: Exception) {
// Ignore
}
if (!acl.bypass) { if (!acl.bypass) {
acl.subnets.clear() acl.subnets.clear()
acl.hostnames.clear() acl.hostnames.clear()
...@@ -148,11 +152,15 @@ class Acl { ...@@ -148,11 +152,15 @@ class Acl {
return this 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 { fun flatten(depth: Int): Acl {
if (depth > 0) for (url in urls.asIterable()) { 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) { if (bypass != child.bypass) {
Log.w(TAG, "Imported network ACL has a conflicting mode set. " + Log.w(TAG, "Imported network ACL has a conflicting mode set. " +
"This will probably not work as intended. URL: $url") "This will probably not work as intended. URL: $url")
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment