From: Nigel Croxon Date: Tue, 16 Jul 2024 11:20:10 +0000 (-0400) Subject: mdadm: lib.c fix coverity issues X-Git-Tag: mdadm-4.4~122 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=da7aecdf25371e1476da4ec56e9ec5ddf13af5da;p=thirdparty%2Fmdadm.git mdadm: lib.c fix coverity issues Fixing the following coding errors the coverity tools found: * Event fixed_size_dest: You might overrun the 32-character fixed-size string "devnm" by copying "cp + 1" without checking the length. * Event fixed_size_dest: You might overrun the 32-character fixed-size string "devnm" by copying "cp" without checking the length. Signed-off-by: Nigel Croxon --- diff --git a/lib.c b/lib.c index 2b09293c..13d4e4f1 100644 --- a/lib.c +++ b/lib.c @@ -109,7 +109,7 @@ char *devid2kname(dev_t devid) link[n] = 0; cp = strrchr(link, '/'); if (cp) { - strcpy(devnm, cp + 1); + snprintf(devnm, sizeof(devnm), "%s", cp + 1); return devnm; } } @@ -159,7 +159,7 @@ char *devid2devnm(dev_t devid) ep = strchr(cp, '/'); if (ep) *ep = 0; - strcpy(devnm, cp); + snprintf(devnm, sizeof(devnm), "%s", cp); return devnm; } }