Changeset 47d4f8c for lib


Ignore:
Timestamp:
06/27/18 18:01:48 (2 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!

Location:
lib
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • lib/format_linux_common.c

    rf9df20e r47d4f8c  
    8787                sock = socket(PF_INET, SOCK_STREAM, 0);
    8888                memset(&ifr, 0, sizeof(struct ifreq));
    89                 strncpy(ifr.ifr_name, libtrace->uridata, IF_NAMESIZE);
     89                strncpy(ifr.ifr_name, libtrace->uridata, IF_NAMESIZE - 1);
    9090                if (ioctl(sock, SIOCGIFHWADDR, &ifr) != 0) {
    9191                        perror("Can't get HWADDR for interface");
  • lib/libtrace.h.in

    r32ee9b2 r47d4f8c  
    277277typedef struct trace_err_t{
    278278        int err_num;            /**< error code */
    279         char problem[255];      /**< the format, uri etc that caused the error for reporting purposes */
     279        char problem[1024];     /**< the format, uri etc that caused the error for reporting purposes */
    280280} libtrace_err_t;
    281281
  • 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.