Skip to content

Commit c1609a3

Browse files
committed
fix: handle null values in Arrays.equal/compare hooks
`null` arrays would crash in the `Arrays.equal` and `Arrays.compare` hooks.
1 parent 068587e commit c1609a3

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/main/java/com/code_intelligence/jazzer/runtime/TraceCmpHooks.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,7 @@ public static void arraysEquals(
744744
if (returnValue) return;
745745
byte[] first = (byte[]) arguments[0];
746746
byte[] second = (byte[]) arguments[1];
747+
if (first == null || second == null) return;
747748
TraceDataFlowNativeCallbacks.traceMemcmp(first, second, 1, hookId);
748749
}
749750

@@ -777,6 +778,7 @@ public static void arraysCompare(
777778
if (returnValue == 0) return;
778779
byte[] first = (byte[]) arguments[0];
779780
byte[] second = (byte[]) arguments[1];
781+
if (first == null || second == null) return;
780782
TraceDataFlowNativeCallbacks.traceMemcmp(first, second, returnValue, hookId);
781783
}
782784

src/test/java/com/code_intelligence/jazzer/runtime/TraceCmpHooksTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,13 @@ public void cmpHookShouldHandleConcurrentModifications() throws InterruptedExcep
5252
// noinspection ResultOfMethodCallIgnored
5353
ES.awaitTermination(5, TimeUnit.SECONDS);
5454
}
55+
56+
@Test
57+
public void handlesNullValuesInArrayCompare() {
58+
byte[] b1 = new byte[10];
59+
byte[] b2 = null;
60+
// Make sure we don't crash the JVM on null arrays.
61+
TraceCmpHooks.arraysEquals(null, null, new Object[] {b1, b2}, 1, false);
62+
TraceCmpHooks.arraysCompare(null, null, new Object[] {b1, b2}, 1, 1);
63+
}
5564
}

0 commit comments

Comments
 (0)