CVE-2026-58966 AI-generated analysis
platform/external/hplip, prnt/hpps/hppsfilter.c (HP PostScript CUPS filter, hppsfilter)
Replaces unbounded sprintf calls with snprintf and rewrites strncpy calls in prnt/hpps/hppsfilter.c (external/hplip) so the copy limit is the destination size minus one with explicit NUL termination, preventing fixed-size buffers from being overrun by job arguments, CUPS options and PPD values.
Root cause
hppsfilter.c builds PJL/PostScript command strings in fixed-size buffers (buffer, sec_pin_command[MAX_BUFFER], sfile_name[FILE_NAME_SIZE], final, input_slot, newline, finalstr). It used sprintf with variable strings (argument[1], argument[2], argument[3] from argv, cupsGetOption values, GetOptionValue PPD values, sec_pin, finalstr, gethostname/getdomainname results) with no size limit, and used strncpy(dst, val, strlen(val)), which bounds the copy by the source length rather than the destination size, so long values overflow and the copy is not NUL terminated. In GetPPDValues, strncpy(finalstr,&newstring[1],i-1) copied up to the newline position with no check of i against sizeof(finalstr) and no lower bound check on i. In main, the HPBookletPageSize copy used a hard-coded 64 rather than the buffer size.
How the fix works
- Single commit e14870053bce in external/hplip; it adds patches/1100_hplip-3.22.6-fix-strncpy-and-use-snprintf.patch (the file name suggests a patch series on top of hplip 3.22.6) and applies the identical change to prnt/hpps/hppsfilter.c.
- hppsfilter.c:open_dbg_outfile: sprintf into sfile_name replaced by snprintf(sfile_name, sizeof(sfile_name), ...).
- hppsfilter.c:GetPPDValues: the strncpy into finalstr is now guarded by if (i > 1); copy_len = i - 1 is clamped to sizeof(finalstr) - 1, strncpy uses copy_len, finalstr[copy_len] is set to '\0', and ppd_values[12] = 1 is only set inside the guard.
- hppsfilter.c:WriteHeader: the three sprintf calls formatting argument[1], argument[2], argument[3] into buffer become snprintf(buffer, sizeof(buffer), ...).
- hppsfilter.c:WriteSecurePrinting: strncpy(input_slot, val, strlen(val)) becomes strncpy(input_slot, val, sizeof(input_slot) - 1) plus input_slot[sizeof(input_slot) - 1] = '\0'; the sprintf of sec_pin into sec_pin_command becomes snprintf with sizeof(sec_pin_command).
- hppsfilter.c:WriteJobAccounting: all JobAcct1..JobAcct8 sprintf calls (argument[2], hostname, domain name, outstr, input_slot, constants) become snprintf(buffer, sizeof(buffer), ...); the job-uuid strncpy into input_slot is bounded by sizeof(input_slot) - 1 and NUL terminated.
- hppsfilter.c:WriteBornOnDate: the per-character hex loop becomes snprintf(&final[len], sizeof(final) - len, "%x", outstr[count]) and the final PJL DMINFO line uses snprintf(buffer, sizeof(buffer), ...).
- hppsfilter.c:WriteECONOMODE2, WriteHPPJLPRINTQUALITY, WriteHPPJLOUTPUTMODE, WriteHPPJLDRYTIME, WriteHPPJLSATURATION, WriteHPPJLINKBLEED, WriteHPPJLCOLORASGRAY, WriteHPPJLTRUEBLACK: each strncpy(input_slot, val, strlen(val)) becomes strncpy(input_slot, val, sizeof(input_slot) - 1) followed by explicit NUL termination.
- hppsfilter.c:main: strncpy(newline, subString, 64) becomes strncpy(newline, subString, sizeof(newline) - 1) with NUL termination; the JobAcct17 sprintf of finalstr and the PrivacyLevelPin sprintf of sec_pin into buffer become snprintf with sizeof(buffer).
Completeness
- Covers every sprintf and strncpy site in prnt/hpps/hppsfilter.c shown in the diff (open_dbg_outfile, GetPPDValues, WriteHeader, WriteSecurePrinting, WriteJobAccounting, WriteBornOnDate, the eight WriteHPPJL*/WriteECONOMODE2 helpers, and main).
- Only hppsfilter.c is changed; no other hplip source file is touched by this commit, so string handling elsewhere in the project is out of scope of this fix.
- In WriteBornOnDate the loop size argument is sizeof(final) - len; it relies on len never exceeding sizeof(final) (the loop is driven by strlen(outstr)). The material does not show the sizes of final or outstr, so this cannot be judged from the diff alone.
- snprintf truncates; the code does not check the return value, so over-long input now produces truncated PJL commands rather than an error.
- The pre-existing if(input_slot) checks are left as is; if input_slot is an array (as the fix's use of sizeof suggests) they are always true.
Behavior changes
- Over-long job arguments, CUPS option values, PPD values, hostname/domain strings and secure-print PINs are now truncated to the destination buffer size instead of overflowing; copied option values are always NUL terminated.
- GetPPDValues now only copies into finalstr and sets ppd_values[12] = 1 when i > 1; previously ppd_values[12] was set unconditionally on that path, so with i <= 1 the JobAcct17 output in main is no longer produced.
- The HPBookletPageSize copy limit in main changed from a hard-coded 64 to sizeof(newline) - 1 with explicit termination.
Per major
- Android 14: not affected per the bulletin; external/hplip is not present in android-security-14.0.0_r31 (code absent).
- Android 15: not affected per the bulletin; external/hplip is not present in android-security-15.0.0_r19 (code absent).
- Android 16: not listed by the bulletin (not affected per the bulletin); external/hplip is not present in android-security-16.0.0_r10 (code absent).
- Android 17: same fix: commit e14870053bce (cherry-pick of 513ef72f4e38, Change-Id I3f12e32677d841392e3798784c311dc8c3caff77) in android-security-17.0.0_r3; 8/8 lines of the patched region present.
Unknowns
- The declared sizes of buffer, input_slot, newline, finalstr, final and the values of MAX_BUFFER/FILE_NAME_SIZE are not shown, so exact overflow margins cannot be stated.
- The type of i in GetPPDValues is not shown.
- Which specific site was reported in bug 511632970 is not shown; the commit fixes all sites generically.
- How and with what privileges hppsfilter is executed on Android (the EoP vector) is not shown in the material.
- The bulletin's affected-version list includes 16-qpr2 and 17-qpr2-next, but no fix commit for those branches is in the material and the per-major facts treat Android 16 as not listed.