CVE-2009-4270: Buffer Overflow

Published Nov 24, 2009
·
Updated

Created attachment 373324 [details] ghostscript backtrace

Description of problem: When cups prints a PDF, it passes it at some point through pstoraster which calls gs. I noticed a PDF I was working on caused printing to fail, and it appears that some of the debugging output (which pstoraster turns on) from the gs cups driver can trigger a buffer overflow in the gs debug handling (which uses vsprintf - bad bad bad).

I think there are two issues here. One is that somehow gs ended up with MediaType argument without null termination (at least that's how it appears). The other is that ghostscript's print handling code uses (v)sprintf when it should be using (v)snprintf. In fact, ghostscript uses (v)sprintf with an "%s" format modifier over 50 times in the source code, several instances of which are probably unsafe (such as here).

Consider the following code from base/gsmisc.c: int errprintf(const gsmemoryt mem, const char fmt, ...) { ... char buf[PRINTFBUFLENGTH]; ... count = vsprintf(buf, fmt, args); errwrite(mem, buf, count); if (count >= PRINTFBUFLENGTH) { count = sprintf(buf, "PANIC: printf exceeded %d bytes. Stack has been corrupted.\n", PRINTFBUFLENGTH); errwrite(mem, buf, count); } ...

Just marvellous -- ghostscript expects vsprintf to return sanely if it overflows (which it doesn't), and then expects to print a nice panic message. It would be a 5 line patch to fix this so that it uses vsnprintf, and if count+1 exceeds the buffer length then it can print a warning that the message was truncated instead. Same goes for outprintf.

I will attach the stack trace from gdb, the cups error log and the PDF which caused the problem.

I wasn't sure if this was security-sensitive or not, but I ticked the box just to be on the safe side. With all the sanity checking that gcc adds to (v)sprintf these days, it's probably very hard to exploit.

Version-Release number of selected component (if applicable): ghostscript-8.70-1.fc12.i686

How reproducible: No idea - works every time on this PDF though.

Steps to Reproduce: 1. Open PDF in evince 2. Print PDF to any printer 3. Wait for message saying "printing failed" or somesuch.

Additional info: To attach gdb, I put a 'sleep 20' command in the pstoraster shell script (/usr/lib/cups/filter/pstoraster) just before it executed gs, then I "printed" the PDF, found the sleeping bash process and attached gdb to it.

Other sources

Stack-based buffer overflow in the errprintf function in base/gsmisc.c in ghostscript 8.64 through 8.70 allows remote attackers to cause a denial of service (crash) and possibly execute arbitrary code via a crafted PDF file, as originally reported for debug logging code in gdevcups.c in the CUPS output driver.

Red Hat

Affected Software

3 affected componentsFixes available
redhat/8.70<2.
2.
Ghostscript Ghostscript=8.64
Ghostscript Ghostscript=8.70

Event History

Dec 21, 2009
CVE Published
via MITRE·04:00 PM
Data Sourced
via MITRE·04:00 PM
Description
Jan 12, 2024
Data Sourced
via Red Hat·12:25 PM
RemedyDescriptionSeverity

Frequently Asked Questions

1

What is the severity of CVE-2009-4270?

CVE-2009-4270 is considered a critical vulnerability due to its potential to cause a denial of service and allow remote code execution.

2

How do I fix CVE-2009-4270?

To fix CVE-2009-4270, update Ghostscript to version 8.71 or later, which addresses the buffer overflow issue.

3

What are the affected versions in CVE-2009-4270?

CVE-2009-4270 affects Ghostscript versions 8.64 through 8.70.

4

Can CVE-2009-4270 be exploited remotely?

Yes, CVE-2009-4270 can be exploited remotely through specially crafted PDF files.

5

What types of attacks can CVE-2009-4270 facilitate?

CVE-2009-4270 can facilitate denial of service attacks and possibly the execution of arbitrary code.

Contact

SecAlerts Pty Ltd.
132 Wickham Terrace
Fortitude Valley,
QLD 4006, Australia
info@secalerts.co
By using SecAlerts services, you agree to our services end-user license agreement. This website is safeguarded by reCAPTCHA and governed by the Google Privacy Policy and Terms of Service. All names, logos, and brands of products are owned by their respective owners, and any usage of these names, logos, and brands for identification purposes only does not imply endorsement. If you possess any content that requires removal, please get in touch with us.
© 2026 SecAlerts Pty Ltd.
ABN: 70 645 966 203, ACN: 645 966 203