]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libblkid: Avoid strlen if only first char is checked
authorTobias Stoeckmann <tobias@stoeckmann.org>
Mon, 3 Oct 2016 20:05:03 +0000 (22:05 +0200)
committerKarel Zak <kzak@redhat.com>
Thu, 6 Oct 2016 12:56:39 +0000 (14:56 +0200)
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.

libblkid/src/superblocks/befs.c
libblkid/src/superblocks/ext.c
libblkid/src/superblocks/jfs.c
libblkid/src/superblocks/nilfs.c
libblkid/src/superblocks/romfs.c
libblkid/src/superblocks/xfs.c

index 7e9eaf687b07a765a5a3a007abbb8bcfb1edff6f..36e079f106007ce6048fcc45570f82346fcad69a 100644 (file)
@@ -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)
index 5b1d179f36cbc31ab104077c178e27b8958f7bfa..caf82c1710ca879be9d25c22ca34877fd21a2cf9 100644 (file)
@@ -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);
index ac684d8cd75cee51518cd702c523d91be808ccc0..0f956ef00d242e84281f32c7a1ac333ab50b9ef4 100644 (file)
@@ -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;
index ab0f74c23f6d7a516878808db45c45e3c11d4b1e..ee5c5f9b4844927c6029464a56ce7f9106cb76fa 100644 (file)
@@ -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));
 
index 8e63c100d0d70763577925631d876520fcb2a63c..f3e9f8b05d6eae3b211d26e3e19cfbb065896b8a 100644 (file)
@@ -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;
index 01e9cda8200c3349b6f4b2e168d138d57561d4fe..99848f9004a1bb350d3e0e1629232110b9ce55e7 100644 (file)
@@ -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);