Ticket #4103: mc-4103-cid-treestore.c-fix-copy-into-fixed-size-buffer-warning.patch

File mc-4103-cid-treestore.c-fix-copy-into-fixed-size-buffer-warning.patch, 1.3 KB (added by and, 3 years ago)
  • src/filemanager/treestore.c

    From 54dc86f4f09f772a14f4861f38d5bae26bf5c28d Mon Sep 17 00:00:00 2001
    From: Andreas Mohr <and@gmx.li>
    Date: Mon, 21 Dec 2020 18:11:39 +0000
    Subject: [PATCH] (treestore.c) fix copy-into-fixed-size-buffer warning
    
    Additional ignore common value greater than oldname maxsize
    
    found by Coverity
    coverity id #32616
    
    Signed-off-by: Andreas Mohr <and@gmx.li>
    ---
     src/filemanager/treestore.c | 5 +++--
     1 file changed, 3 insertions(+), 2 deletions(-)
    
    diff --git a/src/filemanager/treestore.c b/src/filemanager/treestore.c
    index 08354b217..630df628f 100644
    a b tree_store_load_from (const char *name) 
    264264 
    265265                    common = atoi (s); 
    266266                    different = strtok (NULL, ""); 
    267                     if (different != NULL) 
     267                    if (different != NULL && common < MC_MAXPATHLEN) 
    268268                    { 
    269269                        vfs_path_t *vpath; 
    270270 
    271271                        vpath = vfs_path_from_str (oldname); 
    272                         strcpy (oldname + common, different); 
     272                        strncpy (oldname + common, different, MC_MAXPATHLEN - (size_t) common); 
     273                        oldname[MC_MAXPATHLEN - 1] = '\0'; 
    273274                        if (vfs_file_is_local (vpath)) 
    274275                        { 
    275276                            vfs_path_t *tmp_vpath;