Skip to content

Conversation

practicalswift
Copy link
Contributor

@practicalswift practicalswift commented Feb 12, 2020

Context: C and C++ locale assumptions in bitcoind and bitcoin-qt

Add fuzzing harness for locale independence testing of functions in strencodings.h and tinyformat.h.

Test this PR using:

$ make distclean
$ ./autogen.sh
$ CC=clang CXX=clang++ ./configure --enable-fuzz \
      --with-sanitizers=address,fuzzer,undefined
$ make
$ src/test/fuzz/locale
…

The tested functions (ParseInt32(…), ParseInt64(…), atoi(const std::string&), atoi64(const std::string& str), i64tostr(const char*), itostr(…), strprintf(…)) all call locale dependent functions (such as strtol(…), strtoll(…), atoi(const char*), etc.) but are assumed to do so in a way that the tested functions return same results regardless of the chosen C locale (setlocale).

This fuzzer aims to test that those assumptions hold up also in practice now and over time.

@practicalswift practicalswift force-pushed the fuzzers-locale branch 2 times, most recently from 680f630 to fbd1d58 Compare February 12, 2020 15:01
@fanquake fanquake added the Tests label Feb 12, 2020
@DrahtBot
Copy link
Contributor

DrahtBot commented Feb 12, 2020

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

Reviewers, this pull request conflicts with the following ones:

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@practicalswift
Copy link
Contributor Author

Rebased! :)

@maflcko
Copy link
Member

maflcko commented Mar 6, 2020

The OP says "all call locale dependent functions", the title says "locale independence". Which is correct?

What is the point of a test that tests the functions are not locale independent?

@practicalswift
Copy link
Contributor Author

@MarcoFalke They all call functions that are known to be locale dependent (see list in lint-locale-dependence.sh) but they are supposed to do so in a way that guarantees that their own output is locale independent. Does that answer your question? :)

@maflcko maflcko merged commit 45cdcd4 into bitcoin:master Mar 6, 2020
@fanquake
Copy link
Member

fanquake commented Mar 6, 2020

This has broken Travis:

Run locale with args ['valgrind', '--quiet', '--error-exitcode=1', '/home/travis/build/bitcoin/bitcoin/build/bitcoin-x86_64-pc-linux-gnu/src/test/fuzz/locale', '-runs=1', '/home/travis/build/bitcoin/bitcoin/ci/scratch//qa-assets/fuzz_seed_corpus/locale']
Output: INFO: Seed: 818858521
INFO: Loaded 1 modules   (1402 inline 8-bit counters): 1402 [0x3a7c40, 0x3a81ba), 
INFO: Loaded 1 PC tables (1402 PCs): 1402 [0x3a81c0,0x3ad960), 
No such file or directory: /home/travis/build/bitcoin/bitcoin/ci/scratch//qa-assets/fuzz_seed_corpus/locale; exiting
INFO: Seed: 818858521
INFO: Loaded 1 modules   (1402 inline 8-bit counters): 1402 [0x3a7c40, 0x3a81ba), 
INFO: Loaded 1 PC tables (1402 PCs): 1402 [0x3a81c0,0x3ad960), 
No such file or directory: /home/travis/build/bitcoin/bitcoin/ci/scratch//qa-assets/fuzz_seed_corpus/locale; exiting
Target "locale" failed with exit code 1: valgrind --quiet --error-exitcode=1 /home/travis/build/bitcoin/bitcoin/build/bitcoin-x86_64-pc-linux-gnu/src/test/fuzz/locale -runs=1 /home/travis/build/bitcoin/bitcoin/ci/scratch//qa-assets/fuzz_seed_corpus/locale

I assume seeds just need to be added to https://github.com/bitcoin-core/qa-assets?

fanquake added a commit that referenced this pull request Mar 7, 2020
…d unbreak Travis! :))

0d0bc3b build: Add locale fuzzer to FUZZERS_MISSING_CORPORA (practicalswift)

Pull request description:

  Add `locale` fuzzer to `FUZZERS_MISSING_CORPORA`.

  This is a follow-up to #18126 which broke Travis. Sorry about that :)

ACKs for top commit:
  fanquake:
    ACK 0d0bc3b

Tree-SHA512: c0968dc798839f87c891d1dfccf5541883ac56b51a29f52244e78c221c9c087d2dea0a959612d907d53b29fca1f486b340227b17653227ecbf6ca5ab0e85b0d3
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Mar 7, 2020
…ORA (and unbreak Travis! :))

0d0bc3b build: Add locale fuzzer to FUZZERS_MISSING_CORPORA (practicalswift)

Pull request description:

  Add `locale` fuzzer to `FUZZERS_MISSING_CORPORA`.

  This is a follow-up to bitcoin#18126 which broke Travis. Sorry about that :)

