Skip to content
Closed
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
2 changes: 1 addition & 1 deletion ppd/ppd-ipp.c
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ ppdLoadAttributes(
while (*ptr && isspace(*ptr)) ptr ++;
if (!isdigit(*ptr))
{
strcpy(buf, ptr);
snprintf(buf, sizeof(buf), "%s", ptr);
ptr = buf;
Copy link
Member

@tillkamppeter tillkamppeter Nov 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that, at least for the string in buf comming from a correct *cupsFilter(2): ... line, the crash cannot have been caused by the string pointed at by ptr being too long for buf, as ptr is pointing somewhere into buf. The problem is that, according to the man page, strcpy() is not suitable for copying overlapping strings/buffers, and so that could have caused the crash here.

Now, with the replacement by snprintf() the crash has gone away in this particular case, but here the man page also says that this function is not suitable for overlapping strings/buffers, so one should expect that a crash still can happen in other situations.

To be safe one could eaither do a for() loop moving the characters to the beginning of the buffer one-by-one or the memmove() function which according to its man page supports overlapping memory areas.

memmove(buf, ptr, strnlen(ptr, sizeof(buf) - 1) + 1);

could be used here and should work reliably, at least if buf contains a correctly \0-terminated string.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

strlen(ptr) + 1 (to also move the terminating nul character)

while (*ptr && !isspace(*ptr)) ptr ++;
if (*ptr)
Expand Down