Alsa-Devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: Tobias Stoeckmann <tobias@stoeckmann.org>
Cc: alsa-devel@alsa-project.org
Subject: Re: [PATCH] terminate readlink result string
Date: Mon, 13 Jul 2015 16:38:02 +0200	[thread overview]
Message-ID: <s5hfv4sced1.wl-tiwai@suse.de> (raw)
In-Reply-To: <20150711112356.GA30962@localhost>

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
> 

      reply	other threads:[~2015-07-13 14:38 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-11 11:23 [PATCH] terminate readlink result string Tobias Stoeckmann
2015-07-13 14:38 ` Takashi Iwai [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=s5hfv4sced1.wl-tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=alsa-devel@alsa-project.org \
    --cc=tobias@stoeckmann.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox