Commit 501cbc71 by Michel Normand Committed by Daniel Lezcano

report error if statefd parm is not a digit

parent 883a8168
...@@ -230,3 +230,23 @@ extern char **lxc_arguments_dup(const char *file, struct lxc_arguments *args) ...@@ -230,3 +230,23 @@ extern char **lxc_arguments_dup(const char *file, struct lxc_arguments *args)
return argv; return argv;
} }
int lxc_arguments_str_to_int(struct lxc_arguments *args, const char *str)
{
long val;
char *endptr;
errno = 0;
val = strtol(str, &endptr, 10);
if (errno) {
lxc_error(args, "invalid statefd '%s' : %m", str);
return -1;
}
if (*endptr) {
lxc_error(args, "invalid digit for statefd '%s'", str);
return -1;
}
return (int)val;
}
...@@ -78,6 +78,7 @@ extern int lxc_arguments_parse(struct lxc_arguments *args, ...@@ -78,6 +78,7 @@ extern int lxc_arguments_parse(struct lxc_arguments *args,
int argc, char *const argv[]); int argc, char *const argv[]);
extern char **lxc_arguments_dup(const char *file, struct lxc_arguments *args); extern char **lxc_arguments_dup(const char *file, struct lxc_arguments *args);
extern int lxc_arguments_str_to_int(struct lxc_arguments *args, const char *str);
extern const char *lxc_strerror(int errnum); extern const char *lxc_strerror(int errnum);
......
...@@ -60,15 +60,12 @@ static int my_parser(struct lxc_arguments* args, int c, char* arg) ...@@ -60,15 +60,12 @@ static int my_parser(struct lxc_arguments* args, int c, char* arg)
case 'p': args->flags = LXC_FLAG_PAUSE; break; case 'p': args->flags = LXC_FLAG_PAUSE; break;
case 'S': args->statefile = arg; break; case 'S': args->statefile = arg; break;
case 'd': { case 'd': {
long val; int fd;
errno = 0; fd = lxc_arguments_str_to_int(args, arg);
val = strtol(arg, (char **)NULL, 10); if (fd < 0)
if (errno) {
lxc_error(args, "invalid statefd '%s' : %m\n",
arg);
return -1; return -1;
}
args->statefd = (int)val; args->statefd = fd;
break; break;
} }
} }
......
...@@ -63,15 +63,12 @@ static int my_parser(struct lxc_arguments* args, int c, char* arg) ...@@ -63,15 +63,12 @@ static int my_parser(struct lxc_arguments* args, int c, char* arg)
case 'p': args->flags = LXC_FLAG_PAUSE; break; case 'p': args->flags = LXC_FLAG_PAUSE; break;
case 's': return lxc_config_define_add(&defines, arg); case 's': return lxc_config_define_add(&defines, arg);
case 'd': { case 'd': {
long val; int fd;
errno = 0; fd = lxc_arguments_str_to_int(args, arg);
val = strtol(arg, (char **)NULL, 10); if (fd < 0)
if (errno) {
lxc_error(args, "invalid statefd '%s' : %m\n",
arg);
return -1; return -1;
}
args->statefd = (int)val; args->statefd = fd;
break; break;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment