Ticket #3547: mc-3547-invalid-command-line-options-cause-segfault.patch

File mc-3547-invalid-command-line-options-cause-segfault.patch, 1.7 KB (added by mooffie, 7 years ago)
  • lib/shell.c

    From af30d8fc59186963c309a1c91190543e1d00dc0c Mon Sep 17 00:00:00 2001
    From: Mooffie <mooffie@gmail.com>
    Date: Mon, 14 Dec 2015 23:06:07 +0200
    Subject: [PATCH] Invalid command-line options cause segfault.
    
    That's because main() calls mc_shell_deinit() without mc_shell_init()
    having been called.
    
    Solution: we make mc_shell_deinit() not crash when mc_global.shell ==
    NULL.
    
    (The use of MC_PTR_FREE there is just a matter of style -- it's not part
    of the solution.)
    
    The patch also moves the call to mc_shell_deinit() past
    'startup_exit_ok:'. This is obviously the intended design.
    'startup_exit_falure:' is just meant to print mcerror.
    ---
     lib/shell.c | 7 +++++--
     src/main.c  | 3 +--
     2 files changed, 6 insertions(+), 4 deletions(-)
    
    diff --git a/lib/shell.c b/lib/shell.c
    index 5159909..3d9ba2e 100644
    a b mc_shell_init (void) 
    243243void 
    244244mc_shell_deinit (void) 
    245245{ 
    246     g_free (mc_global.shell->path); 
    247     g_free (mc_global.shell); 
     246    if (mc_global.shell != NULL) 
     247    { 
     248        g_free (mc_global.shell->path); 
     249        MC_PTR_FREE (mc_global.shell); 
     250    } 
    248251} 
    249252 
    250253/* --------------------------------------------------------------------------------------------- */ 
  • src/main.c

    diff --git a/src/main.c b/src/main.c
    index aec94c4..4e6503c 100644
    a b main (int argc, char *argv[]) 
    244244      startup_exit_falure: 
    245245        fprintf (stderr, _("Failed to run:\n%s\n"), mcerror->message); 
    246246        g_error_free (mcerror); 
    247  
    248         mc_shell_deinit (); 
    249247      startup_exit_ok: 
     248        mc_shell_deinit (); 
    250249        str_uninit_strings (); 
    251250        mc_timer_destroy (mc_global.timer); 
    252251        return exit_code;