From 2190529c5ead6e0eab95b62fa07557226b090ca4 Mon Sep 17 00:00:00 2001 From: Armaan Sandhu Date: Sun, 1 Nov 2026 19:10:26 -0500 Subject: [PATCH] pdftops: fix the printer make and model used for quirks For a printer-make-and-model starting with "Hewlett-Packard " or "Hewlett Packard ", strncpy(make, "HP", sizeof(make)) pads the rest of the buffer with NULs, which wipes the model it was about to use. "Hewlett-Packard LaserJet 4000" came out as "HP ", so the HP LaserJet quirks never matched. Write just "HP" and its terminator instead. In the PPD case, ppd->product is only set if the PPD has a *Product line, so without one ppd->product + 1 crashes, and an empty *Product reads past the end of the string. Leave the make and model empty in those cases, the code after it already handles that. --- ppd/pdftops.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ppd/pdftops.c b/ppd/pdftops.c index a53f8e40..0d0c1a27 100644 --- a/ppd/pdftops.c +++ b/ppd/pdftops.c @@ -447,7 +447,7 @@ ppdFilterPDFToPS(int inputfd, // I - File descriptor input stream !strncasecmp(make, "Hewlett-Packard ", 16)) { model = make + 16; - strncpy(make, "HP", sizeof(make)); + memcpy(make, "HP", 3); // Not strncpy(), that would pad over the model } else if ((model = strchr(make, ' ')) != NULL) *model++ = '\0'; @@ -456,7 +456,7 @@ ppdFilterPDFToPS(int inputfd, // I - File descriptor input stream snprintf(make_model, sizeof(make_model), "%s %s", make, model); } } - else if (ppd) + else if (ppd && ppd->manufacturer && ppd->product && ppd->product[0]) { snprintf(make_model, sizeof(make_model), "%s %s", ppd->manufacturer, ppd->product + 1);