]> 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>
Tue, 23 Oct 2012 10:40:39 +0000 (12:40 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
lib/sysfs.c
misc-utils/lsblk.c
misc-utils/lslocks.c
sys-utils/eject.c

index 29bde82d0a02a50f798f552bae18a4b8b825ca0c..3ac1fe0ca4743902592088374df98092303999ca 100644 (file)
@@ -646,7 +646,7 @@ int sysfs_scsi_get_hctl(struct sysfs_cxt *cxt, int *h, int *c, int *t, int *l)
        if (cxt->has_hctl)
                goto done;
 
-       len = sysfs_readlink(cxt, "device", buf, sizeof(buf));
+       len = sysfs_readlink(cxt, "device", buf, sizeof(buf) - 1);
        if (len < 0)
                return len;
 
index ae203cab21c045f96dd4becbefeec72e2cfa2ba3..c57e78f1f84db44d48f4a8cf0f68706cdc280669 100644 (file)
@@ -1045,7 +1045,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';
@@ -1158,7 +1158,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 820f5dcfaafb59352c828537cb29bb37c02e8d00..33dc88750cf2e31853264ed0c71241dfd972c7f7 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 5d5d7b18b3aa30520d45b806aa3b03cb03665955..e28837155e761deebd63737b6ba89ab891afae29 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';