[PATCH] nul-terminate readlink result

Tobias Stoeckmann tobias at stoeckmann.org
Sat Jul 11 02:02:57 PDT 2015


readlink by itself does not guarantee that its result is properly
nul-terminated. Setting the last byte of the buffer to '\0' fixes
this issue.
---
 libkms/linux.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libkms/linux.c b/libkms/linux.c
index 4d47148..667d37c 100644
--- a/libkms/linux.c
+++ b/libkms/linux.c
@@ -82,6 +82,7 @@ linux_name_from_sysfs(int fd, char **out)
 
 	if (readlink(path, link, PATH_SIZE) < 0)
 		return -EINVAL;
+	link[PATH_SIZE] = '\0';
 
 	/* link looks something like this: ../../../bus/pci/drivers/intel */
 	slash_name = strrchr(link, '/');
-- 
2.4.5



More information about the dri-devel mailing list