From: Darrick J. Wong Date: Tue, 26 May 2020 18:36:03 +0000 (-0400) Subject: xfs_db: don't crash if el_gets returns null X-Git-Tag: xfsprogs-5.7-fixes_2020-06-25~9 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cafb847b11b7f7cca0b7c02ffbe7ae6796614a4a;p=thirdparty%2Fxfsprogs-dev.git xfs_db: don't crash if el_gets returns null el_gets returns NULL if it fails to read any characters (due to EOF or errors occurred). strdup will crash if it is fed a NULL string, so check the return value to avoid segfaulting. Signed-off-by: Darrick J. Wong Reviewed-by: Eric Sandeen Reviewed-by: Christoph Hellwig Signed-off-by: Eric Sandeen --- diff --git a/db/input.c b/db/input.c index 553025bc9..448e84b09 100644 --- a/db/input.c +++ b/db/input.c @@ -230,14 +230,21 @@ fetchline(void) } if (inputstacksize == 1) { - line = xstrdup(el_gets(el, &count)); - if (line) { - if (count > 0) - line[count-1] = '\0'; - if (*line) { - history(hist, &hevent, H_ENTER, line); - logprintf("%s", line); - } + const char *cmd; + + cmd = el_gets(el, &count); + if (!cmd) + return NULL; + + line = xstrdup(cmd); + if (!line) + return NULL; + + if (count > 0) + line[count-1] = '\0'; + if (*line) { + history(hist, &hevent, H_ENTER, line); + logprintf("%s", line); } } else { line = fetchline_internal();