OSDN Git Service

Fix bug in verifier: soft fail was hiding hard fail.
authorAart Bik <ajcbik@google.com>
Mon, 23 May 2016 21:58:49 +0000 (14:58 -0700)
committerAart Bik <ajcbik@google.com>
Tue, 24 May 2016 18:13:24 +0000 (11:13 -0700)
Rationale:
Dexfuzzing found a situation where a soft fail (modifying
a final field) was hiding a hard fail (type error on that
field), which caused a crash in the compiler later on.
Also added a crash-before/pass-after regression test,
so we don't add the return by accident later.

BUG=28908555

(cherry picked from commit c2bc26513ea7c5e2dd9f3b102fb23fd207e4ce63)

Change-Id: Ie79c4afa28cddbca4dfb78e5c75da6644612c15c

runtime/verifier/method_verifier.cc
test/600-verifier-fails/expected.txt [new file with mode: 0644]
test/600-verifier-fails/info.txt [new file with mode: 0644]
test/600-verifier-fails/smali/sput.smali [new file with mode: 0644]
test/600-verifier-fails/src/Main.java [new file with mode: 0644]

index 2b96328..b2be770 100644 (file)
@@ -4652,7 +4652,7 @@ void MethodVerifier::VerifyISFieldAccess(const Instruction* inst, const RegType&
       if (field->IsFinal() && field->GetDeclaringClass() != GetDeclaringClass().GetClass()) {
         Fail(VERIFY_ERROR_ACCESS_FIELD) << "cannot modify final field " << PrettyField(field)
                                         << " from other class " << GetDeclaringClass();
-        return;
+        // Keep hunting for possible hard fails.
       }
     }
 
diff --git a/test/600-verifier-fails/expected.txt b/test/600-verifier-fails/expected.txt
new file mode 100644 (file)
index 0000000..b0aad4d
--- /dev/null
@@ -0,0 +1 @@
+passed
diff --git a/test/600-verifier-fails/info.txt b/test/600-verifier-fails/info.txt
new file mode 100644 (file)
index 0000000..478dd9b
--- /dev/null
@@ -0,0 +1,4 @@
+The situation in this test was discovered by running dexfuzz on
+another fuzzingly random generated Java test. The soft verification
+fail (on the final field modification) should not hide the hard
+verification fail (on the type mismatch) to avoid a crash later on.
diff --git a/test/600-verifier-fails/smali/sput.smali b/test/600-verifier-fails/smali/sput.smali
new file mode 100644 (file)
index 0000000..87f3799
--- /dev/null
@@ -0,0 +1,23 @@
+#
+# Copyright (C) 2016 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+.class public LA;
+.super Ljava/lang/Object;
+
+.method public foo(I)V
+.registers 2
+    sput v1, LMain;->staticField:Ljava/lang/String;
+    return-void
+.end method
diff --git a/test/600-verifier-fails/src/Main.java b/test/600-verifier-fails/src/Main.java
new file mode 100644 (file)
index 0000000..ba4cc31
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.lang.reflect.Method;
+
+public class Main {
+
+  public static final String staticField = null;
+
+  public static void main(String[] args) throws Exception {
+    try {
+      Class<?> a = Class.forName("A");
+    } catch (java.lang.VerifyError e) {
+      System.out.println("passed");
+    }
+  }
+}