]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
libmisc/yesno.c: Fix regression
authorSamanta Navarro <ferivoz@riseup.net>
Fri, 28 Apr 2023 11:54:38 +0000 (11:54 +0000)
committerSerge Hallyn <serge@hallyn.com>
Fri, 28 Apr 2023 16:22:48 +0000 (11:22 -0500)
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>
libmisc/yesno.c

index 2ef4d9fab79182050ef3b525b4001a4b309ad8df..029cd815e1c88213934ec72566a8634e8712751a 100644 (file)
@@ -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);