summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSamanta Navarro <ferivoz@riseup.net>2023-04-28 11:54:38 +0000
committerSerge Hallyn <serge@hallyn.com>2023-04-28 11:22:48 -0500
commitc0fc4d2122057530b11567503839116dca5998ce (patch)
tree3e951b858dedbfb1baa142742f34194cb5be1db2
parent0c4fa6ee0af0c9d52c583d1cea6b655fb95724c1 (diff)
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 <ferivoz@riseup.net>
-rw-r--r--libmisc/yesno.c9
1 files 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);