Skip to contentSkip to conversation

xfsprogs: xfs_quota allow user or group names beginning with

PATCH In review [email protected] 2 participants 2 messages Apr 22, 2013

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 xfsprogs: xfs_quota allow user or group names beginning with

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.

---

Fresh clone of xfsprogs showed I missed a change in quota_proj_type() (Thanks Chandra pointing that out)

V2:
Change 'i=0' to 'i = 0' (sandeen suggestion)
Use bool instead of boolean_t (dchinner suggestion)
V3:
Also change quota_proj_type() to use isdigits_only() (sekharan suggestion)

 include/input.h |    2 ++
 libxcmd/input.c |   13 +++++++++++++
 quota/quota.c   |    6 +++---
 quota/quota.h   |    2 ++
 4 files changed, 20 insertions(+), 3 deletions(-)
include/input.h +2 -0
Index: b/include/input.h
===================================================================
@@ -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,
 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 */
 
libxcmd/input.c +13 -0
Index: b/libxcmd/input.c
===================================================================
@@ -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
quota/quota.c +3 -3
Index: 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))) {
quota/quota.h +2 -0
Index: b/quota/quota.h
===================================================================
@@ -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 *);
 

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

Reviewed-by on v3 1/1
#1 lore raw
Quoted 5 lines · On Mon, 2013-04-22 at 12:32 -0500, [email protected] wrote:

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.

Quoted 120 lines

---

Fresh clone of xfsprogs showed I missed a change in quota_proj_type() (Thanks Chandra pointing that out)

V2:
Change 'i=0' to 'i = 0' (sandeen suggestion)
Use bool instead of boolean_t (dchinner suggestion)
V3:
Also change quota_proj_type() to use isdigits_only() (sekharan suggestion)

 include/input.h |    2 ++
 libxcmd/input.c |   13 +++++++++++++
 quota/quota.c   |    6 +++---
 quota/quota.h   |    2 ++
 4 files changed, 20 insertions(+), 3 deletions(-)

Index: b/include/input.h
===================================================================

include/input.h +2 -0
@@ -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,
 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: b/libxcmd/input.c
===================================================================

libxcmd/input.c +13 -0
@@ -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: b/quota/quota.c
===================================================================

quota/quota.c +3 -3
@@ -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: b/quota/quota.h
===================================================================

quota/quota.h +2 -0
@@ -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 *);
 
Quoted 5 lines

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs