Commit 642376aa authored by Scott Violet's avatar Scott Violet Committed by Chromium LUCI CQ

weblayer: fix possible NPE in uploading crash

If the supplied id doesn't identify a crash file, then an
NPE is triggered. This adds an early out.

BUG: 1169894
TEST: CrashReporterTest.testBogusCrashId
Change-Id: I78defd46f82c22f79ece02d5191b27342e1144c0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2644464
Commit-Queue: Scott Violet <sky@chromium.org>
Reviewed-by: default avatarClark DuVall <cduvall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#846431}
parent 2f6607f2
......@@ -119,4 +119,23 @@ public class CrashReporterTest {
Assert.assertFalse(mCrashReport.exists());
Assert.assertFalse(mCrashSidecar.exists());
}
@Test
@SmallTest
public void testBogusCrashId() throws Exception {
CallbackHelper callbackHelper = new CallbackHelper();
InstrumentationActivity activity = mActivityTestRule.launchShellWithUrl("about:blank");
TestThreadUtils.runOnUiThreadBlocking(() -> {
CrashReporterController crashReporterController =
CrashReporterController.getInstance(activity);
crashReporterController.registerCallback(new CrashReporterCallback() {
@Override
public void onCrashUploadFailed(String localId, String message) {
callbackHelper.notifyCalled();
}
});
crashReporterController.uploadCrash("bogus-crash-id");
});
callbackHelper.waitForFirst();
}
}
......@@ -82,6 +82,14 @@ public final class CrashReporterControllerImpl extends ICrashReporterController.
AsyncTask.THREAD_POOL_EXECUTOR.execute(() -> {
TraceEvent.instant(TAG, "CrashReporterController: Begin uploading crash");
File minidumpFile = getCrashFileManager().getCrashFileWithLocalId(localId);
if (minidumpFile == null) {
try {
mClient.onCrashUploadFailed(localId, "invalid crash id");
} catch (RemoteException e) {
throw new AndroidRuntimeException(e);
}
return;
}
MinidumpUploader.Result result = new MinidumpUploader().upload(minidumpFile);
if (result.isSuccess()) {
CrashFileManager.markUploadSuccess(minidumpFile);
......
......@@ -39,5 +39,5 @@ public abstract class CrashReporterCallback {
* @param localId the local identifier of the crash that failed to upload.
* @param failureReason a free text string giving the failure reason.
*/
public void onCrashUploadFailed(@NonNull String localId, @NonNull String faulreReason) {}
public void onCrashUploadFailed(@NonNull String localId, @NonNull String failureReason) {}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment