alsactl: sprintf to snprintf prevent buffer overflow

sprintf() is a bit dangerous unless you explicitly know your type size
and want to keep it in sync always. Its safer to just use snprintf() and
ensure your string doesn't overflow and is NULL terminated.

Signed-off-by: Doug Goldstein <cardoe@cardoe.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
Doug Goldstein 2013-05-01 11:30:26 -05:00 committed by Takashi Iwai
parent b4f34ac260
commit 888275e66c

View file

@ -53,9 +53,9 @@ static int state_lock_(const char *file, int lock, int timeout)
lck.l_len = 11; lck.l_len = 11;
lck.l_pid = 0; lck.l_pid = 0;
if (lock) { if (lock) {
sprintf(lcktxt, "%10li\n", (long)getpid()); snprintf(lcktxt, sizeof(lcktxt), "%10li\n", (long)getpid());
} else { } else {
sprintf(lcktxt, "%10s\n", ""); snprintf(lcktxt, sizeof(lcktxt), "%10s\n", "");
} }
while (fd < 0 && timeout-- > 0) { while (fd < 0 && timeout-- > 0) {
fd = open(nfile, O_RDWR); fd = open(nfile, O_RDWR);