From: Karel Zak Date: Mon, 21 Jun 2021 13:31:43 +0000 (+0200) Subject: lslogins: check errno after strto..() X-Git-Tag: v2.37.1~52 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=21ef212a586bb4c4d243d53d49ad2233064919ff;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; }