Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ check_PROGRAMS = \
test-analyze \
test-pdf \
test-ps \
test-ieee1284-normalize \
testfilters

TESTS = \
Expand All @@ -115,6 +116,7 @@ TESTS = \
test-analyze \
test-pdf \
test-ps \
test-ieee1284-normalize \
cupsfilters/testfilters.sh \
cupsfilters/test-pclm-overflow.sh \
cupsfilters/test-pdftoraster-copy-height.sh
Expand Down Expand Up @@ -289,6 +291,15 @@ test1284_CFLAGS = \
-I$(srcdir)/cupsfilters/ \
$(CUPS_CFLAGS)

test_ieee1284_normalize_SOURCES = \
cupsfilters/test-ieee1284-normalize.c
test_ieee1284_normalize_CFLAGS = \
-I$(srcdir)/cupsfilters/ \
$(CUPS_CFLAGS)
test_ieee1284_normalize_LDADD = \
libcupsfilters.la \
$(CUPS_LIBS)

testpdf1_SOURCES = \
cupsfilters/testpdf1.c \
cupsfilters/fontembed-private.h
Expand Down
9 changes: 6 additions & 3 deletions cupsfilters/ieee1284.c
Original file line number Diff line number Diff line change
Expand Up @@ -804,8 +804,8 @@ cfIEEE1284NormalizeMakeModel(
makeptr ++;
bufptr ++;
}
while (isspace(*(bufptr - 1))) bufptr --;
if (bufptr < buffer + bufsize - 1)
while (bufptr > buffer && isspace(*(bufptr - 1))) bufptr --;
if (bufptr > buffer && bufptr < buffer + bufsize - 1)
{
*bufptr = ' ';
makeptr ++;
Expand All @@ -822,7 +822,7 @@ cfIEEE1284NormalizeMakeModel(
modelptr ++;
bufptr ++;
}
while (isspace(*(bufptr - 1))) bufptr --;
while (bufptr > buffer && isspace(*(bufptr - 1))) bufptr --;
*bufptr = '\0';
if (!nomakemodel && makeptr != bufptr)
modelptr = makeptr;
Expand Down Expand Up @@ -1161,6 +1161,9 @@ cfIEEE1284NormalizeMakeModel(
// Remove repeated manufacturer names...
//

if (!modelptr || modelptr > buffer + strlen(buffer))
modelptr = buffer + strlen(buffer);

compare_len = modelptr - buffer;
while (compare_len > 0 && strncasecmp(buffer, modelptr, compare_len) == 0)
move_right_part(buffer, bufsize, modelptr, buffer - modelptr);
Expand Down
73 changes: 73 additions & 0 deletions cupsfilters/test-ieee1284-normalize.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
//
// IEEE-1284 normalization regression test for libcupsfilters (Issue #214).
//
// Copyright © 2026 by OpenPrinting.
//
// Licensed under Apache License v2.0. See the file "LICENSE" for more
// information.
//

#include <config.h>
#include <cupsfilters/ieee1284.h>
#include <stdio.h>
#include <string.h>

int
main(void)
{
char buffer[1024]; // Make/model buffer
char *model = NULL; // Pointer to model name
char *res; // Result pointer

//
// Issue #214 regression test: empty MFG and MDL fields in IEEE-1284 device ID
//

res = cfIEEE1284NormalizeMakeModel("MFG:;MDL:;", NULL,
CF_IEEE1284_NORMALIZE_HUMAN, NULL,
buffer, sizeof(buffer), &model, NULL,
NULL);
if (res != NULL)
{
printf("FAIL: MFG:;MDL:; expected NULL, got \"%s\"\n", res);
return (1);
}

res = cfIEEE1284NormalizeMakeModel("MFG:;MDL:;CMD:PostScript;", NULL,
CF_IEEE1284_NORMALIZE_HUMAN, NULL,
buffer, sizeof(buffer), &model, NULL,
NULL);
if (res != NULL)
{
printf("FAIL: MFG:;MDL:;CMD:PostScript; expected NULL, got \"%s\"\n", res);
return (1);
}

//
// Verify valid inputs behavior preservation
//

res = cfIEEE1284NormalizeMakeModel("MDL:;", NULL,
CF_IEEE1284_NORMALIZE_HUMAN, NULL,
buffer, sizeof(buffer), &model, NULL,
NULL);
if (!res || strcmp(res, "MDL:;"))
{
printf("FAIL: MDL:; expected \"MDL:;\", got \"%s\"\n", res ? res : "NULL");
return (1);
}

res = cfIEEE1284NormalizeMakeModel("MFG:HP;MDL:DeskJet;", NULL,
CF_IEEE1284_NORMALIZE_HUMAN, NULL,
buffer, sizeof(buffer), &model, NULL,
NULL);
if (!res || strcmp(res, "HP DeskJet"))
{
printf("FAIL: MFG:HP;MDL:DeskJet; expected \"HP DeskJet\", got \"%s\"\n",
res ? res : "NULL");
return (1);
}

puts("PASS: cfIEEE1284NormalizeMakeModel issue #214 tests passed.");
return (0);
}