~emersion/mrsh

1738e41b2a35e5f99b9a1300a5f687478458226a — Haz 4 months ago 1558d22
Fix segfault when calling `mrsh -o`

* at main.c we call mrsh_process_args from builtins/set.c
* that function calls set function impl. in the same file.
* set function returns early in its switch block commandline arg `-o`
  when called without a long option.
* this might be the desired behaviour, but it skips populating
  state->frame
* the code responsible for that is after the switch statement
* add a jump to handle this case
1 files changed, 4 insertions(+), 2 deletions(-)

M builtin/set.c
M builtin/set.c => builtin/set.c +4 -2
@@ 135,7 135,7 @@ static int set(struct mrsh_state *state, int argc, char *argv[],
		case 'o':
			if (i + 1 == argc) {
				print_options(state);
				return 0;
				goto out; // we must populate state->argv
			}
			option = find_long_option(argv[i + 1]);
			if (!option) {


@@ 199,7 199,9 @@ static int set(struct mrsh_state *state, int argc, char *argv[],
		argv_free(state->frame->argc, state->frame->argv);
		state->frame->argc = argc - i + 1;
		state->frame->argv = argv_dup(argv_0, state->frame->argc, &argv[i]);
	} else if (init_args != NULL) {
	} else
out:
	  if (init_args != NULL) {
		// No args given, but we need to initialize state->argv
		state->frame->argc = 1;
		state->frame->argv = argv_dup(strdup(argv[0]), 1, argv);