From d7139e6ba0d642a516d56be277587ece013eaccf Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Wed, 10 Jan 2018 00:54:59 +0100 Subject: TunnelEditorFragment: do not pass null localConfig Otherwise we might dereference it, per this play store gathered trace: Xiaomi Redmi 3S (land), 2048MB RAM, Android 7.1 java.lang.NullPointerException: at com.wireguard.android.model.Tunnel.setConfig (Tunnel.java:118) at com.wireguard.android.fragment.TunnelEditorFragment.onOptionsItemSelected (TunnelEditorFragment.java:160) at android.app.Fragment.performOptionsItemSelected (Fragment.java:2478) at android.app.FragmentManagerImpl.dispatchOptionsItemSelected (FragmentManager.java:2182) at android.app.FragmentController.dispatchOptionsItemSelected (FragmentController.java:336) at android.app.Activity.onMenuItemSelected (Activity.java:3211) at com.android.internal.policy.PhoneWindow.onMenuItemSelected (PhoneWindow.java:1219) at com.android.internal.view.menu.MenuBuilder.dispatchMenuItemSelected (MenuBuilder.java:761) at com.android.internal.view.menu.MenuItemImpl.invoke (MenuItemImpl.java:152) at com.android.internal.view.menu.MenuBuilder.performItemAction (MenuBuilder.java:904) at com.android.internal.view.menu.MenuBuilder.performItemAction (MenuBuilder.java:894) at android.widget.ActionMenuView.invokeItem (ActionMenuView.java:616) at com.android.internal.view.menu.ActionMenuItemView.onClick (ActionMenuItemView.java:152) at android.view.View.performClick (View.java:5637) at android.view.View$PerformClick.run (View.java:22433) at android.os.Handler.handleCallback (Handler.java:751) at android.os.Handler.dispatchMessage (Handler.java:95) at android.os.Looper.loop (Looper.java:153) at android.app.ActivityThread.main (ActivityThread.java:6244) at java.lang.reflect.Method.invoke (Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:891) at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:781) --- .../wireguard/android/fragment/TunnelEditorFragment.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'app/src') diff --git a/app/src/main/java/com/wireguard/android/fragment/TunnelEditorFragment.java b/app/src/main/java/com/wireguard/android/fragment/TunnelEditorFragment.java index eec5c098..aa4321e8 100644 --- a/app/src/main/java/com/wireguard/android/fragment/TunnelEditorFragment.java +++ b/app/src/main/java/com/wireguard/android/fragment/TunnelEditorFragment.java @@ -146,18 +146,19 @@ public class TunnelEditorFragment extends BaseFragment { public boolean onOptionsItemSelected(final MenuItem item) { switch (item.getItemId()) { case R.id.menu_action_save: - if (getSelectedTunnel() == null) { + final Tunnel selectedTunnel = getSelectedTunnel(); + if (selectedTunnel == null) { Log.d(TAG, "Attempting to create new tunnel " + localName.get()); final TunnelManager manager = Application.getComponent().getTunnelManager(); manager.create(localName.get(), localConfig) .whenComplete(this::onTunnelCreated); - } else if (!getSelectedTunnel().getName().equals(localName.get())) { + } else if (!selectedTunnel.getName().equals(localName.get())) { Log.d(TAG, "Attempting to rename tunnel to " + localName.get()); - getSelectedTunnel().rename(localName.get()) + selectedTunnel.rename(localName.get()) .whenComplete(this::onTunnelRenamed); - } else { - Log.d(TAG, "Attempting to save config of " + getSelectedTunnel().getName()); - getSelectedTunnel().setConfig(localConfig) + } else if (localConfig != null) { + Log.d(TAG, "Attempting to save config of " + selectedTunnel.getName()); + selectedTunnel.setConfig(localConfig) .whenComplete(this::onConfigSaved); } return true; -- cgit v1.2.3