ACKs for top commit:
  fanquake:
    ACK 0d0bc3b

Tree-SHA512: c0968dc798839f87c891d1dfccf5541883ac56b51a29f52244e78c221c9c087d2dea0a959612d907d53b29fca1f486b340227b17653227ecbf6ca5ab0e85b0d3
jasonbcox pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Nov 4, 2020
Summary:
```
Context: C and C++ locale assumptions in bitcoind and bitcoin-qt

Add fuzzing harness for locale independence testing of functions in
strencodings.h and tinyformat.h.
```

Backport of core [[bitcoin/bitcoin#18126 | PR18126]].

Test Plan:
  ninja bitcoin-fuzzers
  ./test/fuzz/test_runner.py <path_to_corpus>

Reviewers: #bitcoin_abc, PiRK

Reviewed By: PiRK

Differential Revision: https://reviews.bitcoinabc.org/D8251
sidhujag pushed a commit to syscoin-core/syscoin that referenced this pull request Nov 10, 2020
…ORA (and unbreak Travis! :))

0d0bc3b build: Add locale fuzzer to FUZZERS_MISSING_CORPORA (practicalswift)

Pull request description:

  Add `locale` fuzzer to `FUZZERS_MISSING_CORPORA`.

  This is a follow-up to bitcoin#18126 which broke Travis. Sorry about that :)

ACKs for top commit:
  fanquake:
    ACK 0d0bc3b

Tree-SHA512: c0968dc798839f87c891d1dfccf5541883ac56b51a29f52244e78c221c9c087d2dea0a959612d907d53b29fca1f486b340227b17653227ecbf6ca5ab0e85b0d3
@practicalswift practicalswift deleted the fuzzers-locale branch April 10, 2021 19:39
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Sep 17, 2021
…ORA (and unbreak Travis! :))

0d0bc3b build: Add locale fuzzer to FUZZERS_MISSING_CORPORA (practicalswift)

Pull request description:

  Add `locale` fuzzer to `FUZZERS_MISSING_CORPORA`.

  This is a follow-up to bitcoin#18126 which broke Travis. Sorry about that :)

ACKs for top commit:
  fanquake:
    ACK 0d0bc3b

Tree-SHA512: c0968dc798839f87c891d1dfccf5541883ac56b51a29f52244e78c221c9c087d2dea0a959612d907d53b29fca1f486b340227b17653227ecbf6ca5ab0e85b0d3
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Sep 18, 2021
…ORA (and unbreak Travis! :))

0d0bc3b build: Add locale fuzzer to FUZZERS_MISSING_CORPORA (practicalswift)

Pull request description:

  Add `locale` fuzzer to `FUZZERS_MISSING_CORPORA`.

  This is a follow-up to bitcoin#18126 which broke Travis. Sorry about that :)

ACKs for top commit:
  fanquake:
    ACK 0d0bc3b

Tree-SHA512: c0968dc798839f87c891d1dfccf5541883ac56b51a29f52244e78c221c9c087d2dea0a959612d907d53b29fca1f486b340227b17653227ecbf6ca5ab0e85b0d3
thelazier pushed a commit to thelazier/dash that referenced this pull request Sep 25, 2021
…ORA (and unbreak Travis! :))

0d0bc3b build: Add locale fuzzer to FUZZERS_MISSING_CORPORA (practicalswift)

Pull request description:

  Add `locale` fuzzer to `FUZZERS_MISSING_CORPORA`.

  This is a follow-up to bitcoin#18126 which broke Travis. Sorry about that :)

ACKs for top commit:
  fanquake:
    ACK 0d0bc3b

Tree-SHA512: c0968dc798839f87c891d1dfccf5541883ac56b51a29f52244e78c221c9c087d2dea0a959612d907d53b29fca1f486b340227b17653227ecbf6ca5ab0e85b0d3
kwvg added a commit to kwvg/dash that referenced this pull request Feb 27, 2022
kwvg added a commit to kwvg/dash that referenced this pull request Feb 27, 2022
kwvg added a commit to kwvg/dash that referenced this pull request Feb 28, 2022
kwvg added a commit to kwvg/dash that referenced this pull request Feb 28, 2022
kwvg added a commit to kwvg/dash that referenced this pull request Feb 28, 2022
kwvg added a commit to kwvg/dash that referenced this pull request Feb 28, 2022
kwvg added a commit to kwvg/dash that referenced this pull request Mar 13, 2022
kwvg added a commit to kwvg/dash that referenced this pull request Mar 24, 2022
kwvg added a commit to kwvg/dash that referenced this pull request Mar 24, 2022
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Aug 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants