]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
super0: use define for char array in examine_super0
authorKinga Stefaniuk <kinga.stefaniuk@intel.com>
Thu, 4 Jul 2024 12:53:35 +0000 (14:53 +0200)
committerMariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
Tue, 30 Jul 2024 13:59:24 +0000 (15:59 +0200)
Using nb with 11 length may cause format-truncation errors,
because it was possible to use snprintf with 12 length input
and write it to 11 length output. Added new define and use it
to avoid this error.

Signed-off-by: Kinga Stefaniuk <kinga.stefaniuk@intel.com>
mdadm.h
super0.c

diff --git a/mdadm.h b/mdadm.h
index 27009154297f38140fbdffe3826551ce36e8d4ef..22d5e8f49bc2de5d8277f1188cd923b3c7cb7781 100644 (file)
--- a/mdadm.h
+++ b/mdadm.h
@@ -2021,6 +2021,9 @@ enum r0layout {
 #define PATH_MAX       4096
 #endif
 
+/* The max string length necessary for decimal conversion, cannot be longer than count of bits */
+#define INT_2_DEC_STR_MAX (sizeof(int) * 8)
+
 #define RESYNC_NONE -1
 #define RESYNC_DELAYED -2
 #define RESYNC_PENDING -3
index 9b8a1bd63bb7a6657abe56b5d1e51f4a27431f14..9b4e187e83b8ec6672f55335a6da82e5b64462d9 100644 (file)
--- a/super0.c
+++ b/super0.c
@@ -229,7 +229,7 @@ static void examine_super0(struct supertype *st, char *homehost)
             d++) {
                mdp_disk_t *dp;
                char *dv;
-               char nb[11];
+               char nb[INT_2_DEC_STR_MAX];
                int wonly, failfast;
                if (d>=0) dp = &sb->disks[d];
                else dp = &sb->this_disk;