-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #503 from cppalliance/overflow
Add fuzzing to snprintf and fix overflow
- Loading branch information
Showing
11 changed files
with
1,129 additions
and
38 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright 2024 Matt Borland | ||
// Distributed under the Boost Software License, Version 1.0. | ||
// https://www.boost.org/LICENSE_1_0.txt | ||
|
||
#include <boost/decimal.hpp> | ||
#include <iostream> | ||
#include <exception> | ||
#include <string> | ||
#include <array> | ||
|
||
extern "C" int LLVMFuzzerTestOneInput(const std::uint8_t* data, std::size_t size) | ||
{ | ||
try | ||
{ | ||
auto c_data = reinterpret_cast<const char*>(data); | ||
|
||
const auto formats = std::array<boost::decimal::chars_format, 4>{boost::decimal::chars_format::general, | ||
boost::decimal::chars_format::fixed, | ||
boost::decimal::chars_format::scientific, | ||
boost::decimal::chars_format::hex}; | ||
|
||
const auto dec32_printf_formats = std::array<const char*, 4>{"%Hg", "%Hf", "%He", "%Ha"}; | ||
const auto dec64_printf_formats = std::array<const char*, 4>{"%Dg", "%Df", "%De", "%Da"}; | ||
const auto dec128_printf_formats = std::array<const char*, 4>{"%DDg", "%DDf", "%DDe", "%DDa"}; | ||
|
||
for (std::size_t i {}; i < 4; ++i) | ||
{ | ||
char buffer[20]; // Small enough it should overflow sometimes | ||
|
||
boost::decimal::decimal32 f_val {}; | ||
boost::decimal::from_chars(c_data, c_data + size, f_val, formats[i]); | ||
boost::decimal::snprintf(buffer, sizeof(buffer), dec32_printf_formats[i], f_val); | ||
|
||
boost::decimal::decimal64 val {}; | ||
boost::decimal::from_chars(c_data, c_data + size, val, formats[i]); | ||
boost::decimal::snprintf(buffer, sizeof(buffer), dec64_printf_formats[i], val); | ||
|
||
boost::decimal::decimal128 ld_val {}; | ||
boost::decimal::from_chars(c_data, c_data + size, ld_val, formats[i]); | ||
boost::decimal::snprintf(buffer, sizeof(buffer), dec128_printf_formats[i], ld_val); | ||
} | ||
} | ||
catch(...) | ||
{ | ||
std::cerr << "Error with: " << data << std::endl; | ||
std::terminate(); | ||
} | ||
|
||
return 0; | ||
} |
Binary file added
BIN
+54 Bytes
fuzzing/old_crashes/fuzz_snprintf/crash-0f98407c0445c159941e51537e7e1aef12389cb9
Binary file not shown.
Binary file added
BIN
+104 Bytes
fuzzing/old_crashes/fuzz_snprintf/crash-39b3bbdd25caf060db102da1e205ae425d00bd4a
Binary file not shown.
4 changes: 4 additions & 0 deletions
4
fuzzing/old_crashes/fuzz_snprintf/crash-4d4789c815eca915bafcab20e0616937b61b420e
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
-2679829776778; | ||
09KKK | ||
6778; | ||
85e-q |
Binary file added
BIN
+51 Bytes
fuzzing/old_crashes/fuzz_snprintf/crash-64658a68226236a90a22b345a5246a9d757a85ba
Binary file not shown.
Binary file added
BIN
+52 Bytes
fuzzing/old_crashes/fuzz_snprintf/crash-84f646031cc6bba521a785bc54f8f0d46e87f17f
Binary file not shown.
Binary file added
BIN
+54 Bytes
fuzzing/old_crashes/fuzz_snprintf/crash-fba81762857f7cfb462a37424bcbae34df9ad8c2
Binary file not shown.
Oops, something went wrong.