dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Tobias Stoeckmann <tobias@stoeckmann.org>
To: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH] nul-terminate readlink result
Date: Sun, 12 Jul 2015 12:14:47 +0200	[thread overview]
Message-ID: <20150712101446.GA15768@localhost> (raw)
In-Reply-To: <20150711090257.GA13400@localhost>

On Sat, Jul 11, 2015 at 11:02:57AM +0200, Tobias Stoeckmann wrote:
>  	if (readlink(path, link, PATH_SIZE) < 0)
>  		return -EINVAL;
> +	link[PATH_SIZE] = '\0';

Sorry, this patch is wrong. It has to be terminated at the correct
position. Please see this updated version:


From a1840916dd370d5c84ebf23df91f1c13d564d212 Mon Sep 17 00:00:00 2001
From: Tobias Stoeckmann <tobias@stoeckmann.org>
Date: Sun, 12 Jul 2015 12:10:59 +0200
Subject: [PATCH] nul-terminate readlink result

readlink by itself does not terminate its result. The caller has
to terminate the string at the proper position.
---
 libkms/linux.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/libkms/linux.c b/libkms/linux.c
index 4d47148..5e2431f 100644
--- a/libkms/linux.c
+++ b/libkms/linux.c
@@ -55,6 +55,7 @@ linux_name_from_sysfs(int fd, char **out)
 	unsigned maj, min;
 	char* slash_name;
 	int ret;
+	ssize_t len;
 
 	/* 
 	 * Inside the sysfs directory for the device there is a symlink
@@ -80,8 +81,9 @@ linux_name_from_sysfs(int fd, char **out)
 
 	snprintf(path, PATH_SIZE, "/sys/dev/char/%d:%d/device/driver", maj, min);
 
-	if (readlink(path, link, PATH_SIZE) < 0)
+	if ((len = readlink(path, link, PATH_SIZE)) < 0)
 		return -EINVAL;
+	link[len] = '\0';
 
 	/* link looks something like this: ../../../bus/pci/drivers/intel */
 	slash_name = strrchr(link, '/');
-- 
2.4.5

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

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

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-11  9:02 [PATCH] nul-terminate readlink result Tobias Stoeckmann
2015-07-12 10:14 ` Tobias Stoeckmann [this message]
2015-07-13 15:42   ` Emil Velikov

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=20150712101446.GA15768@localhost \
    --to=tobias@stoeckmann.org \
    --cc=dri-devel@lists.freedesktop.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