deal with missing argv

A user reported that fish was dying from a SIGSEGV when launched by the
sjterm terminal app. This was traced to a bug in sjterm passing an empty
argv array to the shell. Which, while technically legal, is very unusual
and a bad practice.

Fixes #3269
This commit is contained in:
Kurtis Rader 2016-07-27 16:35:33 -07:00
parent 49008d7a1c
commit 375de96016

View file

@ -451,6 +451,12 @@ int main(int argc, char **argv) {
// struct stat tmp; // struct stat tmp;
// stat("----------FISH_HIT_MAIN----------", &tmp); // stat("----------FISH_HIT_MAIN----------", &tmp);
if (!argv[0]) {
static const char *dummy_argv[2] = {"fish", NULL};
argv = (char **)dummy_argv; //!OCLINT(parameter reassignment)
argc = 1; //!OCLINT(parameter reassignment)
debug(0, _(L"I don't know my program name (no argv), using \"%s\""), argv[0]);
}
std::vector<std::string> cmds; std::vector<std::string> cmds;
my_optind = fish_parse_opt(argc, argv, &cmds); my_optind = fish_parse_opt(argc, argv, &cmds);