summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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) {