Merge branch '3606_shell_segfault'

* 3606_shell_segfault:
  (mc_shell_recognize_path): clarify duplicate comments
  Ticket #3606: fix segfault due to incorrect value of SHELL environment variable.
This commit is contained in:
Andrew Borodin 2016-03-17 09:24:45 +03:00
commit 787cea240f

View File

@ -136,18 +136,10 @@ mc_shell_get_from_env (void)
} }
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
/**
* Get a shell type and store in mc_shell->type variable
*/
static gboolean static void
mc_shell_recognize_and_fill_type (mc_shell_t * mc_shell) mc_shell_recognize_real_path (mc_shell_t * mc_shell)
{ {
gboolean result = TRUE;
/* Find out what type of shell we have. Also consider real paths (resolved symlinks)
* because e.g. csh might point to tcsh, ash to dash or busybox, sh to anything. */
if (strstr (mc_shell->path, "/zsh") != NULL || strstr (mc_shell->real_path, "/zsh") != NULL if (strstr (mc_shell->path, "/zsh") != NULL || strstr (mc_shell->real_path, "/zsh") != NULL
|| getenv ("ZSH_VERSION") != NULL) || getenv ("ZSH_VERSION") != NULL)
{ {
@ -187,31 +179,33 @@ mc_shell_recognize_and_fill_type (mc_shell_t * mc_shell)
mc_shell->type = SHELL_ASH_BUSYBOX; mc_shell->type = SHELL_ASH_BUSYBOX;
mc_shell->name = mc_shell->path; mc_shell->name = mc_shell->path;
} }
else if (strstr (mc_shell->path, "/bash") != NULL || getenv ("BASH") != NULL) else
mc_shell->type = SHELL_NONE;
}
/* --------------------------------------------------------------------------------------------- */
static void
mc_shell_recognize_path (mc_shell_t * mc_shell)
{
/* If shell is not symlinked to busybox, it is safe to assume it is a real shell */
if (strstr (mc_shell->path, "/bash") != NULL || getenv ("BASH") != NULL)
{ {
/* If bash is not symlinked to busybox, it is safe to assume it is a real bash */
mc_shell->type = SHELL_BASH; mc_shell->type = SHELL_BASH;
mc_shell->name = "bash"; mc_shell->name = "bash";
} }
else if (strstr (mc_shell->path, "/sh") != NULL || getenv ("SH") != NULL) else if (strstr (mc_shell->path, "/sh") != NULL || getenv ("SH") != NULL)
{ {
/* If bash is not symlinked to busybox, it is safe to assume it is a real bash */
mc_shell->type = SHELL_SH; mc_shell->type = SHELL_SH;
mc_shell->name = "sh"; mc_shell->name = "sh";
} }
else if (strstr (mc_shell->path, "/ash") != NULL || getenv ("ASH") != NULL) else if (strstr (mc_shell->path, "/ash") != NULL || getenv ("ASH") != NULL)
{ {
/* If bash is not symlinked to busybox, it is safe to assume it is a real bash */
mc_shell->type = SHELL_ASH_BUSYBOX; mc_shell->type = SHELL_ASH_BUSYBOX;
mc_shell->name = "ash"; mc_shell->name = "ash";
} }
else else
{
mc_shell->type = SHELL_NONE; mc_shell->type = SHELL_NONE;
mc_global.tty.use_subshell = FALSE;
result = FALSE;
}
return result;
} }
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
@ -230,9 +224,16 @@ mc_shell_init (void)
mc_shell->real_path = mc_realpath (mc_shell->path, rp_shell); mc_shell->real_path = mc_realpath (mc_shell->path, rp_shell);
if (!mc_shell_recognize_and_fill_type (mc_shell)) /* Find out what type of shell we have. Also consider real paths (resolved symlinks)
mc_global.tty.use_subshell = FALSE; * because e.g. csh might point to tcsh, ash to dash or busybox, sh to anything. */
if (mc_shell->real_path != NULL)
mc_shell_recognize_real_path (mc_shell);
if (mc_shell->type == SHELL_NONE)
mc_shell_recognize_path (mc_shell);
mc_global.tty.use_subshell = mc_shell->type != SHELL_NONE;
mc_global.shell = mc_shell; mc_global.shell = mc_shell;
} }