All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] android/hal-sco: Fix divide by zero
@ 2015-03-31 15:03 Szymon Janc
  2015-03-31 18:08 ` Szymon Janc
  0 siblings, 1 reply; 2+ messages in thread
From: Szymon Janc @ 2015-03-31 15:03 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc

audio_stream_in_frame_size or audio_stream_frame_size can return 0 so
this needs to be checked before divide.
---
 android/hal-sco.c | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/android/hal-sco.c b/android/hal-sco.c
index 380b2a8..2c95866 100644
--- a/android/hal-sco.c
+++ b/android/hal-sco.c
@@ -1054,17 +1054,23 @@ static ssize_t in_read(struct audio_stream_in *stream, void *buffer,
 								size_t bytes)
 {
 	struct sco_stream_in *in = (struct sco_stream_in *) stream;
-#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
-	size_t frame_size = audio_stream_in_frame_size(&in->stream);
-#else
-	size_t frame_size = audio_stream_frame_size(&stream->common);
-#endif
-	size_t frame_num = bytes / frame_size;
-	size_t input_frame_num = frame_num;
+	size_t frame_size, frame_num, input_frame_num;
 	void *read_buf = buffer;
 	size_t total = bytes;
 	int ret;
 
+#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
+	frame_size = audio_stream_in_frame_size(&in->stream);
+#else
+	frame_size = audio_stream_frame_size(&stream->common);
+#endif
+
+	if (!frame_size)
+		return -1;
+
+	frame_num = bytes / frame_size;
+	input_frame_num = frame_num;
+
 	DBG("Read from fd %d bytes %zu", sco_fd, bytes);
 
 	if (ipc_get_sco_fd(&in->bd_addr) != SCO_STATUS_SUCCESS)
-- 
1.9.3


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

* Re: [PATCH] android/hal-sco: Fix divide by zero
  2015-03-31 15:03 [PATCH] android/hal-sco: Fix divide by zero Szymon Janc
@ 2015-03-31 18:08 ` Szymon Janc
  0 siblings, 0 replies; 2+ messages in thread
From: Szymon Janc @ 2015-03-31 18:08 UTC (permalink / raw)
  To: linux-bluetooth

On Tuesday 31 of March 2015 17:03:30 Szymon Janc wrote:
> audio_stream_in_frame_size or audio_stream_frame_size can return 0 so
> this needs to be checked before divide.
> ---
>  android/hal-sco.c | 20 +++++++++++++-------
>  1 file changed, 13 insertions(+), 7 deletions(-)
> 
> diff --git a/android/hal-sco.c b/android/hal-sco.c
> index 380b2a8..2c95866 100644
> --- a/android/hal-sco.c
> +++ b/android/hal-sco.c
> @@ -1054,17 +1054,23 @@ static ssize_t in_read(struct audio_stream_in
> *stream, void *buffer, size_t bytes)
>  {
>  	struct sco_stream_in *in = (struct sco_stream_in *) stream;
> -#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
> -	size_t frame_size = audio_stream_in_frame_size(&in->stream);
> -#else
> -	size_t frame_size = audio_stream_frame_size(&stream->common);
> -#endif
> -	size_t frame_num = bytes / frame_size;
> -	size_t input_frame_num = frame_num;
> +	size_t frame_size, frame_num, input_frame_num;
>  	void *read_buf = buffer;
>  	size_t total = bytes;
>  	int ret;
> 
> +#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
> +	frame_size = audio_stream_in_frame_size(&in->stream);
> +#else
> +	frame_size = audio_stream_frame_size(&stream->common);
> +#endif
> +
> +	if (!frame_size)
> +		return -1;
> +
> +	frame_num = bytes / frame_size;
> +	input_frame_num = frame_num;
> +
>  	DBG("Read from fd %d bytes %zu", sco_fd, bytes);
> 
>  	if (ipc_get_sco_fd(&in->bd_addr) != SCO_STATUS_SUCCESS)

Applied.

-- 
BR
Szymon Janc

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

end of thread, other threads:[~2015-03-31 18:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-31 15:03 [PATCH] android/hal-sco: Fix divide by zero Szymon Janc
2015-03-31 18:08 ` Szymon Janc

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.