Skip to content

Commit

Permalink
Bugfix for ipv6 addresses which the app was trying to parse
Browse files Browse the repository at this point in the history
as if they contain a port.
  • Loading branch information
iiordanov committed Nov 21, 2015
1 parent 06cd034 commit 47d55b2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion eclipse_projects/bVNC/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.iiordanov.bVNC" android:installLocation="auto"
android:versionCode="3800" android:versionName="v3.8.0">
android:versionCode="3810" android:versionName="v3.8.1">

<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="10"></uses-sdk>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
import java.util.regex.Matcher;

import android.app.Activity;
import android.app.AlertDialog;
Expand Down Expand Up @@ -207,14 +208,15 @@ void initialize () {
connection.Gen_populate((ContentValues) extras.getParcelable(Constants.CONNECTION));
}

// Parse a HOST:PORT entry
// Parse a HOST:PORT entry but only if not ipv6 address
String host = connection.getAddress();
if (host.indexOf(':') > -1) {
if (!Utils.isValidIpv6Address(host) && host.indexOf(':') > -1) {
String p = host.substring(host.indexOf(':') + 1);
try {
connection.setPort(Integer.parseInt(p));
int parsedPort = Integer.parseInt(p);
connection.setPort(parsedPort);
connection.setAddress(host.substring(0, host.indexOf(':')));
} catch (Exception e) {}
connection.setAddress(host.substring(0, host.indexOf(':')));
}

if (connection.getPort() == 0)
Expand Down
13 changes: 11 additions & 2 deletions eclipse_projects/bVNC/src/com/iiordanov/bVNC/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.Reader;
import java.io.Writer;
import java.lang.reflect.Field;
import java.net.Inet6Address;
import java.net.InetAddress;
import java.net.UnknownHostException;

import org.xml.sax.SAXException;

Expand All @@ -50,7 +52,6 @@
import android.view.ViewConfiguration;

public class Utils {

public static void showYesNoPrompt(Context _context, String title, String message, OnClickListener onYesListener, OnClickListener onNoListener) {
AlertDialog.Builder builder = new AlertDialog.Builder(_context);
builder.setTitle(title);
Expand Down Expand Up @@ -202,4 +203,12 @@ public static void importSettingsFromXml (String file, SQLiteDatabase db) throws
Reader reader = new InputStreamReader(new FileInputStream(file));
SqliteElement.importXmlStreamToDb(db, reader, ReplaceStrategy.REPLACE_EXISTING);
}

public static boolean isValidIpv6Address(final String address) {
try {
return InetAddress.getByName(address) instanceof Inet6Address;
} catch (final UnknownHostException ex) {
return false;
}
}
}

0 comments on commit 47d55b2

Please sign in to comment.