UBSan: pointer index expression overflowed [@ GetTrimmableWhitespaceCount]
Categories
(Core :: Layout: Text and Fonts, defect, P2)
Tracking
()
People
(Reporter: tsmith, Assigned: away)
References
(Blocks 2 open bugs)
Details
(Keywords: csectype-undefined, testcase)
Attachments
(2 files)
Comment 1•7 years ago
|
||
Reporter | ||
Updated•6 years ago
|
Reporter | ||
Updated•6 years ago
|
const char* str = aFrag->Get1b() + aStartOffset;
for (; count < aLength; ++count) {
if (!IsTrimmableSpace(*str)) break;
str += aDirection;
}
My debugger says:
aStartOffset = 0n-1
aLength = 0n0
aDirection = 0n-1
and aFrag's string pointer is null.
So we construct this invalid pointer by doing nullptr + (-1)
but we never read from it because the for loop's condition is never satisfied.
What is the preferred technique for dealing with this? Should we add a aLength > 0
check to appease the checker? Should we consider it a false positive? Should the caller be modified not to call this function if length is 0?
ubsan was complaining about the expression
const char* str = aFrag->Get1b() + aStartOffset;
when aFrag->Get1b() == nullptr
and aStartOffset == -1
, because the addition generates an invalid pointer.
Due to other logic in the function, we would never dereference that pointer, so it was reasonably harmless, but this patch silences the complaint.
Comment 6•6 years ago
|
||
bugherder |
Updated•6 years ago
|
Updated•6 years ago
|
Description
•