Fix crash when processing QR code content with a bad URI format

This commit is contained in:
Alexander Bakker 2018-11-14 21:12:44 +01:00
parent a651378315
commit 926b5139da
2 changed files with 9 additions and 2 deletions

View file

@ -48,6 +48,14 @@ public class GoogleAuthInfo {
return builder.build(); return builder.build();
} }
public static GoogleAuthInfo parseUri(String s) throws GoogleAuthInfoException {
Uri uri = Uri.parse(s);
if (uri == null) {
throw new GoogleAuthInfoException("bad uri format");
}
return GoogleAuthInfo.parseUri(uri);
}
public static GoogleAuthInfo parseUri(Uri uri) throws GoogleAuthInfoException { public static GoogleAuthInfo parseUri(Uri uri) throws GoogleAuthInfoException {
if (!uri.getScheme().equals("otpauth")) { if (!uri.getScheme().equals("otpauth")) {
throw new GoogleAuthInfoException("unsupported protocol"); throw new GoogleAuthInfoException("unsupported protocol");

View file

@ -108,8 +108,7 @@ public class ScannerActivity extends AegisActivity implements ZXingScannerView.R
public void handleResult(Result rawResult) { public void handleResult(Result rawResult) {
try { try {
// parse google auth uri // parse google auth uri
Uri uri = Uri.parse(rawResult.getText()); GoogleAuthInfo info = GoogleAuthInfo.parseUri(rawResult.getText());
GoogleAuthInfo info = GoogleAuthInfo.parseUri(uri);
DatabaseEntry entry = new DatabaseEntry(info); DatabaseEntry entry = new DatabaseEntry(info);
Intent intent = new Intent(); Intent intent = new Intent();