From fcf6d9a4ffb72f5e6a39b9f090350ce196e81440 Mon Sep 17 00:00:00 2001 From: Thorsten Kukuk Date: Fri, 24 Jan 2025 17:06:48 +0100 Subject: [PATCH] lslogins: don't ignore stat error Signed-off-by: Thorsten Kukuk --- login-utils/lslogins.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/login-utils/lslogins.c b/login-utils/lslogins.c index ebfdf6a79..a7152737a 100644 --- a/login-utils/lslogins.c +++ b/login-utils/lslogins.c @@ -498,10 +498,14 @@ static int parse_utmpx(const char *path, size_t *nrecords, struct utmpx **record /* optimize allocation according to file size, the realloc() below is * just fallback only */ - if (stat(path, &st) == 0 && (size_t) st.st_size >= sizeof(struct utmpx)) { - imax = st.st_size / sizeof(struct utmpx); - ary = xreallocarray(NULL, imax, sizeof(struct utmpx)); - } + if (stat(path, &st) == 0) { + if ((size_t) st.st_size >= sizeof(struct utmpx)) { + imax = st.st_size / sizeof(struct utmpx); + ary = xreallocarray(NULL, imax, sizeof(struct utmpx)); + } else + return -ENODATA; + } else + return -errno; for (i = 0; ; i++) { struct utmpx *u; -- 2.47.3