Changeset 47d4f8c for lib/trace.c


Ignore:
Timestamp:
06/27/18 18:01:48 (3 years ago)
Author:
Shane Alcock <salcock@…>
Branches:
cachetimestamps, develop, master, rc-4.0.4, ringdecrementfix, ringperformance
Children:
1ed69dc
Parents:
35de364
Message:

Fix various string truncation/overflow warnings

Thanks gcc 8!

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/trace.c

    r32ee9b2 r47d4f8c  
    107107 * will use our own one that does
    108108 */
    109 static void xstrncpy(char *dest, const char *src, size_t n)
    110 {
    111         strncpy(dest,src,n);
    112         dest[n]='\0';
     109static inline void xstrncpy(char *dest, const char *src, size_t n,
     110                size_t destlen)
     111{
     112        size_t slen = destlen - 1;
     113        if (n < slen) {
     114                slen = n;
     115        }
     116        strncpy(dest,src,slen);
     117        dest[slen]='\0';
    113118}
    114119
     
    120125                exit(EXIT_FAILURE);
    121126        }
    122         xstrncpy(ret,src,n);
     127        xstrncpy(ret,src,n,n+1);
    123128        return ret;
    124129}
     
    371376
    372377        if((uridata = strchr(uri,':')) == NULL) {
    373                 xstrncpy(scan, uri, strlen(uri));
     378                xstrncpy(scan, uri, strlen(uri), URI_PROTO_LINE);
    374379        } else {
    375                 xstrncpy(scan,uri, (size_t)(uridata - uri));
     380                xstrncpy(scan,uri, (size_t)(uridata - uri), URI_PROTO_LINE);
    376381        }
    377382
Note: See TracChangeset for help on using the changeset viewer.