Skip to contentSkip to conversation

Fix possible sprintf overrun in snd_pcm_hw_open

PATCH In review David Henningsson 2 participants 4 messages Dec 8, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix possible sprintf overrun in snd_pcm_hw_open

I spotted this while reading code a few weeks ago, and I ran it through the Ubuntu security team just to be sure. They decided it was not needing any security embargo or similar, so here comes the patch.

Signature · 2 lines
David Henningsson, Canonical Ltd.
http://launchpad.net/~diwic
Quoted 1 line

From 3333d9bb8d8f9cc95f9dbf68d0a703a4e832a948 Mon Sep 17 00:00:00 2001

From: David Henningsson <[email protected]>
Date: Wed, 8 Dec 2010 11:06:59 +0100
Subject: [PATCH] Fix possible sprintf overrun in snd_pcm_hw_open

Possible buffer overrun if the number of "card" and "device" are absurdly high, especially on 64-bit platforms.

---
 src/pcm/pcm_hw.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
src/pcm/pcm_hw.c +1 -1
index 9d243d5..ce74ad4 100644
@@ -1270,7 +1270,7 @@ int snd_pcm_hw_open(snd_pcm_t **pcmp, const char *name,
 		SNDERR("invalid stream %d", stream);
 		return -EINVAL;
 	}
-	sprintf(filename, filefmt, card, device);
+	snprintf(filename, sizeof(filename), filefmt, card, device);
 
       __again:
       	if (attempt++ > 3) {
Signature · 1 line
1.7.1

_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

#1 lore raw
Quoted 2 lines · David Henningsson

Possible buffer overrun if the number of "card" and "device" are absurdly high, especially on 64-bit platforms.

The size of "int" is 32 bits even on 64-bit platforms.

As far as I can see, there is no bug.

Regards,
Clemens

#2 lore raw
Quoted 5 lines · Clemens Ladisch
Quoted 2 lines · David Henningsson

Possible buffer overrun if the number of "card" and "device" are absurdly high, especially on 64-bit platforms.

The size of "int" is 32 bits even on 64-bit platforms.

Seems you're right, then I learned something new today :-)

Although this might be compiler dependent, and some exotic platform might decide otherwise in the future?

Quoted 1 line

As far as I can see, there is no bug.

Even for 32-bit platforms, you would still overrun the buffer if you set card = device = −2147483647.

Signature · 6 lines
David Henningsson, Canonical Ltd.
http://launchpad.net/~diwic
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
#3 lore raw
Quoted 9 lines · David Henningsson
Quoted 5 lines · Clemens Ladisch
Quoted 2 lines · David Henningsson

Possible buffer overrun if the number of "card" and "device" are absurdly high, especially on 64-bit platforms.

The size of "int" is 32 bits even on 64-bit platforms.

Seems you're right, then I learned something new today :-)

Quoted 8 lines

Although this might be compiler dependent, and some exotic platform might decide otherwise in the future?

Quoted 1 line

As far as I can see, there is no bug.

Even for 32-bit platforms, you would still overrun the buffer if you set card = device = −2147483647.

...or maybe not, forgot that the %d characters are removed. Oh well, doesn't hurt to change it into snprintf anyway ;-)

Signature · 6 lines
David Henningsson, Canonical Ltd.
http://launchpad.net/~diwic
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel