From c0fc4d2122057530b11567503839116dca5998ce Mon Sep 17 00:00:00 2001 From: Samanta Navarro Date: Fri, 28 Apr 2023 11:54:38 +0000 Subject: [PATCH] libmisc/yesno.c: Fix regression The getline function does not return a pointer but the amount of read characters. The error return value to check for is -1. Set buf to NULL to avoid dereference of an uninitialized stack value. The getline function returns -1 if size argument is NULL. Always use a valid pointer even if size is unimportant. Signed-off-by: Samanta Navarro --- libmisc/yesno.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/libmisc/yesno.c b/libmisc/yesno.c index 2ef4d9fa..029cd815 100644 --- a/libmisc/yesno.c +++ b/libmisc/yesno.c @@ -50,8 +50,9 @@ static int rpmatch(const char *response); bool yes_or_no(bool read_only) { - bool ret; - char *buf; + bool ret; + char *buf; + size_t size; if (read_only) { puts(_("No")); @@ -60,8 +61,10 @@ yes_or_no(bool read_only) fflush(stdout); + buf = NULL; ret = false; - if (getline(&buf, NULL, stdin) != NULL) + size = 0; + if (getline(&buf, &size, stdin) != -1) ret = rpmatch(buf) == 1; free(buf);