Skip to content

Commit

Permalink
hydra: fix segfaults in argument parsing
Browse files Browse the repository at this point in the history
Add checks for missing argument. As a TODO, we should enhance the error
reporting to make it more user friendly. But we should prevent segfault
for now at least.
  • Loading branch information
hzhou committed Oct 12, 2021
1 parent 1e783d7 commit 702cca7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/pm/hydra/ui/mpich/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ static char **config_argv = NULL;
static int reading_config_file = 0;
static struct HYD_arg_match_table match_table[];

#define ASSERT_ARGV \
do { \
if (!**argv) { \
status = HYD_FAILURE; \
HYDU_ERR_POP(status, "missing command line argument, add -h for help\n"); \
}\
} while (0)

static void init_ui_mpich_info(void)
{
HYD_ui_mpich_info.ppn = -1;
Expand Down Expand Up @@ -777,6 +785,7 @@ static HYD_status np_fn(char *arg, char ***argv)
status = get_current_exec(&exec);
HYDU_ERR_POP(status, "get_current_exec returned error\n");

ASSERT_ARGV;
status = HYDU_set_int(arg, &exec->proc_count, atoi(**argv));
HYDU_ERR_POP(status, "error getting executable process count\n");

Expand Down
4 changes: 4 additions & 0 deletions src/pm/hydra/utils/alloc/alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,10 @@ HYD_status HYDU_create_proxy_list(struct HYD_exec *exec_list, struct HYD_node *n
pg->proxy_list->next = NULL;
HYDU_free_proxy_list(pg->proxy_list);
pg->proxy_list = tmp;
if (pg->proxy_list == NULL) {
status = HYD_FAILURE;
HYDU_ERR_POP(status, "Missing executable.\n");
}
}
for (proxy = pg->proxy_list; proxy->next;) {
if (proxy->next->exec_list == NULL) {
Expand Down

0 comments on commit 702cca7

Please sign in to comment.