This is an archive of the discontinued LLVM Phabricator instance.

[compiler-rt] Fix incorrect use of snprintf
ClosedPublic

Authored by vitalybuka on Feb 2 2017, 1:09 AM.

Details

Summary

snprintf returns buffer size needed for printing. If buffer was small, calling
code receives incorrectly symbolized buffer and fail.

Diff Detail

Repository
rL LLVM

Event Timeline

vitalybuka created this revision.Feb 2 2017, 1:09 AM
vitalybuka updated this revision to Diff 86778.Feb 2 2017, 1:12 AM

Additional warning

eugenis added inline comments.Feb 2 2017, 11:54 AM
lib/sanitizer_common/sanitizer_symbolizer_libcdep.cc
361 ↗(On Diff #86778)

I think it should be >=.

Writes at most "length" symbols to "buffer" (including trailing '\0').
Returns the number of symbols that should have been written to buffer
(not including trailing '\0'). Thus, the string is truncated
iff return value is not less than "length".

lib/sanitizer_common/symbolizer/sanitizer_symbolize.cc
45 ↗(On Diff #86778)

I think it should be <.

vitalybuka updated this revision to Diff 86869.Feb 2 2017, 12:08 PM

snprintf returned value does not include termination 0

vitalybuka marked 2 inline comments as done.Feb 2 2017, 12:08 PM
eugenis accepted this revision.Feb 2 2017, 12:16 PM
eugenis added inline comments.
test/sanitizer_common/TestCases/symbolize_stack.cc
1 ↗(On Diff #86869)

add a comment that you are testing symbolization of very long function names

This revision is now accepted and ready to land.Feb 2 2017, 12:16 PM
vitalybuka marked an inline comment as done.Feb 2 2017, 12:20 PM
This revision was automatically updated to reflect the committed changes.