lkml.org 
[lkml]   [2018]   [Mar]   [1]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: [PATCH] sound/pci/ice1712: replace strcpy() with scnprintf()
On Thu, Mar 1, 2018 at 1:45 PM, Joey Pabalinas <joeypabalinas@gmail.com> wrote:
> Replace unsafe uses of strcpy() to copy the name
> argument into the sid.name buffer with scnprintf()
> to guard against possible buffer overflows.


> - struct snd_ctl_elem_id sid;
> - memset(&sid, 0, sizeof(sid));
> - /* FIXME: strcpy is bad. */
> - strcpy(sid.name, name);
> + struct snd_ctl_elem_id sid = {0};
> +
> + scnprintf(sid.name, sizeof(sid.name), "%s", name);

So, why not just use strlcpy()?
scnprintf() here adds an overhead for no benefit.

> sid.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
> return snd_ctl_find_id(card, &sid);

> - struct snd_ctl_elem_id sid;
> - memset(&sid, 0, sizeof(sid));
> - /* FIXME: strcpy is bad. */
> - strcpy(sid.name, name);
> + struct snd_ctl_elem_id sid = {0};
> +
> + scnprintf(sid.name, sizeof(sid.name), "%s", name);
> sid.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
> return snd_ctl_find_id(card, &sid);

Ditto.

--
With Best Regards,
Andy Shevchenko

\
 
 \ /
  Last update: 2018-03-01 14:55    [W:0.088 / U:0.240 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site