Skip to content

Commit

Permalink
Fix some PPD parser issues discovered via fuzzing (Issue #5623, Issue #…
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelrsweet committed Aug 1, 2019
1 parent b4909ef commit d11af54
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 1 deletion.
3 changes: 2 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CHANGES - 2.2.12 - 2019-07-16
CHANGES - 2.2.12 - 2019-08-01
=============================


Expand Down Expand Up @@ -29,6 +29,7 @@ Changes in CUPS v2.2.12
- The scheduler now uses both the group's membership list as well as the
various OS-specific membership functions to determine whether a user belongs
to a named group (Issue #5613)
- Fixed some PPD parser issues (Issue #5623, Issue #5624)
- The scheduler would restart continuously when idle and printers were not
shared (rdar://52561199)
- Fixed a command ordering issue in the Zebra ZPL driver.
Expand Down
9 changes: 9 additions & 0 deletions cgi-bin/admin.c
Original file line number Diff line number Diff line change
Expand Up @@ -3410,6 +3410,9 @@ do_set_options(http_t *http, /* I - HTTP connection */

switch (cparam->type)
{
case PPD_CUSTOM_UNKNOWN :
break;

case PPD_CUSTOM_POINTS :
if (!_cups_strncasecmp(option->defchoice, "Custom.", 7))
{
Expand Down Expand Up @@ -4009,6 +4012,9 @@ get_option_value(

switch (cparam->type)
{
case PPD_CUSTOM_UNKNOWN :
break;

case PPD_CUSTOM_CURVE :
case PPD_CUSTOM_INVCURVE :
case PPD_CUSTOM_REAL :
Expand Down Expand Up @@ -4087,6 +4093,9 @@ get_option_value(

switch (cparam->type)
{
case PPD_CUSTOM_UNKNOWN :
break;

case PPD_CUSTOM_CURVE :
case PPD_CUSTOM_INVCURVE :
case PPD_CUSTOM_REAL :
Expand Down
12 changes: 12 additions & 0 deletions cups/ppd-emit.c
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,9 @@ ppdEmitString(ppd_file_t *ppd, /* I - PPD file record */
{
switch (cparam->type)
{
case PPD_CUSTOM_UNKNOWN :
break;

case PPD_CUSTOM_CURVE :
case PPD_CUSTOM_INVCURVE :
case PPD_CUSTOM_POINTS :
Expand Down Expand Up @@ -708,6 +711,9 @@ ppdEmitString(ppd_file_t *ppd, /* I - PPD file record */
{
switch (cparam->type)
{
case PPD_CUSTOM_UNKNOWN :
break;

case PPD_CUSTOM_CURVE :
case PPD_CUSTOM_INVCURVE :
case PPD_CUSTOM_POINTS :
Expand Down Expand Up @@ -803,6 +809,9 @@ ppdEmitString(ppd_file_t *ppd, /* I - PPD file record */
{
switch (cparam->type)
{
case PPD_CUSTOM_UNKNOWN :
break;

case PPD_CUSTOM_CURVE :
case PPD_CUSTOM_INVCURVE :
case PPD_CUSTOM_POINTS :
Expand Down Expand Up @@ -1005,6 +1014,9 @@ ppdEmitString(ppd_file_t *ppd, /* I - PPD file record */
{
switch (cparam->type)
{
case PPD_CUSTOM_UNKNOWN :
break;

case PPD_CUSTOM_CURVE :
case PPD_CUSTOM_INVCURVE :
case PPD_CUSTOM_POINTS :
Expand Down
6 changes: 6 additions & 0 deletions cups/ppd-mark.c
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,9 @@ ppd_mark_option(ppd_file_t *ppd, /* I - PPD file */

switch (cparam->type)
{
case PPD_CUSTOM_UNKNOWN :
break;

case PPD_CUSTOM_CURVE :
case PPD_CUSTOM_INVCURVE :
case PPD_CUSTOM_REAL :
Expand Down Expand Up @@ -932,6 +935,9 @@ ppd_mark_option(ppd_file_t *ppd, /* I - PPD file */

switch (cparam->type)
{
case PPD_CUSTOM_UNKNOWN :
break;

case PPD_CUSTOM_CURVE :
case PPD_CUSTOM_INVCURVE :
case PPD_CUSTOM_REAL :
Expand Down
29 changes: 29 additions & 0 deletions cups/ppd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1003,6 +1003,13 @@ _ppdOpen(
goto error;
}

if (cparam->type != PPD_CUSTOM_UNKNOWN)
{
pg->ppd_status = PPD_BAD_CUSTOM_PARAM;

goto error;
}

/*
* Get the parameter data...
*/
Expand Down Expand Up @@ -1876,6 +1883,13 @@ _ppdOpen(
}
else if (!strcmp(keyword, "PaperDimension"))
{
if (!_cups_strcasecmp(name, "custom") || !_cups_strncasecmp(name, "custom.", 7))
{
pg->ppd_status = PPD_ILLEGAL_OPTION_KEYWORD;

goto error;
}

if ((size = ppdPageSize(ppd, name)) == NULL)
size = ppd_add_size(ppd, name);

Expand All @@ -1898,6 +1912,13 @@ _ppdOpen(
}
else if (!strcmp(keyword, "ImageableArea"))
{
if (!_cups_strcasecmp(name, "custom") || !_cups_strncasecmp(name, "custom.", 7))
{
pg->ppd_status = PPD_ILLEGAL_OPTION_KEYWORD;

goto error;
}

if ((size = ppdPageSize(ppd, name)) == NULL)
size = ppd_add_size(ppd, name);

Expand Down Expand Up @@ -1927,6 +1948,13 @@ _ppdOpen(
{
DEBUG_printf(("2_ppdOpen: group=%p, subgroup=%p", group, subgroup));

if (!_cups_strcasecmp(name, "custom") || !_cups_strncasecmp(name, "custom.", 7))
{
pg->ppd_status = PPD_ILLEGAL_OPTION_KEYWORD;

goto error;
}

if (!strcmp(keyword, "PageSize"))
{
/*
Expand Down Expand Up @@ -2651,6 +2679,7 @@ ppd_get_cparam(ppd_coption_t *opt, /* I - PPD file */
if ((cparam = calloc(1, sizeof(ppd_cparam_t))) == NULL)
return (NULL);

cparam->type = PPD_CUSTOM_UNKNOWN;
strlcpy(cparam->name, param, sizeof(cparam->name));
strlcpy(cparam->text, text[0] ? text : param, sizeof(cparam->text));

Expand Down
1 change: 1 addition & 0 deletions cups/ppd.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ typedef struct ppd_profile_s /**** sRGB Color Profiles ****/
/**** New in CUPS 1.2/macOS 10.5 ****/
typedef enum ppd_cptype_e /**** Custom Parameter Type @since CUPS 1.2/macOS 10.5@ ****/
{
PPD_CUSTOM_UNKNOWN = -1, /* Unknown type (error) */
PPD_CUSTOM_CURVE, /* Curve value for f(x) = x^value */
PPD_CUSTOM_INT, /* Integer number value */
PPD_CUSTOM_INVCURVE, /* Curve value for f(x) = x^(1/value) */
Expand Down
4 changes: 4 additions & 0 deletions cups/testppd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1054,6 +1054,10 @@ main(int argc, /* I - Number of command-line arguments */
{
switch (cparam->type)
{
case PPD_CUSTOM_UNKNOWN :
printf(" %s(%s): PPD_CUSTOM_UNKNOWN (error)\n", cparam->name, cparam->text);
break;

case PPD_CUSTOM_CURVE :
printf(" %s(%s): PPD_CUSTOM_CURVE (%g to %g)\n",
cparam->name, cparam->text,
Expand Down

0 comments on commit d11af54

Please sign in to comment.