lib:util: Fix string check in mkdir_p()
authorAndreas Schneider <asn@samba.org>
Tue, 8 May 2018 07:22:00 +0000 (09:22 +0200)
committerAndreas Schneider <asn@cryptomilk.org>
Thu, 17 May 2018 15:30:09 +0000 (17:30 +0200)
BUG: https://bugzilla.samba.org/show_bug.cgi?id=13437

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Guenther Deschner <gd@samba.org>
lib/util/mkdir_p.c

index 290a1f395206436269901477ac8840a25886f32d..87a3f797618442403a106bf7ee9906056556007f 100644 (file)
@@ -49,11 +49,11 @@ int mkdir_p(const char *dir, int mode)
 
        /* Create ancestors */
        len = strlen(dir);
-       if (len >= PATH_MAX) {
+       ret = snprintf(t, sizeof(t), "%s", dir);
+       if (ret != len) {
                errno = ENAMETOOLONG;
                return -1;
        }
-       strncpy(t, dir, len+1);
 
        ret = mkdir_p(dirname(t), mode);
        if (ret != 0) {