Ticket #4179: mc-4179-cid-background.c-fix-argument-cannot-be-negative.patch

File mc-4179-cid-background.c-fix-argument-cannot-be-negative.patch, 1.9 KB (added by and, 12 months ago)
  • src/background.c

    From 951d3a804936bef13e11853cb598010666f59fa5 Mon Sep 17 00:00:00 2001
    From: Andreas Mohr <and@gmx.li>
    Date: Tue, 18 May 2021 15:14:16 +0000
    Subject: [PATCH] (background.c) fix argument cannot be negative
    
    Fix argument cannot be negative
    
    Found by Coverity
    Coverity id #32593
    
    Signed-off-by: Andreas Mohr <and@gmx.li>
    ---
     src/background.c | 21 ++++++++++++++-------
     1 file changed, 14 insertions(+), 7 deletions(-)
    
    diff --git a/src/background.c b/src/background.c
    index 584cd74ef..66b7c3d37 100644
    a b background_attention (int fd, void *closure) 
    332332            } 
    333333 
    334334        /* Send the result code and the value for shared variables */ 
    335         ret = write (to_child_fd, &result, sizeof (result)); 
    336         if (have_ctx != 0 && to_child_fd != -1) 
    337             ret = write (to_child_fd, ctx, sizeof (*ctx)); 
     335        if (to_child_fd != -1) 
     336        { 
     337            ret = write (to_child_fd, &result, sizeof (result)); 
     338            if (have_ctx != 0) 
     339                ret = write (to_child_fd, ctx, sizeof (*ctx)); 
     340        } 
    338341    } 
    339342    else if (type == Return_String) 
    340343    { 
    background_attention (int fd, void *closure) 
    368371        if (resstr != NULL) 
    369372        { 
    370373            len = strlen (resstr); 
    371             ret = write (to_child_fd, &len, sizeof (len)); 
    372             if (len != 0) 
    373                 ret = write (to_child_fd, resstr, len); 
     374            if (to_child_fd != -1) 
     375            { 
     376                ret = write (to_child_fd, &len, sizeof (len)); 
     377                if (len != 0) 
     378                    ret = write (to_child_fd, resstr, len); 
     379            } 
    374380            g_free (resstr); 
    375381        } 
    376382        else 
    377383        { 
    378384            len = 0; 
    379             ret = write (to_child_fd, &len, sizeof (len)); 
     385            if (to_child_fd != -1) 
     386                ret = write (to_child_fd, &len, sizeof (len)); 
    380387        } 
    381388    } 
    382389