Skip to content

Commit

Permalink
ALSA: compress - move the buffer check
Browse files Browse the repository at this point in the history
Commit ALSA: compress_core: integer overflow in snd_compr_allocate_buffer()
added a new error check for input params.
this add new routine for input checks and moves buffer overflow check to this
new routine. This allows the error value to be propogated to user space

Signed-off-by: Vinod Koul <[email protected]>
Signed-off-by: Takashi Iwai <[email protected]>
  • Loading branch information
Vinod Koul authored and tiwai committed Sep 17, 2012
1 parent e5d6db8 commit 4dc040a
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions sound/core/compress_offload.c
Original file line number Diff line number Diff line change
Expand Up @@ -407,10 +407,6 @@ static int snd_compr_allocate_buffer(struct snd_compr_stream *stream,
unsigned int buffer_size;
void *buffer;

if (params->buffer.fragment_size == 0 ||
params->buffer.fragments > SIZE_MAX / params->buffer.fragment_size)
return -EINVAL;

buffer_size = params->buffer.fragment_size * params->buffer.fragments;
if (stream->ops->copy) {
buffer = NULL;
Expand All @@ -429,6 +425,16 @@ static int snd_compr_allocate_buffer(struct snd_compr_stream *stream,
return 0;
}

static int snd_compress_check_input(struct snd_compr_params *params)
{
/* first let's check the buffer parameter's */
if (params->buffer.fragment_size == 0 ||
params->buffer.fragments > SIZE_MAX / params->buffer.fragment_size)
return -EINVAL;

return 0;
}

static int
snd_compr_set_params(struct snd_compr_stream *stream, unsigned long arg)
{
Expand All @@ -447,11 +453,17 @@ snd_compr_set_params(struct snd_compr_stream *stream, unsigned long arg)
retval = -EFAULT;
goto out;
}

retval = snd_compress_check_input(params);
if (retval)
goto out;

retval = snd_compr_allocate_buffer(stream, params);
if (retval) {
retval = -ENOMEM;
goto out;
}

retval = stream->ops->set_params(stream, params);
if (retval)
goto out;
Expand Down

0 comments on commit 4dc040a

Please sign in to comment.