From a5e0e06cc2ff05f01a3fcf799a5f2c2fe6fb217f Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Tue, 23 May 2023 10:43:59 +0200 Subject: [PATCH] login: fix memory leak [coverity scan] Let's use ul_path_read_buffer() to avoid memory allocation. Signed-off-by: Karel Zak --- login-utils/login.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/login-utils/login.c b/login-utils/login.c index 17b54a7f63..129f3cfa2e 100644 --- a/login-utils/login.c +++ b/login-utils/login.c @@ -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; } } -- 2.47.3