[PATCH] locale: Fix heap buffer overflow in get_string wide character buffer
panzhe0328
panzhe@kylinos.cn
Thu Nov 19 08:25:15 GMT 2026
From: panzhe <panzhe@kylinos.cn>
buf2max is initialized in bytes but used as an element count, so the
initial allocation holds only 56 elements while the growth guard does
not fire until element 224. A quoted wide string of 57 or more
characters therefore writes past the end of the 224-byte block.
Initialize buf2max to 56 and allocate buf2max * sizeof (uint32_t) bytes.
Signed-off-by: panzhe <panzhe@kylinos.cn>
---
locale/programs/linereader.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/locale/programs/linereader.c b/locale/programs/linereader.c
index d3c45fea35..2cf6cfcfbf 100644
--- a/locale/programs/linereader.c
+++ b/locale/programs/linereader.c
@@ -813,12 +813,12 @@ get_string (struct linereader *lr, const struct charmap_t *charmap,
{
bool illegal_string = false;
size_t buf2act = 0;
- size_t buf2max = 56 * sizeof (uint32_t);
+ size_t buf2max = 56;
int ch;
/* We have to provide the wide character result as well. */
if (return_widestr)
- buf2 = xmalloc (buf2max);
+ buf2 = xmalloc (buf2max * sizeof (uint32_t));
/* Read until the end of the string (or end of the line or file). */
while ((ch = lr_getc (lr)) != '"' && ch != '\n' && ch != EOF)
--
2.54.0
More information about the Libc-alpha
mailing list