strtoul function return a 64bits value on a 64bits system, so an
overflow occurs when we store user value into a quota/project
structure.
This commit apply the same 32 bits verification for "lfs" project,
quota,setquota and find commands on uid, gid and project id arguments.
Signed-off-by: Etienne AUJAMES <eaujames@ddn.com>
Change-Id: I809e9ac55d4bc676c20b18c6c198a69eaba9cff6
Reviewed-on: https://review.whamcloud.com/38938
Reviewed-by: Wang Shilong <wshilong@whamcloud.com>
Tested-by: jenkins <devops@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
+static int str2quotaid(__u32 *id, const char *arg)
+{
+ unsigned long int projid_tmp = 0;
+ char *endptr = NULL;
+
+ projid_tmp = strtoul(arg, &endptr, 10);
+ if (*endptr != '\0')
+ return -EINVAL;
+ if (projid_tmp > UINT32_MAX ||
+ (projid_tmp == ULONG_MAX && (errno == ERANGE)))
+ return -ERANGE;
+
+ *id = projid_tmp;
+ return 0;
+}
+
static int name2uid(unsigned int *id, const char *name)
{
struct passwd *passwd;
static int name2uid(unsigned int *id, const char *name)
{
struct passwd *passwd;
case 'G':
rc = name2gid(¶m.fp_gid, optarg);
if (rc) {
case 'G':
rc = name2gid(¶m.fp_gid, optarg);
if (rc) {
- param.fp_gid = strtoul(optarg, &endptr, 10);
- if (*endptr != '\0') {
+ if (str2quotaid(¶m.fp_gid, optarg)) {
fprintf(stderr,
"Group/GID: %s cannot be found.\n",
optarg);
fprintf(stderr,
"Group/GID: %s cannot be found.\n",
optarg);
case 'U':
rc = name2uid(¶m.fp_uid, optarg);
if (rc) {
case 'U':
rc = name2uid(¶m.fp_uid, optarg);
if (rc) {
- param.fp_uid = strtoul(optarg, &endptr, 10);
- if (*endptr != '\0') {
+ if (str2quotaid(¶m.fp_uid, optarg)) {
fprintf(stderr,
"User/UID: %s cannot be found.\n",
optarg);
fprintf(stderr,
"User/UID: %s cannot be found.\n",
optarg);
case LFS_PROJID_OPT:
rc = name2projid(¶m.fp_projid, optarg);
if (rc) {
case LFS_PROJID_OPT:
rc = name2projid(¶m.fp_projid, optarg);
if (rc) {
- param.fp_projid = strtoul(optarg, &endptr, 10);
- if (*endptr != '\0') {
+ if (str2quotaid(¶m.fp_projid, optarg)) {
- "Invalid project ID: %s",
+ "Invalid project ID: %s\n",
optarg);
ret = -1;
goto err;
optarg);
ret = -1;
goto err;
{ .val = 'o', .name = "pool", .has_arg = required_argument },
{ .name = NULL } };
unsigned int limit_mask = 0;
{ .val = 'o', .name = "pool", .has_arg = required_argument },
{ .name = NULL } };
unsigned int limit_mask = 0;
bool use_default = false;
int qtype, qctl_len;
bool use_default = false;
int qtype, qctl_len;
rc = name2projid(&qctl->qc_id, optarg);
quota_type:
if (rc) {
rc = name2projid(&qctl->qc_id, optarg);
quota_type:
if (rc) {
- qctl->qc_id = strtoul(optarg, &endptr, 10);
- if (*endptr != '\0') {
+ if (str2quotaid(&qctl->qc_id, optarg)) {
fprintf(stderr,
"%s setquota: invalid id '%s'\n",
progname, optarg);
fprintf(stderr,
"%s setquota: invalid id '%s'\n",
progname, optarg);
phc.recursive = true;
break;
case 'p':
phc.recursive = true;
break;
case 'p':
- phc.projid = strtoul(optarg, NULL, 0);
+ if (str2quotaid(&phc.projid, optarg)) {
+ fprintf(stderr,
+ "Invalid project ID: %s\n",
+ optarg);
+ return CMD_HELP;
+ }
+
phc.assign_projid = true;
break;
phc.assign_projid = true;
break;
struct if_quotactl *qctl;
char *obd_uuid;
int rc = 0, rc1 = 0, verbose = 0, quiet = 0;
struct if_quotactl *qctl;
char *obd_uuid;
int rc = 0, rc1 = 0, verbose = 0, quiet = 0;
__u32 valid = QC_GENERAL, idx = 0;
bool human_readable = false;
bool show_default = false;
__u32 valid = QC_GENERAL, idx = 0;
bool human_readable = false;
bool show_default = false;
- qctl->qc_id = strtoul(name, &endptr, 10);
- if (*endptr != '\0') {
+ if (str2quotaid(&qctl->qc_id, name)) {
fprintf(stderr, "%s quota: invalid id '%s'\n",
progname, name);
rc = CMD_HELP;
fprintf(stderr, "%s quota: invalid id '%s'\n",
progname, name);
rc = CMD_HELP;