Re: [PATCH] ASoC: SOF: debug: Fix a potential issue on string buffer termination

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

On Mon, 8 Feb 2021, Hui Wang wrote:

> The function simple_write_to_buffer() doesn't add string termination
> at the end of buf, we need to add it on our own if calling that
> function to write the size of count chars to buf. This change refers
> to the function tokenize_input() in debug.c and the function
> sof_dfsentry_trace_filter_write() in trace.c.
[...]
> --- a/sound/soc/sof/debug.c
> +++ b/sound/soc/sof/debug.c
> @@ -352,9 +352,10 @@ static ssize_t sof_dfsentry_write(struct file *file, const char __user *buffer,
>  	char *string;
>  	int ret;
>  
> -	string = kzalloc(count, GFP_KERNEL);
> +	string = kzalloc(count+1, GFP_KERNEL);

ouch, good catch, thanks! We have this correct in soc/sof/trace.c, but not 
here. To keep up with kernel style, maybe:

+	string = kzalloc(count + 1, GFP_KERNEL);

>  	if (!string)
>  		return -ENOMEM;
> +	string[count] = '\0';

kzalloc() returns zeros, so no need for this.

Br, Kai



[Index of Archives]     [ALSA User]     [Linux Audio Users]     [Pulse Audio]     [Kernel Archive]     [Asterisk PBX]     [Photo Sharing]     [Linux Sound]     [Video 4 Linux]     [Gimp]     [Yosemite News]

  Powered by Linux