Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AFL-fuzz hang/crash fixes #1886

Merged
merged 3 commits into from Feb 20, 2018
Merged

AFL-fuzz hang/crash fixes #1886

merged 3 commits into from Feb 20, 2018

Conversation

dezgeg
Copy link
Contributor

@dezgeg dezgeg commented Feb 20, 2018

Fix three issues AFL found in ~30 hours.

E.g. nix-instantiate --eval -E 'abort "\r"' hangs.

Found by afl-fuzz.
Otherwise, running e.g.

nix-instantiate --eval -E --strict 'builtins.replaceStrings [""] ["X"] "abc"'

would just hang in an infinite loop.

Found by afl-fuzz.
The assertion is broken because there is no one-to-one mapping from
length of a base64 string to the length of the output.

E.g.

"1q69lz7Empb06nzfkj651413n9icx0njmyr3xzq1j9q=" results in a 32-byte output.
"1q69lz7Empb06nzfkj651413n9icx0njmyr3xzq1j9qy" results in a 33-byte output.

To reproduce, evaluate:

builtins.derivationStrict {
    name = "0";
    builder = "0";
    system = "0";
    outputHashAlgo = "sha256";
    outputHash = "1q69lz7Empb06nzfkj651413n9icx0njmyr3xzq1j9qy";
}

Found by afl-fuzz.
@copumpkin
Copy link
Member

Nice! Have any information on your AFL setup for Nix? Might also be fun to try on macOS due to the different codepaths we exercise.

@dtzWill
Copy link
Member

dtzWill commented Feb 20, 2018

This is great!

Next stop.... OSS-Fuzz?

@@ -1216,7 +1216,7 @@ std::string filterANSIEscapes(const std::string & s, unsigned int width)

else if (*i == '\r')
// do nothing for now
;
i++;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, would love a C++ unit testing framework to put this in.

@shlevy shlevy merged commit 546f98d into NixOS:master Feb 20, 2018
@edolstra
Copy link
Member

The fix for an infinite loop in replaceString caused an infinite loop: e2d71bd.

edolstra added a commit that referenced this pull request Feb 21, 2018
… string"

This reverts commit 4ea9707.

It causes an infinite loop in Nixpkgs evaluation,
e.g. "nix-instantiate -A hello" hung.

PR #1886.
@dezgeg
Copy link
Contributor Author

dezgeg commented Feb 21, 2018

Eep. Will take a look.

@dezgeg
Copy link
Contributor Author

dezgeg commented Mar 2, 2018

@copumpkin The setup is at https://github.com/dezgeg/fuzz-nix. However I don't actually try to build the (potential) generated derivations, just evaluate them with nix-instantiate --dry-run --read-only-mode.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants