Fix OOB read in stdlib thousand grouping parsing [BZ #29727]
commit17bfe5954baee1f18672aea94caa1126ec36fb81
authorSzabolcs Nagy <szabolcs.nagy@arm.com>
Tue, 11 Oct 2022 14:24:41 +0000 (11 15:24 +0100)
committerSzabolcs Nagy <szabolcs.nagy@arm.com>
Wed, 2 Nov 2022 15:42:27 +0000 (2 15:42 +0000)
tree985ff73ad29bc4cc4e15ce6d182ecd808b7b02d7
parent7457b7eef8dfe8cc48e55b9f9837df6dd397b80d
Fix OOB read in stdlib thousand grouping parsing [BZ #29727]

__correctly_grouped_prefixmb only worked with thousands_len == 1,
otherwise it read past the end of cp or thousands.

This affects scanf formats like %'d, %'f and the internal but
exposed __strto{l,ul,f,d,..}_internal with grouping flag set
and an LC_NUMERIC locale where thousands_len > 1.

Avoid OOB access by considering thousands_len when initializing cp.
This fixes bug 29727.

Found by the morello port with strict bounds checking where

FAIL: stdlib/tst-strtod4
FAIL: stdlib/tst-strtod5i

crashed using a locale with thousands_len==3.
stdlib/grouping.c