[pulseaudio-discuss] [PATCH] modargs: Fix get_sample_rate if no "rate" is present in the modarg

Peter Meerwald pmeerw at pmeerw.net
Wed Dec 11 07:46:07 PST 2013


Hello, 

> This patch fixes a bug which was introduced in:
>     e74d4244a285a7e29300c19df7b202ba7c51ecef
> 
> The offending function was introduced in:
>     832ad693f5081b09a36d180f81c19be9092eb2e9
> pa_modargs_get_samplerate() is not safe to be called if the modarg does
> not contain an entry with a "rate" key.

Tanu made a point here
http://lists.freedesktop.org/archives/pulseaudio-discuss/2013-October/019015.html
saying that the function's output 'rate' should only be modified on 
success 

unfortunately the local variable does not get initialized, leading to the 
bug you observed when no "rate" modarg is present

I think the correct way to fix this is to initialize local_rate to rate; 
this matches the logic of pa_modargs_get_sample_spec() and most other 
getter functions, except pa_modargs_get_alternate_sample_rate()

I'll post fixes addressing this issues; there are complains on the mail 
list regarding this issues, sorry for the delay

regards, p.

> pa_modargs_get_value_u32 returns 0 (success) if no value with the
> specified key is found, in this case the rate_local variable inside
> pa_modargs_get_samplerate() remains uninitialized.
 
> This patch modifies the pa_modargs_get_samplerate() function to modify
> the function argument rate. The function must now be called with an
> initialized rate argument.
> ---
>  src/pulsecore/modargs.c | 10 +++-------
>  1 file changed, 3 insertions(+), 7 deletions(-)
> 
> diff --git a/src/pulsecore/modargs.c b/src/pulsecore/modargs.c
> index 432e480..f3bf803 100644
> --- a/src/pulsecore/modargs.c
> +++ b/src/pulsecore/modargs.c
> @@ -365,17 +365,13 @@ int pa_modargs_get_value_volume(pa_modargs *ma, const char *key, pa_volume_t *va
>  }
>  
>  int pa_modargs_get_sample_rate(pa_modargs *ma, uint32_t *rate) {
> -    uint32_t rate_local;
> -
>      pa_assert(rate);
>  
> -    if ((pa_modargs_get_value_u32(ma, "rate", &rate_local)) < 0 ||
> -        rate_local <= 0 ||
> -        rate_local > PA_RATE_MAX)
> +    if ((pa_modargs_get_value_u32(ma, "rate", rate)) < 0 ||
> +        *rate <= 0 ||
> +        *rate > PA_RATE_MAX)
>          return -1;
>  
> -    *rate = rate_local;
> -
>      return 0;
>  }
>  
> 

-- 

Peter Meerwald
+43-664-2444418 (mobile)


More information about the pulseaudio-discuss mailing list