From: Rich Johnston Date: Mon, 22 Apr 2013 17:32:05 +0000 (+0000) Subject: xfsprogs: xfs_quota allow user or group names beginning with digits X-Git-Tag: v3.1.11~6 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=fd537fc50eeade63bbd2a66105f39d04a011a7f5;p=thirdparty%2Fxfsprogs-dev.git xfsprogs: xfs_quota allow user or group names beginning with digits xfs_quota does not properly parse users or groups that begin with a number. Only call atoi when user or group consists of digits only. Signed-off-by: Rich Johnston Reported-by: James Carter Reviewed-by: Eric Sandeen Reviewed-by: Chandra Seetharaman --- diff --git a/include/input.h b/include/input.h index b2279835c..61b40c846 100644 --- a/include/input.h +++ b/include/input.h @@ -22,6 +22,7 @@ #include #include #include +#include extern char **breakline(char *input, int *count); extern void doneline(char *input, char **vec); @@ -46,6 +47,7 @@ extern void timestr(struct timeval *tv, char *str, size_t sz, int flags); extern uid_t uid_from_string(char *user); extern gid_t gid_from_string(char *group); extern prid_t prid_from_string(char *project); +extern bool isdigits_only(const char *str); #define HAVE_FTW_H 1 /* TODO: configure me */ diff --git a/libxcmd/input.c b/libxcmd/input.c index b0c132685..c06b5b8fd 100644 --- a/libxcmd/input.c +++ b/libxcmd/input.c @@ -19,6 +19,7 @@ #include #include #include +#include #if defined(ENABLE_READLINE) # include @@ -398,6 +399,18 @@ gid_from_string( return -1; } +bool isdigits_only( + const char *str) +{ + int i; + + for (i = 0; i < strlen(str); i++) { + if (!isdigit(str[i])) + return false; + } + return true; +} + #define HAVE_FTW_H 1 /* TODO: configure me */ #ifndef HAVE_FTW_H diff --git a/quota/quota.c b/quota/quota.c index 3fba055c9..7e52ad228 100644 --- a/quota/quota.c +++ b/quota/quota.c @@ -224,7 +224,7 @@ quota_user_type( uid_t id; if (name) { - if (isdigit(name[0])) { + if (isdigits_only(name)) { id = atoi(name); name = getusername(id, flags & NO_LOOKUP_FLAG); } else if ((u = getpwnam(name))) { @@ -273,7 +273,7 @@ quota_group_type( int i, ngroups, dofree = 0; if (name) { - if (isdigit(name[0])) { + if (isdigits_only(name)) { gid = atoi(name); name = getgroupname(gid, flags & NO_LOOKUP_FLAG); } else { @@ -344,7 +344,7 @@ quota_proj_type( return; } - if (isdigit(name[0])) { + if (isdigits_only(name)) { id = atoi(name); name = getprojectname(id, flags & NO_LOOKUP_FLAG); } else if ((p = getprnam(name))) { diff --git a/quota/quota.h b/quota/quota.h index 78f21645f..618bb49ec 100644 --- a/quota/quota.h +++ b/quota/quota.h @@ -19,6 +19,7 @@ #include #include #include +#include /* * Different forms of XFS quota @@ -80,4 +81,5 @@ enum { extern char *uid_to_name(__uint32_t __uid); extern char *gid_to_name(__uint32_t __gid); extern char *prid_to_name(__uint32_t __prid); +extern bool isdigits_only(const char *);