From: Takashi Iwai Subject: Re: [PATCH] terminate readlink result string Date: Mon, 13 Jul 2015 16:38:02 +0200 Message-ID: References: <20150711112356.GA30962@localhost> Mime-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mx2.suse.de (cantor2.suse.de [195.135.220.15]) by alsa0.perex.cz (Postfix) with ESMTP id A7DA7260632 for ; Mon, 13 Jul 2015 16:38:03 +0200 (CEST) In-Reply-To: <20150711112356.GA30962@localhost> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org To: Tobias Stoeckmann Cc: alsa-devel@alsa-project.org List-Id: alsa-devel@alsa-project.org On Sat, 11 Jul 2015 13:23:57 +0200, Tobias Stoeckmann wrote: > > readlink does not guarantee that its result string is nul-terminated. > Instead, increase the buffer by one byte to make sure that we can > add '\0' at the end. Applied, thanks. Takashi > --- > alsactl/init_sysfs.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/alsactl/init_sysfs.c b/alsactl/init_sysfs.c > index 0cbada2..5c789b6 100644 > --- a/alsactl/init_sysfs.c > +++ b/alsactl/init_sysfs.c > @@ -108,11 +108,11 @@ static char *sysfs_attr_get_value(const char *devpath, const char *attr_name) > > if (S_ISLNK(statbuf.st_mode)) { > /* links return the last element of the target path */ > - char link_target[PATH_SIZE]; > + char link_target[PATH_SIZE + 1]; > int len; > const char *pos; > > - len = readlink(path_full, link_target, sizeof(link_target)); > + len = readlink(path_full, link_target, sizeof(link_target) - 1); > if (len > 0) { > link_target[len] = '\0'; > pos = strrchr(link_target, '/'); > -- > 2.4.5 > > _______________________________________________ > Alsa-devel mailing list > Alsa-devel@alsa-project.org > http://mailman.alsa-project.org/mailman/listinfo/alsa-devel >