summaryrefslogtreecommitdiffstats
path: root/libblkid/src
diff options
context:
space:
mode:
authorTobias Stoeckmann2016-10-03 22:05:03 +0200
committerKarel Zak2016-10-06 14:56:39 +0200
commite8c20678f3700105ea9299ad481ce3d70419bb9e (patch)
treeac28008b4628ebcadaf424279f5df877bd4cabe7 /libblkid/src
parentdocs: update infor about TIOCSTI (diff)
downloadkernel-qcow2-util-linux-e8c20678f3700105ea9299ad481ce3d70419bb9e.tar.gz
kernel-qcow2-util-linux-e8c20678f3700105ea9299ad481ce3d70419bb9e.tar.xz
kernel-qcow2-util-linux-e8c20678f3700105ea9299ad481ce3d70419bb9e.zip
libblkid: Avoid strlen if only first char is checked
A strlen() call can lead to out of boundary read access if the superblock in question has no nul-bytes after the string. This could be avoided by using strnlen() but the calls in question merely existed to check if the string length is not 0. By changing the calls as proposed with this diff, these files are in sync with other superblock files, which do exactly the same.
Diffstat (limited to 'libblkid/src')
-rw-r--r--libblkid/src/superblocks/befs.c2
-rw-r--r--libblkid/src/superblocks/ext.c2
-rw-r--r--libblkid/src/superblocks/jfs.c2
-rw-r--r--libblkid/src/superblocks/nilfs.c2
-rw-r--r--libblkid/src/superblocks/romfs.c2
-rw-r--r--libblkid/src/superblocks/xfs.c2
6 files changed, 6 insertions, 6 deletions
diff --git a/libblkid/src/superblocks/befs.c b/libblkid/src/superblocks/befs.c
index 7e9eaf687..36e079f10 100644
--- a/libblkid/src/superblocks/befs.c
+++ b/libblkid/src/superblocks/befs.c
@@ -451,7 +451,7 @@ static int probe_befs(blkid_probe pr, const struct blkid_idmag *mag)
/*
* all checks pass, set LABEL, VERSION and UUID
*/
- if (strlen(bs->name))
+ if (*bs->name != '\0')
blkid_probe_set_label(pr, (unsigned char *) bs->name,
sizeof(bs->name));
if (version)
diff --git a/libblkid/src/superblocks/ext.c b/libblkid/src/superblocks/ext.c
index 5b1d179f3..caf82c171 100644
--- a/libblkid/src/superblocks/ext.c
+++ b/libblkid/src/superblocks/ext.c
@@ -170,7 +170,7 @@ static void ext_get_info(blkid_probe pr, int ver, struct ext2_super_block *es)
le32_to_cpu(es->s_feature_incompat),
le32_to_cpu(es->s_feature_ro_compat)));
- if (strlen(es->s_volume_name))
+ if (*es->s_volume_name != '\0')
blkid_probe_set_label(pr, (unsigned char *) es->s_volume_name,
sizeof(es->s_volume_name));
blkid_probe_set_uuid(pr, es->s_uuid);
diff --git a/libblkid/src/superblocks/jfs.c b/libblkid/src/superblocks/jfs.c
index ac684d8cd..0f956ef00 100644
--- a/libblkid/src/superblocks/jfs.c
+++ b/libblkid/src/superblocks/jfs.c
@@ -49,7 +49,7 @@ static int probe_jfs(blkid_probe pr, const struct blkid_idmag *mag)
le16_to_cpu(js->js_l2bfactor))
return 1;
- if (strlen((char *) js->js_label))
+ if (*((char *) js->js_label) != '\0')
blkid_probe_set_label(pr, js->js_label, sizeof(js->js_label));
blkid_probe_set_uuid(pr, js->js_uuid);
return 0;
diff --git a/libblkid/src/superblocks/nilfs.c b/libblkid/src/superblocks/nilfs.c
index ab0f74c23..ee5c5f9b4 100644
--- a/libblkid/src/superblocks/nilfs.c
+++ b/libblkid/src/superblocks/nilfs.c
@@ -143,7 +143,7 @@ static int probe_nilfs2(blkid_probe pr,
DBG(LOWPROBE, ul_debug("nilfs2: primary=%d, backup=%d, swap=%d",
valid[0], valid[1], swp));
- if (strlen(sb->s_volume_name))
+ if (*(sb->s_volume_name) != '\0')
blkid_probe_set_label(pr, (unsigned char *) sb->s_volume_name,
sizeof(sb->s_volume_name));
diff --git a/libblkid/src/superblocks/romfs.c b/libblkid/src/superblocks/romfs.c
index 8e63c100d..f3e9f8b05 100644
--- a/libblkid/src/superblocks/romfs.c
+++ b/libblkid/src/superblocks/romfs.c
@@ -31,7 +31,7 @@ static int probe_romfs(blkid_probe pr, const struct blkid_idmag *mag)
if (!ros)
return errno ? -errno : 1;
- if (strlen((char *) ros->ros_volume))
+ if (*((char *) ros->ros_volume) != '\0')
blkid_probe_set_label(pr, ros->ros_volume,
sizeof(ros->ros_volume));
return 0;
diff --git a/libblkid/src/superblocks/xfs.c b/libblkid/src/superblocks/xfs.c
index 01e9cda82..99848f900 100644
--- a/libblkid/src/superblocks/xfs.c
+++ b/libblkid/src/superblocks/xfs.c
@@ -169,7 +169,7 @@ static int probe_xfs(blkid_probe pr, const struct blkid_idmag *mag)
if (!xfs_verify_sb(xs))
return 1;
- if (strlen(xs->sb_fname))
+ if (*xs->sb_fname != '\0')
blkid_probe_set_label(pr, (unsigned char *) xs->sb_fname,
sizeof(xs->sb_fname));
blkid_probe_set_uuid(pr, xs->sb_uuid);