lslogins: check errno after strto..()

Addresses: https://github.com/karelzak/util-linux/issues/1356
Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
Karel Zak 2021-06-21 15:31:43 +02:00
parent b2db509d13
commit 21ef212a58
1 changed files with 5 additions and 2 deletions

View File

@ -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;
}