Repository navigation
Fix buffer overflow in Android LogException via std::string concatenation - #1950
Merged
Merged
Conversation
…tion Replace the two strncat(buf, ..., sizeof(buf) - 1) calls in firebase::util::LogException with std::string concatenation, and use a stack-local buffer instead of a non-thread-safe static buffer when formatting log_fmt with vsnprintf. Resolves GitHub Code Scanning security alerts (Rule WS-C-00155): - https://github.com/firebase/firebase-cpp-sdk/security/code-scanning/2786 - https://github.com/firebase/firebase-cpp-sdk/security/code-scanning/2787
Contributor
There was a problem hiding this comment.
Code Review
This pull request refactors the LogException function in app/src/util_android.cc to prevent potential buffer overflows by replacing unsafe strncat operations with std::string concatenation, and updates the release notes. The feedback identifies a valid issue where the local buffer buf is left uninitialized, which could lead to undefined behavior if vsnprintf fails; initializing it to zero is recommended.
a-maurice
approved these changes
Oct 27, 2026
Integration test with FLAKINESS (succeeded after retry)Requested by @AustinBenoit on commit 961decf
Add flaky tests to go/fpl-cpp-flake-tracker |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Resolves GitHub Code Scanning security alerts (
WS-C-00155):In
firebase::util::LogException(app/src/util_android.cc), when formatting a JNI exception message with a non-nulllog_fmt, the previous implementation wrotelog_fmtinto a 512-bytestatic char buf[512]viavsnprintfand then calledstrncat(buf, ": ", sizeof(buf) - 1)andstrncat(buf, message_str.c_str(), sizeof(buf) - 1). Because the third parameter tostrncatis the maximum number of bytes to append rather than the total destination buffer size, a long Java exception message could write past the end ofbuf.This change:
strncatcalls withstd::stringconcatenation (message_str = std::string(buf) + ": " + message_str;).char buf[512]withvsnprintf(buf, sizeof(buf), log_fmt, list)instead of a non-thread-safestaticbuffer.### Upcominginrelease_build_files/readme.md.Testing
python3 scripts/format_code.py -git_diff -noformat_file -verbose.bash scripts/gha/check_copyright.sh -g.Type of Change
Place an
xthe applicable box:https://github.com/firebase/firebase-cpp-sdk/security/code-scanning/2786
https://github.com/firebase/firebase-cpp-sdk/security/code-scanning/2787
Notes
Release Notessection ofrelease_build_files/readme.md.