Ticket #2942: mc-2942-external-panelize-fix-absolute-path-result.patch

File mc-2942-external-panelize-fix-absolute-path-result.patch, 2.6 KB (added by and, 9 years ago)
  • src/filemanager/panelize.c

    From 52aff731d74c2ea8785fb3b6840068202365c45e Mon Sep 17 00:00:00 2001
    From: Andreas Mohr <and@gmx.li>
    Date: Sat, 5 Mar 2016 12:13:06 +0000
    Subject: [PATCH] External panelize: Fix absolute path result usage
    
    Fix absolute paths result usage, before list[0] was checked but
    it was always ".." from dir_list_init()
    so never absolute path result was detected.
    
    Bug #2942 reported by ackalker.
    
    - sanity: access line[1] only if string is long enough
    - tweak: use strlen() once only for speed-up
    - cleanup: remove unneeded list->len check because list is always init
    - cleanup: remove unchecked ret value from mc_chdir()
    - cleanup: remove unused LABELS macro
    - hint: add external panelize expected absolute _or_ relative results hint
    
    Signed-off-by: Andreas Mohr <and@gmx.li>
    ---
     src/filemanager/panelize.c | 24 ++++++++++++------------
     1 file changed, 12 insertions(+), 12 deletions(-)
    
    diff --git a/src/filemanager/panelize.c b/src/filemanager/panelize.c
    index 8050244..42352cd 100644
    a b  
    6363#define UX 3 
    6464#define UY 2 
    6565 
    66 #define LABELS   3 
    6766#define B_ADD    B_USER 
    6867#define B_REMOVE (B_USER + 1) 
    6968 
    do_external_panelize (char *command) 
    333332 
    334333    while (TRUE) 
    335334    { 
     335        size_t len; 
     336 
    336337        clearerr (external); 
    337338        if (fgets (line, sizeof (line), external) == NULL) 
    338339        { 
    do_external_panelize (char *command) 
    341342            else 
    342343                break; 
    343344        } 
    344         if (line[strlen (line) - 1] == '\n') 
    345             line[strlen (line) - 1] = 0; 
    346         if (strlen (line) < 1) 
     345 
     346        len = strlen (line); 
     347 
     348        if (line[len - 1] == '\n') 
     349            line[len - 1] = 0; 
     350        if (len < 1) 
    347351            continue; 
    348         if (line[0] == '.' && IS_PATH_SEP (line[1])) 
     352        if (len > 1 && line[0] == '.' && IS_PATH_SEP (line[1])) 
    349353            name = line + 2; 
    350354        else 
    351355            name = line; 
    do_external_panelize (char *command) 
    364368 
    365369    current_panel->is_panelized = TRUE; 
    366370 
    367     if (list->len == 0) 
    368         dir_list_init (list); 
    369     else if (IS_PATH_SEP (list->list[0].fname[0])) 
     371    /* HINT: mixed absolute and relative paths result not supported */ 
     372    if (list->len > 1 && IS_PATH_SEP (list->list[1].fname[0])) 
    370373    { 
    371374        vfs_path_t *vpath_root; 
    372         int ret; 
    373375 
    374376        vpath_root = vfs_path_from_str (PATH_SEP_STR); 
    375377        panel_set_cwd (current_panel, vpath_root); 
    376         ret = mc_chdir (vpath_root); 
     378        (void) mc_chdir (vpath_root); 
    377379        vfs_path_free (vpath_root); 
    378  
    379         (void) ret; 
    380380    } 
    381381 
    382382    if (pclose (external) < 0)