From: "Arkadiusz Miśkiewicz" <arekm@maven.pl>
To: xfs@oss.sgi.com
Subject: [PATCH] Validate string -> number conversion. [version 3]
Date: Fri, 27 Aug 2010 22:54:36 +0200 [thread overview]
Message-ID: <1282942476-5296-1-git-send-email-arekm@maven.pl> (raw)
In-Reply-To: <20100826082612.GE705@dastard>
Make sure that numbers passed as string will fit into proper
types when doing string->uid_t/gid_t/prid_t conversion.
Signed-off-by: Arkadiusz Miśkiewicz <arekm@maven.pl>
---
libxcmd/input.c | 36 ++++++++++++++++++++++++------------
quota/project.c | 2 +-
2 files changed, 25 insertions(+), 13 deletions(-)
diff --git a/libxcmd/input.c b/libxcmd/input.c
index 1bc0745..d7f29c1 100644
--- a/libxcmd/input.c
+++ b/libxcmd/input.c
@@ -336,16 +336,20 @@ prid_from_string(
char *project)
{
fs_project_t *prj;
- prid_t prid;
+ unsigned long prid_long;
char *sp;
/*
* Allow either a full numeric or a valid projectname, even
* if it starts with a digit.
*/
- prid = (prid_t)strtoul(project, &sp, 10);
- if (*project != '\0' && *sp == '\0')
- return prid;
+ prid_long = strtoul(project, &sp, 10);
+ if (*project != '\0' && *sp == '\0') {
+ if ((prid_long == ULONG_MAX && errno == ERANGE)
+ || (prid_long > (prid_t)-1))
+ return -1;
+ return (prid_t)prid_long;
+ }
prj = getprnam(project);
if (prj)
return prj->pr_prid;
@@ -357,12 +361,16 @@ uid_from_string(
char *user)
{
struct passwd *pwd;
- uid_t uid;
+ unsigned long uid_long;
char *sp;
- uid = (uid_t)strtoul(user, &sp, 10);
- if (sp != user)
- return uid;
+ uid_long = strtoul(user, &sp, 10);
+ if (sp != user) {
+ if ((uid_long == ULONG_MAX && errno == ERANGE)
+ || (uid_long > (uid_t)-1))
+ return -1;
+ return (uid_t)uid_long;
+ }
pwd = getpwnam(user);
if (pwd)
return pwd->pw_uid;
@@ -374,12 +382,16 @@ gid_from_string(
char *group)
{
struct group *grp;
- gid_t gid;
+ unsigned long gid_long;
char *sp;
- gid = (gid_t)strtoul(group, &sp, 10);
- if (sp != group)
- return gid;
+ gid_long = strtoul(group, &sp, 10);
+ if (sp != group) {
+ if ((gid_long == ULONG_MAX && errno == ERANGE)
+ || (gid_long > (gid_t)-1))
+ return -1;
+ return (gid_t)gid_long;
+ }
grp = getgrnam(group);
if (grp)
return grp->gr_gid;
diff --git a/quota/project.c b/quota/project.c
index 1aacddd..e9baadd 100644
--- a/quota/project.c
+++ b/quota/project.c
@@ -331,7 +331,7 @@ project_f(
prid = prid_from_string(argv[optind]);
if (prid == -1) {
exitcode = 1;
- fprintf(stderr, _("%s - no such project in %s\n"),
+ fprintf(stderr, _("%s - no such project in %s or invalid project number\n"),
argv[optind], projects_file);
} else
project(argv[optind], type);
--
1.7.2.2
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
next prev parent reply other threads:[~2010-08-27 20:54 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-08-25 8:22 [PATCH] Validate string -> number conversion Arkadiusz Miśkiewicz
2010-08-25 8:45 ` Arkadiusz Miskiewicz
2010-08-25 9:01 ` Arkadiusz Miskiewicz
2010-08-26 8:42 ` Dave Chinner
2010-08-27 22:31 ` [PATCH] xfstests: Quota project id setting overflow Arkadiusz Miśkiewicz
2010-08-26 7:30 ` [PATCH] Validate string -> number conversion Arkadiusz Miśkiewicz
2010-08-26 8:26 ` Dave Chinner
2010-08-27 20:54 ` Arkadiusz Miśkiewicz [this message]
2010-08-27 21:32 ` [PATCH] Validate string -> number conversion. [version 3] Alex Elder
2010-09-01 10:19 ` Christoph Hellwig
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1282942476-5296-1-git-send-email-arekm@maven.pl \
--to=arekm@maven.pl \
--cc=xfs@oss.sgi.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox