Ticket #3955: mc-3955-direntry.c-cleanup-null-dereference-warning.patch

File mc-3955-direntry.c-cleanup-null-dereference-warning.patch, 3.7 KB (added by and, 2 months ago)
  • lib/vfs/direntry.c

    From 10c2fb0fe14972828fcdf740ff159c8668315ccf Mon Sep 17 00:00:00 2001
    From: Andreas Mohr <and@gmx.li>
    Date: Sun, 6 Jan 2019 10:29:47 +0000
    Subject: [PATCH] direntry.c: cleanup -Wnull-dereference warning
    
    Found by GCC8
    
    direntry.c:918:21: error: potential null pointer dereference [-Werror=null-dereference]
         entry->ino->ent = entry;
         ~~~~~~~~~~~~~~~~^~~~~~~
    direntry.c:1276:36: error: potential null pointer dereference [-Werror=null-dereference]
             if ((VFSDATA (path_element)->flags & VFS_S_USETMP) != 0)
    direntry.c:1334:32: error: potential null pointer dereference [-Werror=null-dereference]
         if ((VFSDATA (path_element)->flags & VFS_S_USETMP) != 0 && fh->ino->localname != NULL)
    direntry.c:1314:35: error: potential null pointer dereference [-Werror=null-dereference]
             if (VFSDATA (path_element)->linear_start != NULL)
    direntry.c:1325:14: error: potential null pointer dereference [-Werror=null-dereference]
             if (s->fh_open != NULL && s->fh_open (path_element->class, fh, flags, mode) != 0)
                 ~^~~~~~~~~
    
    Signed-off-by: Andreas Mohr <and@gmx.li>
    ---
     lib/vfs/direntry.c | 18 ++++++++++--------
     1 file changed, 10 insertions(+), 8 deletions(-)
    
    diff --git a/lib/vfs/direntry.c b/lib/vfs/direntry.c
    index 48a5b760c..bfcfa7354 100644
    a b vfs_s_new_entry (struct vfs_class *me, const char *name, struct vfs_s_inode *ino 
    914914    entry = g_new0 (struct vfs_s_entry, 1); 
    915915 
    916916    entry->name = g_strdup (name); 
     917 
    917918    entry->ino = inode; 
    918     entry->ino->ent = entry; 
     919    if (entry->ino != NULL) 
     920        entry->ino->ent = entry; 
    919921    CALL (init_entry) (me, entry); 
    920922 
    921923    return entry; 
    vfs_s_open (const vfs_path_t * vpath, int flags, mode_t mode) 
    12371239    const char *q; 
    12381240    struct vfs_s_inode *ino; 
    12391241    const vfs_path_element_t *path_element; 
     1242    struct vfs_s_subclass *s; 
    12401243 
    12411244    path_element = vfs_path_get_by_index (vpath, -1); 
    12421245 
    vfs_s_open (const vfs_path_t * vpath, int flags, mode_t mode) 
    12731276        ent = vfs_s_generate_entry (path_element->class, name, dir, 0755); 
    12741277        ino = ent->ino; 
    12751278        vfs_s_insert_entry (path_element->class, dir, ent); 
    1276         if ((VFSDATA (path_element)->flags & VFS_S_USETMP) != 0) 
     1279        s = VFSDATA (path_element); 
     1280        if (s != NULL && (s->flags & VFS_S_USETMP) != 0) 
    12771281        { 
    12781282            int tmp_handle; 
    12791283            vfs_path_t *tmp_vpath; 
    vfs_s_open (const vfs_path_t * vpath, int flags, mode_t mode) 
    13091313    fh->linear = LS_NOT_LINEAR; 
    13101314    fh->data = NULL; 
    13111315 
     1316    s = VFSDATA (path_element); 
    13121317    if (IS_LINEAR (flags)) 
    13131318    { 
    1314         if (VFSDATA (path_element)->linear_start != NULL) 
     1319        if (s != NULL && s->linear_start != NULL) 
    13151320        { 
    13161321            vfs_print_message ("%s", _("Starting linear transfer...")); 
    13171322            fh->linear = LS_LINEAR_PREOPEN; 
    vfs_s_open (const vfs_path_t * vpath, int flags, mode_t mode) 
    13191324    } 
    13201325    else 
    13211326    { 
    1322         struct vfs_s_subclass *s; 
    1323  
    1324         s = VFSDATA (path_element); 
    1325         if (s->fh_open != NULL && s->fh_open (path_element->class, fh, flags, mode) != 0) 
     1327        if (s != NULL && s->fh_open != NULL && s->fh_open (path_element->class, fh, flags, mode) != 0) 
    13261328        { 
    13271329            if (s->fh_free_data != NULL) 
    13281330                s->fh_free_data (fh); 
    vfs_s_open (const vfs_path_t * vpath, int flags, mode_t mode) 
    13311333        } 
    13321334    } 
    13331335 
    1334     if ((VFSDATA (path_element)->flags & VFS_S_USETMP) != 0 && fh->ino->localname != NULL) 
     1336    if (s != NULL && (s->flags & VFS_S_USETMP) != 0 && fh->ino->localname != NULL) 
    13351337    { 
    13361338        fh->handle = open (fh->ino->localname, NO_LINEAR (flags), mode); 
    13371339        if (fh->handle == -1)