From 1575e74afc015daebd9d490db9dc9dc8807e8d99 Mon Sep 17 00:00:00 2001 From: ManasBagul23 Date: Thu, 5 Nov 2026 11:24:46 +0530 Subject: [PATCH] ppdc: null-terminate token buffer after variable substitution get_token() substitutes a #define'd variable's value into the current token with strncpy(), but strncpy() does not add a terminating NUL when the source is at least as long as the number of bytes copied. Once that happens the following strlen() walks off the end of the caller's buffer (some of which, like get_po()'s 32-byte locale name, are much smaller than the 1024 bytes a variable's value can hold), and the unconditional NUL write at the end of get_token() then lands outside the buffer too. Switch to snprintf(), which always leaves the destination properly terminated, matching what the "undefined variable" branch right below it already does. --- ppd/ppdc-source.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ppd/ppdc-source.cxx b/ppd/ppdc-source.cxx index e780bfa5..46d8dfc5 100644 --- a/ppd/ppdc-source.cxx +++ b/ppd/ppdc-source.cxx @@ -2012,7 +2012,7 @@ ppdcSource::get_token(ppdcFile *fp, // I - File to read var = find_variable(name); if (var) { - strncpy(bufptr, var->value->value, (size_t)(bufend - bufptr + 1)); + snprintf(bufptr, (size_t)(bufend - bufptr + 1), "%s", var->value->value); bufptr += strlen(bufptr); } else