Fix snprintf buffer too small in exec_ddprof()#499
Open
xroche wants to merge 1 commit intoDataDog:mainfrom
Open
Fix snprintf buffer too small in exec_ddprof()#499xroche wants to merge 1 commit intoDataDog:mainfrom
xroche wants to merge 1 commit intoDataDog:mainfrom
Conversation
digits10 returns the number of decimal digits that round-trip through the type (floor(log10(2^31-1)) = 9), not the number of digits in the max value. The max pid_t (2,147,483,647) has 10 digits, so the buffer needs digits10 + 2 (max digits + NUL), not digits10 + 1. With digits10 + 1 (= 10 bytes), snprintf silently truncates 10-digit values, potentially passing a wrong PID to execve. Fixes DataDog#496
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.
What does this PR do?
Fix
snprintfbuffer sizing inexec_ddprof()(src/lib/dd_profiling.cc).digits10returns the number of decimal digits that can round-trip through the type (floor(log10(2^31 - 1))= 9), not the number of digits in the maximum value. The maxpid_t(2,147,483,647) has 10 digits, so the buffer needsdigits10 + 2(max digits + NUL), notdigits10 + 1.With the current size (10 bytes),
snprintfsilently truncates 10-digit values, potentially passing a wrong PID toexecve.Motivation
Same class of buffer sizing bug as #492 (off-by-one in
loader.c), but in the C++ library mode entry pointexec_ddprof().How to test the change?
The bug is currently mitigated by Linux PID limits (max 2^22 = 7 digits), so it doesn't trigger in practice. The fix is a straightforward buffer size correction.
Classification
Fixes #496