Skip to content

Commit

Permalink
pw_protobuf: Fix undefined pointer deref in fuzz test
Browse files Browse the repository at this point in the history
The encoder fuzz test can sometimes attempt to dereference an undefined
pointer to get its address, which is technically undefined behavior.
This fixes that occurance.

Change-Id: If67d58835ebc7a85813d60b6062ec88aab0e18c8
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/188281
Reviewed-by: Aaron Green <[email protected]>
Pigweed-Auto-Submit: Armando Montanez <[email protected]>
Presubmit-Verified: CQ Bot Account <[email protected]>
Commit-Queue: Auto-Submit <[email protected]>
  • Loading branch information
armandomontanez authored and CQ Bot Account committed Jan 18, 2024
1 parent fd1e0b7 commit 43ce442
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pw_protobuf/encoder_fuzzer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ const char* ConsumeString(FuzzedDataProvider& provider,
span<const std::byte> ConsumeBytes(FuzzedDataProvider& provider,
std::vector<std::byte>* data) {
size_t num = ConsumeSize<std::byte>(provider);
if (num == 0) {
return span<const std::byte>();
}
auto added = provider.ConsumeBytes<std::byte>(num);
size_t off = data->size();
num = added.size();
Expand Down

0 comments on commit 43ce442

Please sign in to comment.