]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
misc: make readlink() usage more robust
authorKarel Zak <kzak@redhat.com>
Tue, 23 Oct 2012 10:40:39 +0000 (12:40 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 31 Oct 2012 13:02:32 +0000 (14:02 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
misc-utils/lsblk.c
misc-utils/lslocks.c
sys-utils/eject.c

index cc97c052c5b0d6eb315b15b50aa0c8ef9902e007..9c25dd0c0dbf69e48ff18288be2ee944605dd28f 100644 (file)
@@ -962,7 +962,7 @@ static int get_wholedisk_from_partition_dirent(DIR *dir, const char *dirname,
        int len;
 
        if ((len = readlink_at(dirfd(dir), dirname,
-                              d->d_name, path, sizeof(path))) < 0)
+                              d->d_name, path, sizeof(path) - 1)) < 0)
                return 0;
 
        path[len] = '\0';
@@ -1075,7 +1075,7 @@ static char *devno_to_sysfs_name(dev_t devno, char *devname, char *buf, size_t b
                return NULL;
        }
 
-       len = readlink(path, buf, buf_size);
+       len = readlink(path, buf, buf_size - 1);
        if (len < 0) {
                warn(_("%s: failed to read link"), path);
                return NULL;
index 45fb6de9760c29b5dd2f35eed3c2b6b574db1bc5..495eb80267e56b83a28998f0bc759dd03270bac5 100644 (file)
@@ -196,7 +196,7 @@ static char *get_filename_sz(ino_t inode, pid_t pid, size_t *size)
                        continue;
 
                if ((len = readlink_at(fd, path, dp->d_name,
-                                      sym, sizeof(path))) < 1)
+                                      sym, sizeof(sym) - 1)) < 1)
                        goto out;
 
                *size = sb.st_size;
index 1a5b834096b4a4d5182f5dc7d3c1d163fdc18563..6d0da18727b30e27a7dbb92531b95d7f62a57a2f 100644 (file)
@@ -837,7 +837,7 @@ static char *get_subsystem(char *chain, char *buf, size_t bufsz)
                memcpy(chain + len, SUBSYSTEM_LINKNAME, sizeof(SUBSYSTEM_LINKNAME));
 
                /* try if subsystem symlink exists */
-               sz = readlink(chain, buf, bufsz);
+               sz = readlink(chain, buf, bufsz - 1);
 
                /* remove last subsystem from chain */
                chain[len] = '\0';