From: Karel Zak Date: Mon, 21 Jun 2021 13:31:43 +0000 (+0200) Subject: lslogins: check errno after strto..() X-Git-Tag: v2.38-rc1~407 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2fc2bb7ebd30b25403447fea63dd5f7e69652f44;p=thirdparty%2Futil-linux.git lslogins: check errno after strto..() Addresses: https://github.com/karelzak/util-linux/issues/1356 Signed-off-by: Karel Zak --- 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; }