]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
login: fix memory leak [coverity scan]
authorKarel Zak <kzak@redhat.com>
Tue, 23 May 2023 08:43:59 +0000 (10:43 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 23 May 2023 08:43:59 +0000 (10:43 +0200)
Let's use ul_path_read_buffer() to avoid memory allocation.

Signed-off-by: Karel Zak <kzak@redhat.com>
login-utils/login.c

index 17b54a7f6393ea5c1871a32e34bb3e56bed2262c..129f3cfa2e3bc30e5aa99f2b50e19619a54dd54d 100644 (file)
@@ -1311,13 +1311,12 @@ static void load_credentials(struct login_context *cxt) {
        }
 
        while ((d = xreaddir(dir))) {
-               char *str;
+               char str[32] = { 0 };
 
-               if (strcmp(d->d_name, "login.noauth") == 0) {
-                       ul_path_read_string(pc, &str, d->d_name);
-                       if (str && strcmp(str, "yes") == 0)
-                               cxt->noauth = 1;
-               }
+               if (strcmp(d->d_name, "login.noauth") == 0
+                   && ul_path_read_buffer(pc, str, sizeof(str), d->d_name) > 0
+                   && *str && strcmp(str, "yes") == 0)
+                       cxt->noauth = 1;
        }
 }