From 0ab52bd3ebc24780827e96be84ca8dd462c7667b Mon Sep 17 00:00:00 2001 From: Eric van Gyzen Date: Mon, 13 Jan 2020 22:33:48 +0000 Subject: [PATCH] fstyp hammer: use strlcpy Use strlcpy to guarantee NUL termination. Due to this, there is no need for strncmp; simply use strcmp. Reported by: Coverity CID: 1412242 MFC after: 2 weeks Sponsored by: Dell EMC Isilon Differential Revision: https://reviews.freebsd.org/D23159 --- usr.sbin/fstyp/hammer.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/usr.sbin/fstyp/hammer.c b/usr.sbin/fstyp/hammer.c index dc41166938dd..3d35813284f2 100644 --- a/usr.sbin/fstyp/hammer.c +++ b/usr.sbin/fstyp/hammer.c @@ -76,7 +76,7 @@ __test_ondisk(const hammer_volume_ondisk_t ondisk) assert(count != 0); memcpy(&fsid, &ondisk->vol_fsid, sizeof(fsid)); memcpy(&fstype, &ondisk->vol_fstype, sizeof(fstype)); - strncpy(label, ondisk->vol_label, sizeof(label)); + strlcpy(label, ondisk->vol_label, sizeof(label)); } else { if (ondisk->vol_count != count) return (5); @@ -84,7 +84,7 @@ __test_ondisk(const hammer_volume_ondisk_t ondisk) return (6); if (memcmp(&ondisk->vol_fstype, &fstype, sizeof(fstype))) return (7); - if (strncmp(ondisk->vol_label, label, sizeof(label))) + if (strcmp(ondisk->vol_label, label)) return (8); }