Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

usb: gadget: u_audio: Fix the size of a buffer in a strscpy() call

The size given to strscpy() is not consistent with the destination buffer
that is used. The size is related to 'driver' and the buffer is
'mixername'.

sizeof(card->mixername) is 80 and sizeof(card->driver) is 16, so in
theory this could lead to unneeded string truncation.

In practice, this is not the case because g_audio_setup() has only 2
callers. 'card_name' is either "UAC1_Gadget" or "UAC2_Gadget".

Anyway, using the correct size is cleaner and more future proof.

In order to be less verbose, use the new 2-argument version of strscpy()
which computes auto-magically the size of the destination.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Link: https://lore.kernel.org/r/bf8a9353319566624f653531b80e5caf3d346ba1.1711176700.git.christophe.jaillet@wanadoo.fr
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Christophe JAILLET and committed by
Greg Kroah-Hartman
16fac242 f8453bbd

+1 -1
+1 -1
drivers/usb/gadget/function/u_audio.c
··· 1257 1257 if ((c_chmask && g_audio->in_ep_fback) 1258 1258 || (p_chmask && params->p_fu.id) 1259 1259 || (c_chmask && params->c_fu.id)) 1260 - strscpy(card->mixername, card_name, sizeof(card->driver)); 1260 + strscpy(card->mixername, card_name); 1261 1261 1262 1262 if (c_chmask && g_audio->in_ep_fback) { 1263 1263 kctl = snd_ctl_new1(&u_audio_controls[UAC_FBACK_CTRL],