summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
authorArne Schwabe <arne@rfc2549.org>2016-03-09 08:44:54 +0100
committerArne Schwabe <arne@rfc2549.org>2016-03-09 08:45:17 +0100
commit752e5bf1c80e63cbb9a8fa81d0213097c97d422b (patch)
tree6f538bbd1e910afd6ed85387f6643409bfd00758 /main
parent034a1752c6f1025552ef585303b5c652d2f873db (diff)
Workaround for endless loop in Logfilehandler
Diffstat (limited to 'main')
-rw-r--r--main/src/main/java/de/blinkt/openvpn/core/LogFileHandler.java11
-rw-r--r--main/src/main/java/de/blinkt/openvpn/core/VpnStatus.java2
2 files changed, 11 insertions, 2 deletions
diff --git a/main/src/main/java/de/blinkt/openvpn/core/LogFileHandler.java b/main/src/main/java/de/blinkt/openvpn/core/LogFileHandler.java
index 4d6c0fa0..da9cb6ef 100644
--- a/main/src/main/java/de/blinkt/openvpn/core/LogFileHandler.java
+++ b/main/src/main/java/de/blinkt/openvpn/core/LogFileHandler.java
@@ -105,16 +105,20 @@ class LogFileHandler extends Handler {
private void readLogCache(File cacheDir) {
File logfile = new File(cacheDir, LOGFILE_NAME);
+
if (!logfile.exists() || !logfile.canRead())
return;
VpnStatus.logDebug("Reread log items from cache file");
+
try {
+
BufferedInputStream logFile = new BufferedInputStream(new FileInputStream(logfile));
byte[] buf = new byte[8192];
int read = logFile.read(buf, 0, 2);
+ int itemsRead=0;
while (read > 0) {
// Marshalled LogItem
@@ -131,12 +135,17 @@ class LogFileHandler extends Handler {
} else {
VpnStatus.logError(String.format(Locale.getDefault(),
"Could not read log item from file: %d/%d: %s",
- read,len, Utils.bytesToHex(buf, read)));
+ read, len, Utils.bytesToHex(buf, read)));
}
p.recycle();
//Next item
read = logFile.read(buf, 0, 2);
+ itemsRead++;
+ if (itemsRead > 2*VpnStatus.MAXLOGENTRIES) {
+ VpnStatus.logError("Too many logentries read from cache, aborting.");
+ read = 0;
+ }
}
} catch (java.io.IOException | java.lang.RuntimeException e) {
diff --git a/main/src/main/java/de/blinkt/openvpn/core/VpnStatus.java b/main/src/main/java/de/blinkt/openvpn/core/VpnStatus.java
index bae94624..06024e8a 100644
--- a/main/src/main/java/de/blinkt/openvpn/core/VpnStatus.java
+++ b/main/src/main/java/de/blinkt/openvpn/core/VpnStatus.java
@@ -73,7 +73,7 @@ public class VpnStatus {
logException(LogLevel.ERROR, context, e);
}
- private static final int MAXLOGENTRIES = 1000;
+ static final int MAXLOGENTRIES = 1000;
public static String getLastCleanLogMessage(Context c) {