diff options
author | Arne Schwabe <arne@rfc2549.org> | 2016-02-22 14:28:54 +0100 |
---|---|---|
committer | Arne Schwabe <arne@rfc2549.org> | 2016-02-22 14:28:54 +0100 |
commit | ca1493138f98e2781b90fd14093d6b5788181bb1 (patch) | |
tree | 90e1f7437d42b41a677abd996e8d00ff2570ef46 /main/src | |
parent | 3f15db11f53bcb5cd453cb7191e782e48bd47889 (diff) |
Fix crashes on reading invalid log items.
Diffstat (limited to 'main/src')
3 files changed, 33 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 5c1741d9..4d6c0fa0 100644 --- a/main/src/main/java/de/blinkt/openvpn/core/LogFileHandler.java +++ b/main/src/main/java/de/blinkt/openvpn/core/LogFileHandler.java @@ -9,6 +9,7 @@ import android.os.Handler; import android.os.Looper; import android.os.Message; import android.os.Parcel; +import android.text.TextUtils; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; @@ -17,6 +18,9 @@ import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; +import java.util.Locale; + +import de.blinkt.openvpn.fragments.Utils; /** * Created by arne on 23.01.16. @@ -122,7 +126,13 @@ class LogFileHandler extends Handler { p.unmarshall(buf, 0, read); p.setDataPosition(0); VpnStatus.LogItem li = VpnStatus.LogItem.CREATOR.createFromParcel(p); - VpnStatus.newLogItem(li, true); + if (li.verify()) { + VpnStatus.newLogItem(li, true); + } else { + VpnStatus.logError(String.format(Locale.getDefault(), + "Could not read log item from file: %d/%d: %s", + read,len, Utils.bytesToHex(buf, read))); + } p.recycle(); //Next item 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 75163865..4eba8e64 100644 --- a/main/src/main/java/de/blinkt/openvpn/core/VpnStatus.java +++ b/main/src/main/java/de/blinkt/openvpn/core/VpnStatus.java @@ -291,7 +291,6 @@ public class VpnStatus { if (mArgs != null) str += TextUtils.join("|", mArgs); - return str; } } @@ -369,6 +368,16 @@ public class VpnStatus { } return mVerbosityLevel; } + + public boolean verify() { + if (mLevel == null) + return false; + + if (mMessage == null && mRessourceId == 0) + return false; + + return true; + } } public interface LogListener { diff --git a/main/src/main/java/de/blinkt/openvpn/fragments/Utils.java b/main/src/main/java/de/blinkt/openvpn/fragments/Utils.java index 07d2f52b..382a97f6 100644 --- a/main/src/main/java/de/blinkt/openvpn/fragments/Utils.java +++ b/main/src/main/java/de/blinkt/openvpn/fragments/Utils.java @@ -262,4 +262,16 @@ public class Utils { return prefix + VpnProfile.INLINE_TAG + newData; } + + final protected static char[] hexArray = "0123456789ABCDEF".toCharArray(); + public static String bytesToHex(byte[] bytes, int len) { + len = Math.min(bytes.length, len); + char[] hexChars = new char[len * 2]; + for ( int j = 0; j < len; j++ ) { + int v = bytes[j] & 0xFF; + hexChars[j * 2] = hexArray[v >>> 4]; + hexChars[j * 2 + 1] = hexArray[v & 0x0F]; + } + return new String(hexChars); + } } |