lslebodn / SSSD / sssd

Forked from SSSD/sssd 7 years ago
Clone

c539977 INOTIFY: Fix warning Wstringop-truncation

Authored and Committed by lslebodn 6 years ago
    INOTIFY: Fix warning Wstringop-truncation
    
    It could not cause any security bug because it is used only with short
    names /etc/passwd, /etc/group, /etc/resolv.conf.
    And only root could set long names via env variables
    SSS_FILES_PASSWD, SSS_FILES_GROUP
    
      CC       src/util/libsss_files_la-inotify.lo
    src/util/inotify.c: In function ‘copy_filenames’:
    src/util/inotify.c:390:5: warning: ‘strncpy’ specified bound 4096
        equals destination size [-Wstringop-truncation]
         strncpy(fcopy, filename, sizeof(fcopy));
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ../sssd/src/util/inotify.c:403:5: warning: ‘strncpy’ specified bound
        4096 equals destination size [-Wstringop-truncation]
         strncpy(fcopy, filename, sizeof(fcopy));
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    man gcc says:
               In the following example, the call to "strncpy" specifies the size
               of the destination buffer as the bound.  If the length of the
               source string is equal to or greater than this size the result of
               the copy will not be NUL-terminated.  Therefore, the call is also
               diagnosed.  To avoid the warning, specify "sizeof buf - 1" as the
               bound and set the last element of the buffer to "NUL".
    
                       void copy (const char *s)
                       {
                         char buf[80];
                         strncpy (buf, s, sizeof buf);
                         ...
                       }
    
    Reviewed-by: Fabiano Fidêncio <fidencio@redhat.com>
    
        
file modified
+5 -5