0
0
mirror of https://github.com/schwabe/ics-openvpn.git synced 2024-09-20 12:02:28 +02:00

Fix crashes on reading invalid log items.

This commit is contained in:
Arne Schwabe 2016-02-22 14:28:54 +01:00
parent 3f15db11f5
commit ca1493138f
3 changed files with 33 additions and 2 deletions

View File

@ -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

View File

@ -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 {

View File

@ -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);
}
}