summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarel Zak2012-10-23 12:40:39 +0200
committerKarel Zak2012-10-23 12:40:39 +0200
commit9f51089e7f14f9b6f432a20ca59c0db5e5f16325 (patch)
tree85b04f0899cc474ba7ec3a97dcf620ce3f22ee63
parentlsblk: use new sysfs functions, clean up get_transport() (diff)
downloadkernel-qcow2-util-linux-9f51089e7f14f9b6f432a20ca59c0db5e5f16325.tar.gz
kernel-qcow2-util-linux-9f51089e7f14f9b6f432a20ca59c0db5e5f16325.tar.xz
kernel-qcow2-util-linux-9f51089e7f14f9b6f432a20ca59c0db5e5f16325.zip
misc: make readlink() usage more robust
Signed-off-by: Karel Zak <kzak@redhat.com>
-rw-r--r--lib/sysfs.c2
-rw-r--r--misc-utils/lsblk.c4
-rw-r--r--misc-utils/lslocks.c2
-rw-r--r--sys-utils/eject.c2
4 files changed, 5 insertions, 5 deletions
diff --git a/lib/sysfs.c b/lib/sysfs.c
index 29bde82d0..3ac1fe0ca 100644
--- a/lib/sysfs.c
+++ b/lib/sysfs.c
@@ -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;
diff --git a/misc-utils/lsblk.c b/misc-utils/lsblk.c
index ae203cab2..c57e78f1f 100644
--- a/misc-utils/lsblk.c
+++ b/misc-utils/lsblk.c
@@ -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;
diff --git a/misc-utils/lslocks.c b/misc-utils/lslocks.c
index 820f5dcfa..33dc88750 100644
--- a/misc-utils/lslocks.c
+++ b/misc-utils/lslocks.c
@@ -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;
diff --git a/sys-utils/eject.c b/sys-utils/eject.c
index 5d5d7b18b..e28837155 100644
--- a/sys-utils/eject.c
+++ b/sys-utils/eject.c
@@ -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';