Skip to content

Commit 0731f1d

Browse files
committed
raster-interpret.c: Verify base for strtol()
Input for `atoi()` can be bad number for argument `base` in `strtol()`, causing returning an incorrect pointer address and later segfault. Break out from function if the base is incorrect. Fixes OpenPrinting#1188
1 parent 745f21c commit 0731f1d

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

cups/raster-interpret.c

+12-2
Original file line numberDiff line numberDiff line change
@@ -1041,7 +1041,8 @@ scan_ps(_cups_ps_stack_t *st, /* I - Stack */
10411041
*cur, /* Current position */
10421042
*valptr, /* Pointer into value string */
10431043
*valend; /* End of value string */
1044-
int parens; /* Parenthesis nesting level */
1044+
int parens, /* Parenthesis nesting level */
1045+
base; /* Numeric base for strtol() */
10451046

10461047

10471048
if (!*ptr)
@@ -1302,7 +1303,16 @@ scan_ps(_cups_ps_stack_t *st, /* I - Stack */
13021303
* Integer with radix...
13031304
*/
13041305

1305-
obj.value.number = strtol(cur + 1, &cur, atoi(start));
1306+
base = atoi(start);
1307+
1308+
/*
1309+
* strtol() takes 0 or 2 to 32 as base...
1310+
*/
1311+
1312+
if (base != 0 && (base < 2 || base > 32))
1313+
return (NULL);
1314+
1315+
obj.value.number = strtol(cur + 1, &cur, base);
13061316
break;
13071317
}
13081318
else if (strchr(".Ee()<>[]{}/%", *cur) || isspace(*cur & 255))

0 commit comments

Comments
 (0)