Linux bluetooth development
 help / color / mirror / Atom feed
* [PATCH] Fix left overs handling in bluetooth_a2dp_write() of audio/pcm_bluetooth.c
@ 2010-08-25  8:49 Colin Didier
  2010-08-25 11:26 ` Johan Hedberg
  0 siblings, 1 reply; 4+ messages in thread
From: Colin Didier @ 2010-08-25  8:49 UTC (permalink / raw)
  To: linux-bluetooth

Hello,

If for some reason there is not enough data provided to the function
bluetooth_a2dp_write() and there are left overs to handle, the ALSA
module will segfault.

The test at the line 1053 of audio/pcm_bluetooth.c is wrong because it
compares unsigned integers and will lead to an unsigned integer overflow
if bytes_left is inferior to a2dp->codesize - data->count.

Here is a patch to fix this issue.

Cheers,
  Colin DIDIER


--- a/audio/pcm_bluetooth.c	2010-08-25 09:35:28.000000000 +0200
+++ b/audio/pcm_bluetooth.c	2010-08-25 09:37:47.000000000 +0200
@@ -1050,8 +1050,10 @@
 	}
 
 	/* Check if we have any left over data from the last write */
-	if (data->count > 0 && (bytes_left - data->count) >= a2dp->codesize) {
-		int additional_bytes_needed = a2dp->codesize - data->count;
+        if (data->count > 0) {
+                int additional_bytes_needed = a2dp->codesize - data->count;
+                if (additional_bytes_needed > bytes_left)
+                        goto out;
 
 		memcpy(data->buffer + data->count, buff,
 						additional_bytes_needed);
@@ -1122,6 +1124,7 @@
 		}
 	}
 
+out:
 	/* Copy the extra to our temp buffer for the next write */
 	if (bytes_left > 0) {
 		memcpy(data->buffer + data->count, buff, bytes_left);

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Fix left overs handling in bluetooth_a2dp_write() of audio/pcm_bluetooth.c
  2010-08-25  8:49 [PATCH] Fix left overs handling in bluetooth_a2dp_write() of audio/pcm_bluetooth.c Colin Didier
@ 2010-08-25 11:26 ` Johan Hedberg
  2010-08-25 13:06   ` [PATCH] Fix leftovers handling Colin Didier
  0 siblings, 1 reply; 4+ messages in thread
From: Johan Hedberg @ 2010-08-25 11:26 UTC (permalink / raw)
  To: Colin Didier; +Cc: linux-bluetooth

Hi Colin,

On Wed, Aug 25, 2010, Colin Didier wrote:
> If for some reason there is not enough data provided to the function
> bluetooth_a2dp_write() and there are left overs to handle, the ALSA
> module will segfault.
> 
> The test at the line 1053 of audio/pcm_bluetooth.c is wrong because it
> compares unsigned integers and will lead to an unsigned integer overflow
> if bytes_left is inferior to a2dp->codesize - data->count.
> 
> Here is a patch to fix this issue.

Thanks for the patch, however it doesn't compile cleanly:

audio/pcm_bluetooth.c: In function ‘bluetooth_a2dp_write’:
audio/pcm_bluetooth.c:1055: error: comparison between signed and unsigned integer expressions
make[1]: *** [audio/audio_libasound_module_pcm_bluetooth_la-pcm_bluetooth.lo] Error 1
make: *** [all] Error 2

Always make sure that patches compile cleanly with
./bootstrap-configure. Also, could you please use git format-patch to
create the patches and make sure they have properly formated commit
messages (fits within an 80-column terminal with git log, not formated
like an email, etc). Thanks.

Johan

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH] Fix leftovers handling
  2010-08-25 11:26 ` Johan Hedberg
@ 2010-08-25 13:06   ` Colin Didier
  2010-08-25 13:28     ` Johan Hedberg
  0 siblings, 1 reply; 4+ messages in thread
From: Colin Didier @ 2010-08-25 13:06 UTC (permalink / raw)
  To: Johan Hedberg; +Cc: linux-bluetooth

If for some reason there is not enough data provided to the function
bluetooth_a2dp_write() and there are leftovers to handle, the ALSA
module will segfault.
---
 audio/pcm_bluetooth.c |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/audio/pcm_bluetooth.c b/audio/pcm_bluetooth.c
index 4c0ab6f..ff463fe 100644
--- a/audio/pcm_bluetooth.c
+++ b/audio/pcm_bluetooth.c
@@ -1050,8 +1050,11 @@ static snd_pcm_sframes_t bluetooth_a2dp_write(snd_pcm_ioplug_t *io,
 	}
 
 	/* Check if we have any left over data from the last write */
-	if (data->count > 0 && (bytes_left - data->count) >= a2dp->codesize) {
-		int additional_bytes_needed = a2dp->codesize - data->count;
+	if (data->count > 0) {
+		unsigned int additional_bytes_needed =
+						a2dp->codesize - data->count;
+		if (additional_bytes_needed > bytes_left)
+			goto out;
 
 		memcpy(data->buffer + data->count, buff,
 						additional_bytes_needed);
@@ -1122,6 +1125,7 @@ static snd_pcm_sframes_t bluetooth_a2dp_write(snd_pcm_ioplug_t *io,
 		}
 	}
 
+out:
 	/* Copy the extra to our temp buffer for the next write */
 	if (bytes_left > 0) {
 		memcpy(data->buffer + data->count, buff, bytes_left);
-- 
1.7.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] Fix leftovers handling
  2010-08-25 13:06   ` [PATCH] Fix leftovers handling Colin Didier
@ 2010-08-25 13:28     ` Johan Hedberg
  0 siblings, 0 replies; 4+ messages in thread
From: Johan Hedberg @ 2010-08-25 13:28 UTC (permalink / raw)
  To: Colin Didier; +Cc: linux-bluetooth

Hi Colin,

On Wed, Aug 25, 2010, Colin Didier wrote:
> If for some reason there is not enough data provided to the function
> bluetooth_a2dp_write() and there are leftovers to handle, the ALSA
> module will segfault.
> ---
>  audio/pcm_bluetooth.c |    8 ++++++--
>  1 files changed, 6 insertions(+), 2 deletions(-)

Thanks. This patch is now upstream.

Johan

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2010-08-25 13:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-08-25  8:49 [PATCH] Fix left overs handling in bluetooth_a2dp_write() of audio/pcm_bluetooth.c Colin Didier
2010-08-25 11:26 ` Johan Hedberg
2010-08-25 13:06   ` [PATCH] Fix leftovers handling Colin Didier
2010-08-25 13:28     ` Johan Hedberg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox