Skip to content

Commit

Permalink
Fix UB in cups_raster_read debug message
Browse files Browse the repository at this point in the history
The first time `cups_raster_read` is called, both `r->bufptr` and
`r->buffer` are NULL.  The calculation here then ends up looking like
adding a size_t to a NULL pointer, which triggers the ubsan detector.
Since we just want an offset, cast the pointer difference to ssize_t
like the code already does a few lines below.
  • Loading branch information
yetamrra committed Feb 1, 2023
1 parent d616562 commit fd792e3
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion cups/raster-stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -1409,7 +1409,7 @@ cups_raster_read(cups_raster_t *r, /* I - Raster stream */
total; /* Total bytes read */


DEBUG_printf(("4cups_raster_read(r=%p, buf=%p, bytes=" CUPS_LLFMT "), offset=" CUPS_LLFMT, (void *)r, (void *)buf, CUPS_LLCAST bytes, CUPS_LLCAST (r->iostart + r->bufptr - r->buffer)));
DEBUG_printf(("4cups_raster_read(r=%p, buf=%p, bytes=" CUPS_LLFMT "), offset=" CUPS_LLFMT, (void *)r, (void *)buf, CUPS_LLCAST bytes, CUPS_LLCAST (r->iostart + (ssize_t)(r->bufptr - r->buffer))));

if (!r->compressed)
return (cups_raster_io(r, buf, bytes));
Expand Down

0 comments on commit fd792e3

Please sign in to comment.