]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
mdadm: lib.c fix coverity issues
authorNigel Croxon <ncroxon@redhat.com>
Tue, 16 Jul 2024 11:20:10 +0000 (07:20 -0400)
committerMariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
Tue, 16 Jul 2024 14:20:16 +0000 (16:20 +0200)
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 <ncroxon@redhat.com>
lib.c

diff --git a/lib.c b/lib.c
index 2b09293cfaded961d73fd318c737163f7138f2b4..13d4e4f1f87a071531ee86f9f736b57f728c816f 100644 (file)
--- 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;
                }
        }