logo

utils-std

Collection of commonly available Unix tools
commit: eb054987dab5a048d2f16ea139b76a2240e78207
parent 4b7d09733e98f47794b356e512e0afaaf942658c
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Thu,  4 Jul 2024 14:19:36 +0200

lib/user_group_parse: Check endptr after strtoul

This is mostly due to glibc not setting EINVAL

Diffstat:

Mlib/user_group_parse.c8++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/lib/user_group_parse.c b/lib/user_group_parse.c @@ -22,10 +22,10 @@ parse_user(char *str, uid_t *user) assert(errno == 0); char *endptr = NULL; - unsigned int id = strtoul(str, &endptr, 0); - if(errno == 0) + unsigned long id = strtoul(str, &endptr, 0); + if(errno == 0 && endptr != NULL && *endptr == '\0') { - *user = id; + *user = (uid_t)id; return 0; } @@ -56,7 +56,7 @@ parse_group(char *str, gid_t *group) assert(errno == 0); char *endptr = NULL; unsigned int id = strtoul(str, &endptr, 0); - if(errno == 0) + if(errno == 0 && endptr != NULL && *endptr == '\0') { *group = id; return 0;