[dev] [sbase] [PATCH] ls: Always leave room for the NULL byte in the link target

From: Michael Forney <mforney_AT_mforney.org>
Date: Mon, 8 Dec 2014 02:19:34 +0000

Otherwise, if the length of the link target is the same as BUFSIZ, we
will try to write past the end of buf.
---
 ls.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/ls.c b/ls.c
index b48391b..a2fb5cb 100644
--- a/ls.c
+++ b/ls.c
_AT_@ -291,7 +291,7 @@ output(Entry *ent)
 		printf("%10lu ", (unsigned long)ent->size);
 	printf("%s %s%s", buf, ent->name, indicator(ent->mode));
 	if (S_ISLNK(ent->mode)) {
-		if ((len = readlink(ent->name, buf, sizeof buf)) < 0)
+		if ((len = readlink(ent->name, buf, sizeof buf - 1)) < 0)
 			eprintf("readlink %s:", ent->name);
 		buf[len] = '\0';
 		mkent(&entlnk, buf, Fflag);
-- 
2.1.3.1.g339ec9c
Received on Mon Dec 08 2014 - 03:19:34 CET

This archive was generated by hypermail 2.3.0 : Mon Dec 08 2014 - 03:24:07 CET