]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
Utils: Change sprintf to snprintf
authorMateusz Kusiak <mateusz.kusiak@intel.com>
Thu, 12 Aug 2021 11:48:48 +0000 (13:48 +0200)
committerJes Sorensen <jsorensen@fb.com>
Fri, 13 Aug 2021 19:21:12 +0000 (15:21 -0400)
Using sprintf can cause segmentation fault by exceeding the size of buffer array.

Signed-off-by: Mateusz Kusiak <mateusz.kusiak@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
util.c

diff --git a/util.c b/util.c
index cdf1da24f2d11456b49f880a87fe7be513d13735..ea07277cea2e20f895c319030d24818515c52805 100644 (file)
--- a/util.c
+++ b/util.c
@@ -947,12 +947,12 @@ dev_t devnm2devid(char *devnm)
        /* First look in /sys/block/$DEVNM/dev for %d:%d
         * If that fails, try parsing out a number
         */
-       char path[100];
+       char path[PATH_MAX];
        char *ep;
        int fd;
        int mjr,mnr;
 
-       sprintf(path, "/sys/block/%s/dev", devnm);
+       snprintf(path, sizeof(path), "/sys/block/%s/dev", devnm);
        fd = open(path, O_RDONLY);
        if (fd >= 0) {
                char buf[20];