Skip to content
Merged
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
12 changes: 8 additions & 4 deletions .github/workflows/cppcheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@ jobs:
# The PPD-compiler sources (ppdc*.{h,cxx}) plus encode.c, ppd-cache.c,
# raster-interpret.c and ppdc-import.cxx are inherited verbatim from CUPS
# (github.com/OpenPrinting/cups); their findings are suppressed here to
# keep that code identical to upstream instead of diverging it. The rest
# are cppcheck false positives (short-circuited NULL checks and a deflate
# output buffer) in libppd's own code.
# keep that code identical to upstream instead of diverging it. This
# includes dangerousTypeCast (new in cppcheck 2.19), which flags the
# C-style casts that all of the C++ code from CUPS (the PPD compiler,
# its tools and ppd-collection.cxx) uses. The rest are cppcheck false
# positives (short-circuited NULL checks and a deflate output buffer)
# in libppd's own code.
cppcheck \
--enable=warning,performance,portability \
--error-exitcode=1 \
Expand All @@ -38,6 +41,7 @@ jobs:
--suppress=unknownMacro \
--suppress=noCopyConstructor \
--suppress=noOperatorEq \
--suppress=dangerousTypeCast \
--suppress=uninitvar:ppd/encode.c \
--suppress=invalidScanfArgType_int:ppd/ppd-cache.c \
--suppress=shiftNegativeLHS:ppd/raster-interpret.c \
Expand All @@ -48,5 +52,5 @@ jobs:
--suppress=uninitvar:ppd/rastertops.c \
--suppress=nullPointerRedundantCheck:ppd/test_ppd_attr.c \
--suppress=nullPointerRedundantCheck:ppd/test_ppd_custom.c \
-DVERSION="$(grep -oP 'AC_INIT\(\[[^\]]*\],\s*\[\K[^\]]*' configure.ac)" \
-DVERSION="\"$(grep -oP 'AC_INIT\(\[[^\]]*\],\s*\[\K[^\]]*' configure.ac)\"" \
.
10 changes: 9 additions & 1 deletion ppd/ppd-filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ ppdFilterCUPSWrapper(
if (argc > 5)
num_options = cupsParseOptions(argv[5], NULL, 0, &options);

if ((filter_data.printer = getenv("PRINTER")) == NULL)
filter_data.printer = getenv("PRINTER");
if (filter_data.printer == NULL)
filter_data.printer = argv[0];
filter_data.job_id = argc > 1 ? atoi(argv[1]) : 0;
filter_data.job_user = argc > 2 ? argv[2] : NULL;
Expand Down Expand Up @@ -228,6 +229,13 @@ ppdFilterLoadPPDFile(cf_filter_data_t *data, // I/O - Job and printer data

filter_data_ext =
(ppd_filter_data_ext_t *)calloc(1, sizeof(ppd_filter_data_ext_t));
if (!filter_data_ext)
{
if (log) log(ld, CF_LOGLEVEL_ERROR,
"ppdFilterLoadPPDFile: Out of memory");
ppdClose(ppd);
return (-1);
}

filter_data_ext->ppdfile = strdup(ppdfile); // PPD file name
filter_data_ext->ppd = ppd; // PPD data
Expand Down
6 changes: 4 additions & 2 deletions ppd/ppd-mark.c
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,8 @@ ppdFindMarkedChoice(ppd_file_t *ppd, // I - PPD file

DEBUG_printf(("2ppdFindMarkedChoice(ppd=%p, option=\"%s\")", ppd, option));

if ((key.option = ppdFindOption(ppd, option)) == NULL)
key.option = ppdFindOption(ppd, option);
if (key.option == NULL)
{
DEBUG_puts("3ppdFindMarkedChoice: Option not found, returning NULL");
return (NULL);
Expand Down Expand Up @@ -484,7 +485,8 @@ ppdIsMarked(ppd_file_t *ppd, // I - PPD file data
if (!ppd)
return (0);

if ((key.option = ppdFindOption(ppd, option)) == NULL)
key.option = ppdFindOption(ppd, option);
if (key.option == NULL)
return (0);

if ((c = (ppd_choice_t *)cupsArrayFind(ppd->marked, &key)) == NULL)
Expand Down
5 changes: 5 additions & 0 deletions ppd/test_ppd_attr.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,11 @@ main(void)

testBegin("ppdOpen(embedded attribute test PPD)");
f = tmpfile();
if (!f)
{
testEndMessage(false, "tmpfile() failed");
return (1);
}
fputs(test_ppd_text, f);
rewind(f);
ppd = ppdOpen(f);
Expand Down
10 changes: 10 additions & 0 deletions ppd/test_ppd_cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,11 @@ main(void)

testBegin("ppdOpen(embedded cache test PPD)");
f = tmpfile();
if (!f)
{
testEndMessage(false, "tmpfile() failed");
return (1);
}
fputs(test_ppd_text, f);
rewind(f);
ppd = ppdOpen(f);
Expand Down Expand Up @@ -657,6 +662,11 @@ main(void)
"*DefaultAuditEmpty: None\n"
"*CloseUI: *AuditEmpty\n";
FILE *fp_foo = tmpfile();
if (!fp_foo)
{
testEndMessage(false, "tmpfile() failed");
return (1);
}
fputs(foomatic_empty_opt_ppd, fp_foo);
rewind(fp_foo);
ppd_file_t *ppd_foo = ppdOpen(fp_foo);
Expand Down
23 changes: 19 additions & 4 deletions ppd/test_ppd_conflicts.c
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,11 @@ static const char test_ppd_installable_text[] =
"*UIConstraints: \"*Duplex DuplexNoTumble *OptionDuplexer False\"\n";


// Non-NULL PPD for the argument-check tests: the functions must return
// before they look at it.
static ppd_file_t dummy_ppd;


//
// 'main()' - Run all ppd-conflicts.c unit tests.
//
Expand Down Expand Up @@ -310,20 +315,20 @@ main(void)
// T03 — ppdGetConflicts(ppd, NULL option, ...) — `!option` clause.
testBegin("ppdGetConflicts(ppd, NULL option, ...) returns 0");
options = NULL;
testEnd(ppdGetConflicts((ppd_file_t *)1, NULL, "x", &options) == 0);
testEnd(ppdGetConflicts(&dummy_ppd, NULL, "x", &options) == 0);

// T04 — ppdGetConflicts(ppd, opt, NULL choice, ...) — `!choice` clause.
testBegin("ppdGetConflicts(ppd, opt, NULL choice, ...) returns 0");
options = NULL;
testEnd(ppdGetConflicts((ppd_file_t *)1, "Duplex", NULL, &options) == 0);
testEnd(ppdGetConflicts(&dummy_ppd, "Duplex", NULL, &options) == 0);

// T05 — ppdGetConflicts(ppd, opt, choice, NULL **options) — `!options`
// clause. Note: because *options would be dereferenced earlier
// to null it, the function tests `if (options)` BEFORE the
// null-check (line 84) — so passing NULL for the slot is safe and
// still returns 0.
testBegin("ppdGetConflicts(ppd, opt, choice, NULL slot) returns 0");
testEnd(ppdGetConflicts((ppd_file_t *)1, "Duplex", "DuplexNoTumble", NULL)
testEnd(ppdGetConflicts(&dummy_ppd, "Duplex", "DuplexNoTumble", NULL)
== 0);

// T06 — ppdInstallableConflict(NULL, ...) — `!ppd` (line 656-657).
Expand All @@ -332,7 +337,7 @@ main(void)

// T07 — ppdInstallableConflict(ppd, NULL option, ...) — `!option`.
testBegin("ppdInstallableConflict(ppd, NULL, ...) returns 0");
testEnd(ppdInstallableConflict((ppd_file_t *)1, NULL, "x") == 0);
testEnd(ppdInstallableConflict(&dummy_ppd, NULL, "x") == 0);

// T08 — ppdResolveConflicts(NULL, ...) — `!ppd` (line 202-203). The
// same line also enforces the symmetry rule `(option == NULL) !=
Expand Down Expand Up @@ -360,6 +365,11 @@ main(void)

testBegin("ppdOpen(embedded conflicts test PPD #1)");
f = tmpfile();
if (!f)
{
testEndMessage(false, "tmpfile() failed");
return (1);
}
fputs(test_ppd_text, f);
rewind(f);
ppd = ppdOpen(f);
Expand Down Expand Up @@ -587,6 +597,11 @@ main(void)

testBegin("ppdOpen(embedded conflicts test PPD #2 — installable group)");
f = tmpfile();
if (!f)
{
testEndMessage(false, "tmpfile() failed");
return (1);
}
fputs(test_ppd_installable_text, f);
rewind(f);
ppd2 = ppdOpen(f);
Expand Down
10 changes: 10 additions & 0 deletions ppd/test_ppd_custom.c
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,11 @@ main(void)

testBegin("ppdOpen(embedded custom test PPD)");
f = tmpfile();
if (!f)
{
testEndMessage(false, "tmpfile() failed");
return (1);
}
fputs(test_ppd_text, f);
rewind(f);
ppd = ppdOpen(f);
Expand Down Expand Up @@ -531,6 +536,11 @@ main(void)
testBegin("ppdOpen(%s) %s", param_cases[i].title,
param_cases[i].opens ? "succeeds" : "fails");
f = tmpfile();
if (!f)
{
testEndMessage(false, "tmpfile() failed");
return (1);
}
fputs(custom_ppd_head, f);
fputs(param_cases[i].params, f);
fputs(custom_page_size, f);
Expand Down
12 changes: 10 additions & 2 deletions ppd/test_ppd_emit.c
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,9 @@ open_embedded_ppd(const char *text)
FILE *f = tmpfile();
ppd_file_t *ppd;

if (!f)
return (NULL);

fputs(text, f);
rewind(f);
ppd = ppdOpen(f);
Expand All @@ -387,6 +390,11 @@ open_embedded_ppd(const char *text)
}


// Non-NULL PPD for the argument-check tests: the functions must return
// before they look at it.
static ppd_file_t dummy_ppd;


int // O - Exit status (0 = all pass)
main(void)
{
Expand Down Expand Up @@ -418,7 +426,7 @@ main(void)

// T02 — !fp half of the same guard.
testBegin("ppdEmit(ppd, NULL fp, ...) returns -1");
testEnd(ppdEmit((ppd_file_t *)1, NULL, PPD_ORDER_JCL) == -1);
testEnd(ppdEmit(&dummy_ppd, NULL, PPD_ORDER_JCL) == -1);

// T03 — ppdEmitString: `if (!ppd) return (NULL);` (line 692).
testBegin("ppdEmitString(NULL, ...) returns NULL");
Expand All @@ -430,7 +438,7 @@ main(void)

// T05 — fd < 0 half of the same guard.
testBegin("ppdEmitFd(ppd, fd=-1, ...) returns -1");
testEnd(ppdEmitFd((ppd_file_t *)1, -1, PPD_ORDER_JCL) == -1);
testEnd(ppdEmitFd(&dummy_ppd, -1, PPD_ORDER_JCL) == -1);

// T06 — ppdCollect(NULL, …, &choices) returns 0 AND nulls the slot.
testBegin("ppdCollect(NULL ppd, …, &choices) returns 0, nulls slot");
Expand Down
10 changes: 10 additions & 0 deletions ppd/test_ppd_ipp.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,11 @@ load_test_ppd(void)
int line; // Error line number

f = tmpfile();
if (!f)
{
testError("tmpfile() failed");
return (NULL);
}
fputs(test_ppd_text, f);
rewind(f);
ppd = ppdOpen(f);
Expand Down Expand Up @@ -1007,6 +1012,11 @@ main(void)
testBegin("ppdLoadAttributes(21-item cupsPwgRaster attribute) caps at 20 items");
{
FILE *f21 = tmpfile();
if (!f21)
{
testEndMessage(false, "tmpfile() failed");
return (1);
}
fputs(test_ppd_text, f21);
fputs("*cupsFilter: \"image/pwg-raster 0 rastertopwg\"\n"
"*cupsPwgRasterAuditSupported: \"v1,v2,v3,v4,v5,v6,v7,v8,v9,v10,"
Expand Down
18 changes: 14 additions & 4 deletions ppd/test_ppd_load_profile.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,11 @@ static const char test_ppd_text[] =
"*cupsInkChannels EightChan.Plain.600dpi: \"8\"\n";


// Non-NULL PPD for the argument-check tests: the functions must return
// before they look at it.
static ppd_file_t dummy_ppd;


//
// 'main()' - Run all ppd-load-profile.c unit tests.
//
Expand Down Expand Up @@ -257,26 +262,26 @@ main(void)
// pointer; the !name short-circuit fires before any dereference.
// Cast a dummy pointer (never dereferenced) to satisfy the type.
testBegin("ppdFindColorAttr(ppd, NULL name, ...) returns NULL");
testEnd(ppdFindColorAttr((ppd_file_t *)1, NULL, "RGB", "Plain", "600dpi",
testEnd(ppdFindColorAttr(&dummy_ppd, NULL, "RGB", "Plain", "600dpi",
spec, sizeof(spec), NULL, NULL) == NULL);

// T03 — NULL colormodel trips the !colormodel guard.
testBegin("ppdFindColorAttr(.., NULL colormodel, ..) returns NULL");
testEnd(ppdFindColorAttr((ppd_file_t *)1, "cupsTestL1", NULL, "Plain",
testEnd(ppdFindColorAttr(&dummy_ppd, "cupsTestL1", NULL, "Plain",
"600dpi", spec, sizeof(spec), NULL, NULL)
== NULL);

// T04 — NULL spec output buffer trips the !spec guard.
testBegin("ppdFindColorAttr(.., NULL spec out-buffer, ..) returns NULL");
testEnd(ppdFindColorAttr((ppd_file_t *)1, "cupsTestL1", "RGB", "Plain",
testEnd(ppdFindColorAttr(&dummy_ppd, "cupsTestL1", "RGB", "Plain",
"600dpi", NULL, sizeof(spec), NULL, NULL)
== NULL);

// T05 — specsize < IPP_MAX_NAME trips the size guard. A 7-character
// buffer is far smaller than IPP_MAX_NAME (256 on every supported
// cups build), so the guard always fires.
testBegin("ppdFindColorAttr(.., specsize < IPP_MAX_NAME) returns NULL");
testEnd(ppdFindColorAttr((ppd_file_t *)1, "cupsTestL1", "RGB", "Plain",
testEnd(ppdFindColorAttr(&dummy_ppd, "cupsTestL1", "RGB", "Plain",
"600dpi", smallbuf, (int)sizeof(smallbuf),
NULL, NULL) == NULL);

Expand All @@ -292,6 +297,11 @@ main(void)

testBegin("ppdOpen(embedded profile test PPD)");
f = tmpfile();
if (!f)
{
testEndMessage(false, "tmpfile() failed");
return (1);
}
fputs(test_ppd_text, f);
rewind(f);
ppd = ppdOpen(f);
Expand Down
5 changes: 5 additions & 0 deletions ppd/test_ppd_localize.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ main(void)
testBegin("ppdOpen(embedded test PPD)");

f = tmpfile();
if (!f)
{
testEndMessage(false, "tmpfile() failed");
return (1);
}
fputs(test_ppd_text, f);
rewind(f);
ppd = ppdOpen(f);
Expand Down
5 changes: 5 additions & 0 deletions ppd/test_ppd_mark.c
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,11 @@ main(void)

testBegin("ppdOpen(embedded mark test PPD)");
f = tmpfile();
if (!f)
{
testEndMessage(false, "tmpfile() failed");
return (1);
}
fputs(test_ppd_text, f);
rewind(f);
ppd = ppdOpen(f);
Expand Down
10 changes: 10 additions & 0 deletions ppd/test_ppd_page.c
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,11 @@ main(void)

testBegin("ppdOpen(embedded variable-size test PPD)");
f = tmpfile();
if (!f)
{
testEndMessage(false, "tmpfile() failed");
return (1);
}
fputs(test_ppd_text, f);
rewind(f);
ppd = ppdOpen(f);
Expand Down Expand Up @@ -509,6 +514,11 @@ main(void)

testBegin("ppdOpen(embedded no-variable-size test PPD)");
f = tmpfile();
if (!f)
{
testEndMessage(false, "tmpfile() failed");
return (1);
}
fputs(test_ppd_novar, f);
rewind(f);
ppd2 = ppdOpen(f);
Expand Down
Loading
Loading