From 2fc2bb7ebd30b25403447fea63dd5f7e69652f44 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Mon, 21 Jun 2021 15:31:43 +0200 Subject: [PATCH] lslogins: check errno after strto..() Addresses: https://github.com/karelzak/util-linux/issues/1356 Signed-off-by: Karel Zak --- login-utils/lslogins.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/login-utils/lslogins.c b/login-utils/lslogins.c index 109e07fea8..d5e9638bfb 100644 --- a/login-utils/lslogins.c +++ b/login-utils/lslogins.c @@ -908,11 +908,14 @@ static struct lslogins_user *get_user_info(struct lslogins_control *ctl, const c static int str_to_uint(char *s, unsigned int *ul) { - char *end; + char *end = NULL; + if (!s || !*s) return -1; + + errno = 0; *ul = strtoul(s, &end, 0); - if (!*end) + if (errno == 0 && end && !*end) return 0; return 1; } -- 2.47.3