]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfsprogs: xfs_quota allow user or group names beginning with digits
authorRich Johnston <rjohnston@sgi.com>
Mon, 22 Apr 2013 17:32:05 +0000 (17:32 +0000)
committerRich Johnston <rjohnston@sgi.com>
Tue, 23 Apr 2013 12:58:11 +0000 (07:58 -0500)
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 <rjohnston@sgi.com>
Reported-by: James Carter <james.carter@bytemark.co.uk>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Chandra Seetharaman <sekharan@us.ibm.com>
include/input.h
libxcmd/input.c
quota/quota.c
quota/quota.h

index b2279835ca580ae8a403d285e3567e3a777d3181..61b40c846ce2be93287ed2da3c035a4ec5982c59 100644 (file)
@@ -22,6 +22,7 @@
 #include <grp.h>
 #include <sys/types.h>
 #include <xfs/project.h>
+#include <stdbool.h>
 
 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 */
 
index b0c13268547b223a0763eee5ca2f004240617952..c06b5b8fd95859c6afb59b94178caaa2ebbb6e93 100644 (file)
@@ -19,6 +19,7 @@
 #include <xfs/xfs.h>
 #include <xfs/input.h>
 #include <ctype.h>
+#include <stdbool.h>
 
 #if defined(ENABLE_READLINE)
 # include <readline/history.h>
@@ -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
index 3fba055c9e31bed492a8a07e556c66f3bba36bcf..7e52ad2280d158bb5a59d356d24b0ef6fb37f90f 100644 (file)
@@ -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))) {
index 78f21645f901567446d58fe5fa76db42df68d140..618bb49eca71620f5c8a039ca12f0d837ca46831 100644 (file)
@@ -19,6 +19,7 @@
 #include <xfs/xqm.h>
 #include <xfs/path.h>
 #include <xfs/project.h>
+#include <stdbool.h>
 
 /*
  * 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 *);