-
Notifications
You must be signed in to change notification settings - Fork 37.7k
build: Add format string linter #13705
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
Conversation
933c042
to
d418963
Compare
@practicalswift Is this for a specific bug/issue you've seen previously? |
@fanquake In the past there has been at least one incident where a mistake in the log message formatting resulted in a near DoS vulnerability. It was an under-tested error path in the network code with an invalid @laanwj suggested writing a format string linter in #9423 (comment). |
Yes, I think this is very useful! we've had some issues with this in the past. Thank for writing it in Python instead of making a long shell mess, this means I can usefully review it. |
Needs rebase for some reason |
This linter checks that the number of arguments passed to each variadic format string function matches the number of format specifiers in the format string.
d418963
to
a3e4556
Compare
@laanwj Weird! Now rebased! |
Thanks, new error:
|
@laanwj Oh, a good chance to add linting also of |
ACK bcd4b0f |
bcd4b0f Add linting of WalletLogPrintf(...) format strings (practicalswift) a3e4556 build: Add format string linter (practicalswift) Pull request description: Add format string linter. This linter checks that the number of arguments passed to each variadic format string function matches the number of format specifiers in the format string. Example output: ``` $ test/lint/lint-format-strings.sh src/init.cpp: Expected 2 argument(s) after format string but found 1 argument(s): LogPrintf("We have a mismatch here: foo=%s bar=%d\n", foo) src/init.cpp: Expected 1 argument(s) after format string but found 2 argument(s): LogPrint(BCLog::RPC, "RPC stopped. This is a mismatch: %s\n", s1, s2) $ echo $? 1 ``` Tree-SHA512: 19ab844a63f04bf193d66682ca42745a1c7d6c454b30222491b9fe8dc047054c4a6d3ee7921ec0676fb9ca2e7f6f93bd6c97996fb09667269bd491cb875349f3
This won't allow have template inside: https://travis-ci.org/bitcoin/bitcoin/jobs/414449333 |
@ken2812221 Oh, interesting! I’ll fix that. Thanks for reporting. In the meantime you can just add an exception ( |
…se of uninitialized memory 870f0cd build: Add MemorySanitizer (MSan) in Travis to detect use of uninitialized memory (practicalswift) Pull request description: Add MemorySanitizer (MSan) in Travis to detect use of uninitialized memory. First UBSan, then ASan followed by TSan... and now: yes, the wait is over -- **MSan is finally here!** :) Some historical context: * 2017: Continuous compilation with Clang Thread Safety analysis enabled (#10866, #10923) * 2018: Continuous testing with trapping on signed integer overflows (`-ftrapv`) (#12686) * 2018: Continuous testing of use of locale dependent functions (#13041) * 2018: Continuous testing of format strings (#13705) * 2018: Continuous compilation with MSVC `TreatWarningAsError` (#14151) * 2018: Continuous testing under UndefinedBehaviorSanitizer – UBSan (#14252, #14673, #17006) * 2018: Continuous testing under AddressSanitizer – ASan (#14794, #17205, #17674) * 2018: Continuous testing under ThreadSanitizer – TSan (#14829) * 2019: Continuous testing in an unsigned char environment (`-funsigned-char`) (#15134) * 2019: Continuous compile-time testing of assumptions we're making (#15391) * 2019: Continuous testing of fuzz test cases under Valgrind (#17633, #18159, #18166) * 2020: Finally... MemorySanitizer – MSAN! :) What is the next step? What tools should we add to CI to keep bugs from entering `master`? :) ACKs for top commit: MarcoFalke: ACK 870f0cd Tree-SHA512: 38327c8b75679d97d469fe42e704cacd1217447a5a603701dd8a58ee50b3be2c10248f8d68a479ed081c0c4b254589d3081c9183f991640b06ef689061f75578
bcd4b0f Add linting of WalletLogPrintf(...) format strings (practicalswift) a3e4556 build: Add format string linter (practicalswift) Pull request description: Add format string linter. This linter checks that the number of arguments passed to each variadic format string function matches the number of format specifiers in the format string. Example output: ``` $ test/lint/lint-format-strings.sh src/init.cpp: Expected 2 argument(s) after format string but found 1 argument(s): LogPrintf("We have a mismatch here: foo=%s bar=%d\n", foo) src/init.cpp: Expected 1 argument(s) after format string but found 2 argument(s): LogPrint(BCLog::RPC, "RPC stopped. This is a mismatch: %s\n", s1, s2) $ echo $? 1 ``` Tree-SHA512: 19ab844a63f04bf193d66682ca42745a1c7d6c454b30222491b9fe8dc047054c4a6d3ee7921ec0676fb9ca2e7f6f93bd6c97996fb09667269bd491cb875349f3
bcd4b0f Add linting of WalletLogPrintf(...) format strings (practicalswift) a3e4556 build: Add format string linter (practicalswift) Pull request description: Add format string linter. This linter checks that the number of arguments passed to each variadic format string function matches the number of format specifiers in the format string. Example output: ``` $ test/lint/lint-format-strings.sh src/init.cpp: Expected 2 argument(s) after format string but found 1 argument(s): LogPrintf("We have a mismatch here: foo=%s bar=%d\n", foo) src/init.cpp: Expected 1 argument(s) after format string but found 2 argument(s): LogPrint(BCLog::RPC, "RPC stopped. This is a mismatch: %s\n", s1, s2) $ echo $? 1 ``` Tree-SHA512: 19ab844a63f04bf193d66682ca42745a1c7d6c454b30222491b9fe8dc047054c4a6d3ee7921ec0676fb9ca2e7f6f93bd6c97996fb09667269bd491cb875349f3
bcd4b0f Add linting of WalletLogPrintf(...) format strings (practicalswift) a3e4556 build: Add format string linter (practicalswift) Pull request description: Add format string linter. This linter checks that the number of arguments passed to each variadic format string function matches the number of format specifiers in the format string. Example output: ``` $ test/lint/lint-format-strings.sh src/init.cpp: Expected 2 argument(s) after format string but found 1 argument(s): LogPrintf("We have a mismatch here: foo=%s bar=%d\n", foo) src/init.cpp: Expected 1 argument(s) after format string but found 2 argument(s): LogPrint(BCLog::RPC, "RPC stopped. This is a mismatch: %s\n", s1, s2) $ echo $? 1 ``` Tree-SHA512: 19ab844a63f04bf193d66682ca42745a1c7d6c454b30222491b9fe8dc047054c4a6d3ee7921ec0676fb9ca2e7f6f93bd6c97996fb09667269bd491cb875349f3
… template parameter syntax 4441ad6 Make format string linter understand basic template parameter syntax (practicalswift) Pull request description: Make format string linter understand basic template parameter syntax. Fixes issue described in bitcoin#13705 (comment). Thanks to @ken2812221 for reporting! Tree-SHA512: 8fb995bc6b29d8b9926ef5969e02cf71c494e829434fcdeb4ed5fabad5ab96e86e5b8eea705e8a416927757b4fa4e58abc0fd4f483daa58c94e2c6fdcb8ee822
… template parameter syntax 4441ad6 Make format string linter understand basic template parameter syntax (practicalswift) Pull request description: Make format string linter understand basic template parameter syntax. Fixes issue described in bitcoin#13705 (comment). Thanks to @ken2812221 for reporting! Tree-SHA512: 8fb995bc6b29d8b9926ef5969e02cf71c494e829434fcdeb4ed5fabad5ab96e86e5b8eea705e8a416927757b4fa4e58abc0fd4f483daa58c94e2c6fdcb8ee822
… template parameter syntax 4441ad6 Make format string linter understand basic template parameter syntax (practicalswift) Pull request description: Make format string linter understand basic template parameter syntax. Fixes issue described in bitcoin#13705 (comment). Thanks to @ken2812221 for reporting! Tree-SHA512: 8fb995bc6b29d8b9926ef5969e02cf71c494e829434fcdeb4ed5fabad5ab96e86e5b8eea705e8a416927757b4fa4e58abc0fd4f483daa58c94e2c6fdcb8ee822
… template parameter syntax 4441ad6 Make format string linter understand basic template parameter syntax (practicalswift) Pull request description: Make format string linter understand basic template parameter syntax. Fixes issue described in bitcoin#13705 (comment). Thanks to @ken2812221 for reporting! Tree-SHA512: 8fb995bc6b29d8b9926ef5969e02cf71c494e829434fcdeb4ed5fabad5ab96e86e5b8eea705e8a416927757b4fa4e58abc0fd4f483daa58c94e2c6fdcb8ee822
… template parameter syntax 4441ad6 Make format string linter understand basic template parameter syntax (practicalswift) Pull request description: Make format string linter understand basic template parameter syntax. Fixes issue described in bitcoin#13705 (comment). Thanks to @ken2812221 for reporting! Tree-SHA512: 8fb995bc6b29d8b9926ef5969e02cf71c494e829434fcdeb4ed5fabad5ab96e86e5b8eea705e8a416927757b4fa4e58abc0fd4f483daa58c94e2c6fdcb8ee822
… template parameter syntax 4441ad6 Make format string linter understand basic template parameter syntax (practicalswift) Pull request description: Make format string linter understand basic template parameter syntax. Fixes issue described in bitcoin#13705 (comment). Thanks to @ken2812221 for reporting! Tree-SHA512: 8fb995bc6b29d8b9926ef5969e02cf71c494e829434fcdeb4ed5fabad5ab96e86e5b8eea705e8a416927757b4fa4e58abc0fd4f483daa58c94e2c6fdcb8ee822
… template parameter syntax 4441ad6 Make format string linter understand basic template parameter syntax (practicalswift) Pull request description: Make format string linter understand basic template parameter syntax. Fixes issue described in bitcoin#13705 (comment). Thanks to @ken2812221 for reporting! Tree-SHA512: 8fb995bc6b29d8b9926ef5969e02cf71c494e829434fcdeb4ed5fabad5ab96e86e5b8eea705e8a416927757b4fa4e58abc0fd4f483daa58c94e2c6fdcb8ee822
…etect use of uninitialized memory 870f0cd build: Add MemorySanitizer (MSan) in Travis to detect use of uninitialized memory (practicalswift) Pull request description: Add MemorySanitizer (MSan) in Travis to detect use of uninitialized memory. First UBSan, then ASan followed by TSan... and now: yes, the wait is over -- **MSan is finally here!** :) Some historical context: * 2017: Continuous compilation with Clang Thread Safety analysis enabled (bitcoin#10866, bitcoin#10923) * 2018: Continuous testing with trapping on signed integer overflows (`-ftrapv`) (bitcoin#12686) * 2018: Continuous testing of use of locale dependent functions (bitcoin#13041) * 2018: Continuous testing of format strings (bitcoin#13705) * 2018: Continuous compilation with MSVC `TreatWarningAsError` (bitcoin#14151) * 2018: Continuous testing under UndefinedBehaviorSanitizer – UBSan (bitcoin#14252, bitcoin#14673, bitcoin#17006) * 2018: Continuous testing under AddressSanitizer – ASan (bitcoin#14794, bitcoin#17205, bitcoin#17674) * 2018: Continuous testing under ThreadSanitizer – TSan (bitcoin#14829) * 2019: Continuous testing in an unsigned char environment (`-funsigned-char`) (bitcoin#15134) * 2019: Continuous compile-time testing of assumptions we're making (bitcoin#15391) * 2019: Continuous testing of fuzz test cases under Valgrind (bitcoin#17633, bitcoin#18159, bitcoin#18166) * 2020: Finally... MemorySanitizer – MSAN! :) What is the next step? What tools should we add to CI to keep bugs from entering `master`? :) ACKs for top commit: MarcoFalke: ACK 870f0cd Tree-SHA512: 38327c8b75679d97d469fe42e704cacd1217447a5a603701dd8a58ee50b3be2c10248f8d68a479ed081c0c4b254589d3081c9183f991640b06ef689061f75578
bcd4b0f Add linting of WalletLogPrintf(...) format strings (practicalswift) a3e4556 build: Add format string linter (practicalswift) Pull request description: Add format string linter. This linter checks that the number of arguments passed to each variadic format string function matches the number of format specifiers in the format string. Example output: ``` $ test/lint/lint-format-strings.sh src/init.cpp: Expected 2 argument(s) after format string but found 1 argument(s): LogPrintf("We have a mismatch here: foo=%s bar=%d\n", foo) src/init.cpp: Expected 1 argument(s) after format string but found 2 argument(s): LogPrint(BCLog::RPC, "RPC stopped. This is a mismatch: %s\n", s1, s2) $ echo $? 1 ``` Tree-SHA512: 19ab844a63f04bf193d66682ca42745a1c7d6c454b30222491b9fe8dc047054c4a6d3ee7921ec0676fb9ca2e7f6f93bd6c97996fb09667269bd491cb875349f3
Add format string linter.
This linter checks that the number of arguments passed to each variadic format string function matches the number of format specifiers in the format string.
Example output: