return res;
}
+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;
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);
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);
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)) {
fprintf(stderr,
- "Invalid project ID: %s",
+ "Invalid project ID: %s\n",
optarg);
ret = -1;
goto err;
{ .val = 'o', .name = "pool", .has_arg = required_argument },
{ .name = NULL } };
unsigned int limit_mask = 0;
- char *endptr;
bool use_default = false;
int qtype, qctl_len;
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);
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;
struct if_quotactl *qctl;
char *obd_uuid;
int rc = 0, rc1 = 0, verbose = 0, quiet = 0;
- char *endptr;
__u32 valid = QC_GENERAL, idx = 0;
bool human_readable = false;
bool show_default = false;
}
if (rc) {
- 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;