Fix crashes in Clojure-related hooks: NPE on nil var root and CCE in traceGenericCmp - #1065
Open
just-sultanov wants to merge 2 commits into
Open
Conversation
The AFTER hook on clojure.lang.Var.getRawRoot dereferenced the result without a null check, throwing a NullPointerException for non-dynamic vars with a nil root (e.g. riddley 0.2.2) and aborting fuzzing during target class loading. Skip the contains check when the result is null and add a regression test.
mapHookInternal and setHookInternal find bracketing keys/elements via compareTo, which can succeed across incompatible Number implementations (e.g. clojure.lang.Ratio vs. java.lang.Double). The unboxing in traceGenericCmp requires both operands to have the same runtime class and otherwise throws a ClassCastException. Only trace comparisons when the bracketing key/element has the same class as the lookup key and add regression tests.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two fixes for crashes in built-in hooks discovered while fuzzing Clojure projects.
In both cases the exception is thrown from inside the fuzz target's class loading (
ExceptionInInitializerError) and aborts fuzzing before any iteration runs.1. NPE in
ClojureLangHooks.clojureMarkContainson nil var rootThe AFTER hook on
clojure.lang.Var.getRawRootdereferenced the hook result without a null check. Reading a non-dynamic var with anilroot (e.g.(def ^:private bb? (System/getProperty "babashka.version"))inriddley 0.2.2, pulled in transitively bymanifold->potemkin->riddley) passesresult = nullinto the hook, throwing an NPE.Skip the contains check when the result is
null.2.
ClassCastExceptioninTraceCmpHooks.mapHookInternal/setHookInternalBracketing keys/elements are found via
compareTo, which can succeed across incompatibleNumberimplementations (e.g.clojure.lang.Ratiovs.java.lang.Doublein a sorted map). The unboxing intraceGenericCmprequires both operands to have the same runtime class and otherwise throws aClassCastException.Only trace comparisons when the bracketing key/element has the same runtime class as the lookup key/element.
Testing
ClojureLangHooksTestandTraceCmpHooksTest.mainand pass with the fix.