Commit e8feba9
committed
Fix stack buffer overflow in LocalizeRadix()
LocalizeRadix() uses strcpy() to copy the remainder of the input string
into an 80-byte stack buffer without bounds checking. When parsing a
floating-point number longer than ~78 characters in a locale where the
radix character differs from '.', the strcpy overflows the buffer.
The fix replaces the fixed-size stack buffer with a dynamically sized
one (stack-allocated up to 256 bytes, heap-allocated for longer strings),
and uses memcpy with explicit length instead of strcpy.
Reproducer:
LC_ALL=de_DE.UTF-8
Parse float string "1.000...001" with >80 characters
-> AddressSanitizer: stack-buffer-overflow in LocalizeRadix (strtod.c:43)1 parent 25445bc commit e8feba9
1 file changed
+19
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| 34 | + | |
34 | 35 | | |
35 | | - | |
36 | | - | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
37 | 39 | | |
38 | 40 | | |
39 | 41 | | |
| 42 | + | |
40 | 43 | | |
41 | 44 | | |
42 | 45 | | |
43 | | - | |
| 46 | + | |
| 47 | + | |
44 | 48 | | |
45 | 49 | | |
46 | 50 | | |
| |||
59 | 63 | | |
60 | 64 | | |
61 | 65 | | |
62 | | - | |
63 | | - | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
64 | 76 | | |
65 | 77 | | |
66 | 78 | | |
| |||
73 | 85 | | |
74 | 86 | | |
75 | 87 | | |
| 88 | + | |
| 89 | + | |
76 | 90 | | |
77 | 91 | | |
0 commit comments