Skip to content

Commit

Permalink
mxqsub: Improve user input verification
Browse files Browse the repository at this point in the history
  • Loading branch information
mariux committed May 21, 2015
1 parent 61b2f09 commit 48c63c0
Showing 1 changed file with 35 additions and 13 deletions.
48 changes: 35 additions & 13 deletions mxqsub.c
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@ int main(int argc, char *argv[])

struct passwd *passwd;
struct group *grp;
char *p;

int opt;
struct mx_getopt_ctl optctl;
Expand Down Expand Up @@ -504,19 +505,28 @@ int main(int argc, char *argv[])
break;

case 1:
mx_log_warning("option --group_id is deprecated. please use --group-name instead.");
case 3:
if (opt == 3)
mx_log_warning("option --group-id is deprecated (usage will change in next version). Using --group-name instead.");
else
mx_log_warning("option --group_id is deprecated. Using --group-name instead.");
case 'N':
if (!(*optctl.optarg)) {
mx_log_crit("--group-name '%s': String is empty.", optctl.optarg);
exit(EX_CONFIG);
}
arg_group_name = optctl.optarg;
break;

case 'a':
if (*optctl.optarg) {
char *p;
arg_program_name = optctl.optarg;
p = strchr(arg_program_name, ' ');
if (p)
*p = 0;
p = strchr(optctl.optarg, ' ');
if (p)
*p = 0;
if (!(*optctl.optarg)) {
mx_log_crit("--command-alias '%s': String is empty.", optctl.optarg);
exit(EX_CONFIG);
}
arg_program_name = optctl.optarg;
break;

case 2:
Expand All @@ -528,11 +538,6 @@ int main(int argc, char *argv[])
}
break;

case 3:
mx_log_warning("option --group-id is deprecated (usage will change in next version). please use --group-name instead.");
arg_group_name = optctl.optarg;
break;

case 'j':
if (mx_strtou16(optctl.optarg, &arg_threads) < 0) {
mx_log_crit("--threads '%s': %m", optctl.optarg);
Expand All @@ -557,6 +562,10 @@ int main(int argc, char *argv[])
break;

case 'w':
if (!(*optctl.optarg)) {
mx_log_crit("--workdir '%s': String is empty.", optctl.optarg);
exit(EX_CONFIG);
}
if (optctl.optarg[0] != '/') {
mx_log_crit("--workdir '%s': workdir is a relativ path. please use absolute path.",
optctl.optarg);
Expand All @@ -566,10 +575,18 @@ int main(int argc, char *argv[])
break;

case 'o':
if (!(*optctl.optarg)) {
mx_log_crit("--stdout '%s': String is empty.", optctl.optarg);
exit(EX_CONFIG);
}
arg_stdout = optctl.optarg;
break;

case 'e':
if (!(*optctl.optarg)) {
mx_log_crit("--stderr '%s': String is empty.", optctl.optarg);
exit(EX_CONFIG);
}
arg_stderr = optctl.optarg;
break;

Expand Down Expand Up @@ -602,6 +619,11 @@ int main(int argc, char *argv[])
if (!arg_program_name)
arg_program_name = argv[0];

if (!(*arg_program_name)) {
mx_log_crit("<command> is empty. Please check usage with '%s --help'.", program_invocation_short_name);
exit(EX_CONFIG);
}

/******************************************************************/

if (*arg_stdout != '/') {
Expand Down Expand Up @@ -681,7 +703,7 @@ int main(int argc, char *argv[])
mx_mysql_option_set_default_file(mysql, arg_mysql_default_file);
mx_mysql_option_set_default_group(mysql, arg_mysql_default_group);

res = mx_mysql_connect(&mysql);
res = mx_mysql_connect_forever(&mysql);
assert(res == 0);

res = mxq_submit_task(mysql, &job, flags);
Expand Down

0 comments on commit 48c63c0

Please sign in to comment.