[hackers] [sbase] ls: Always leave room for the NULL byte in the link target || Michael Forney

From: <git_AT_suckless.org>
Date: Mon, 08 Dec 2014 11:02:33 +0100

commit 573ef00c91fc70edb76afd72f44b9b7bfffd23ff
Author: Michael Forney <mforney_AT_mforney.org>
Date: Mon Dec 8 02:19:34 2014 +0000

    ls: Always leave room for the NULL byte in the link target
    
    Otherwise, if the length of the link target is the same as BUFSIZ, we
    will try to write past the end of buf.

diff --git a/ls.c b/ls.c
index 24af998..ef3f5f6 100644
--- a/ls.c
+++ b/ls.c
_AT_@ -300,7 +300,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';
                 printf(" -> %s%s", buf, indicator(ent->tmode));
Received on Mon Dec 08 2014 - 11:02:33 CET

This archive was generated by hypermail 2.3.0 : Mon Dec 08 2014 - 11:12:11 CET