fix: prevent infinite loop in cfIEEE1284NormalizeMakeModel on empty MFG/MDL (fixes #214) - #223
Open
KHARSHAVARDHAN-eng wants to merge 1 commit into
Conversation
zdohnal
reviewed
Aug 31, 2026
zdohnal
left a comment
Member
There was a problem hiding this comment.
I would prefer returning if there is no manufacturer or model values - while the current MR might be shorter solution at the moment, but IMO it is better to end early if we don't have proper required input rather than trying to recover.
I have my proposal at zdohnal@60d2b49 , but without test. We can combine them, if preferred.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes an infinite loop in
cfIEEE1284NormalizeMakeModel()when given IEEE-1284 device IDs containing emptyMFGandMDLfields (such asMFG:;MDL:;andMFG:;MDL:;CMD:PostScript;).Root Cause
MFG:;was encountered,makeptrandbufptrremained atbuffer. The unpatched code checkedwhile (isspace(*(bufptr - 1))) bufptr--;, reading before thebufferarray start.if (bufptr < buffer + bufsize - 1)evaluated to true for emptyMFG, inserting a space' 'and advancingmakeptrtobuffer + 1.modelptr: WhenMDL:;was processed,bufptrwas decremented back tobufferand NUL-terminated (""). However,if (!nomakemodel && makeptr != bufptr)assignedmodelptr = makeptr(buffer + 1), causingmodelptrto point past the string terminator.compare_len = modelptr - buffer(1) and repeatedly matchedstrncasecmp("", garbage, 1) == 0, looping infinitely inmove_right_part().Fix Description
bufptr > bufferbounds checks before dereferencing*(bufptr - 1)in trailing whitespace removal loops (lines 807 & 825).bufptr > buffercondition at line 808 to prevent inserting a space separator when no manufacturer text was written.modelptrPointer Safety: Added a defensive bounds check at line 1164 (if (!modelptr || modelptr > buffer + strlen(buffer)) modelptr = buffer + strlen(buffer);) to guaranteemodelptrnever points past the string NUL-terminator.cupsfilters/test-ieee1284-normalize.cverifying that emptyMFGandMDLinputs return safely without hanging or crashing, while preserving validMDL:;andMFG:HP;MDL:DeskJet;inputs. Registered the test inMakefile.amundercheck_PROGRAMSandTESTS.Fixes #214.