Whamcloud - gitweb
libext2fs: fix uninitialized length in rep_strdup()
authorTheodore Ts'o <tytso@mit.edu>
Sat, 18 Aug 2018 17:29:41 +0000 (13:29 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Sat, 18 Aug 2018 17:32:25 +0000 (13:32 -0400)
For platforms whose libc don't supply strdup(), the replacement strdup
function in lib/ext2fs/tdb.c needs to always initialize the length
variable.

Reported-by: Vladyslav Tsilytskyi <ykp@protonmail.ch>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
lib/ext2fs/tdb.c

index 195a4c0..5091b12 100644 (file)
@@ -79,12 +79,10 @@ static char *rep_strdup(const char *s)
 {
        char *ret;
        int length;
+
        if (!s)
                return NULL;
-
-       if (!length)
-               length = strlen(s);
-
+       length = strlen(s);
        ret = malloc(length + 1);
        if (ret) {
                strncpy(ret, s, length);