From 0af8c9ebf50b68ad5f80efad7e94688235544a3d Mon Sep 17 00:00:00 2001 From: Kinga Stefaniuk Date: Thu, 4 Jul 2024 14:53:35 +0200 Subject: [PATCH 130/157] super0: use define for char array in examine_super0 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 --- mdadm.h | 3 +++ super0.c | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/mdadm.h b/mdadm.h index 27009154..22d5e8f4 100644 --- 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 diff --git a/super0.c b/super0.c index 9b8a1bd6..9b4e187e 100644 --- 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; -- 2.41.0