From: Theodore Ts'o Date: Sat, 18 Aug 2018 17:29:41 +0000 (-0400) Subject: libext2fs: fix uninitialized length in rep_strdup() X-Git-Tag: v1.44.4~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dd3b4cc367ce5c9208f0ef9960ddf34d6d0a45b9;p=thirdparty%2Fe2fsprogs.git libext2fs: fix uninitialized length in rep_strdup() 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 Signed-off-by: Theodore Ts'o --- diff --git a/lib/ext2fs/tdb.c b/lib/ext2fs/tdb.c index 195a4c0b8..5091b128b 100644 --- a/lib/ext2fs/tdb.c +++ b/lib/ext2fs/tdb.c @@ -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);