]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUILD/MINOR: tools: fix build warning in the date conversion functions
authorWilly Tarreau <w@1wt.eu>
Tue, 12 Feb 2019 10:26:29 +0000 (11:26 +0100)
committerWilly Tarreau <w@1wt.eu>
Tue, 12 Feb 2019 10:30:04 +0000 (11:30 +0100)
Some gcc versions emit potential null deref warnings at -O3 in
date2str_log(), gmt2str_log() and localdate2str_log() after utoa_pad()
because this function may return NULL if its size argument is too small
for the integer value. And it's true that we can't guarantee that the
input number is always valid.

This must be backported to all stable versions.

src/standard.c

index 6729e89be85ebb755bd48abaabb14ef9ea9050ba..efa41710e14e3723a795658f20b80be1852eea4d 100644 (file)
@@ -2825,19 +2825,37 @@ char *date2str_log(char *dst, const struct tm *tm, const struct timeval *date, s
                return NULL;
 
        dst = utoa_pad((unsigned int)tm->tm_mday, dst, 3); // day
+       if (!dst)
+               return NULL;
        *dst++ = '/';
+
        memcpy(dst, monthname[tm->tm_mon], 3); // month
        dst += 3;
        *dst++ = '/';
+
        dst = utoa_pad((unsigned int)tm->tm_year+1900, dst, 5); // year
+       if (!dst)
+               return NULL;
        *dst++ = ':';
+
        dst = utoa_pad((unsigned int)tm->tm_hour, dst, 3); // hour
+       if (!dst)
+               return NULL;
        *dst++ = ':';
+
        dst = utoa_pad((unsigned int)tm->tm_min, dst, 3); // minutes
+       if (!dst)
+               return NULL;
        *dst++ = ':';
+
        dst = utoa_pad((unsigned int)tm->tm_sec, dst, 3); // secondes
+       if (!dst)
+               return NULL;
        *dst++ = '.';
+
        utoa_pad((unsigned int)(date->tv_usec/1000), dst, 4); // millisecondes
+       if (!dst)
+               return NULL;
        dst += 3;  // only the 3 first digits
        *dst = '\0';
 
@@ -2919,17 +2937,32 @@ char *gmt2str_log(char *dst, struct tm *tm, size_t size)
                return NULL;
 
        dst = utoa_pad((unsigned int)tm->tm_mday, dst, 3); // day
+       if (!dst)
+               return NULL;
        *dst++ = '/';
+
        memcpy(dst, monthname[tm->tm_mon], 3); // month
        dst += 3;
        *dst++ = '/';
+
        dst = utoa_pad((unsigned int)tm->tm_year+1900, dst, 5); // year
+       if (!dst)
+               return NULL;
        *dst++ = ':';
+
        dst = utoa_pad((unsigned int)tm->tm_hour, dst, 3); // hour
+       if (!dst)
+               return NULL;
        *dst++ = ':';
+
        dst = utoa_pad((unsigned int)tm->tm_min, dst, 3); // minutes
+       if (!dst)
+               return NULL;
        *dst++ = ':';
+
        dst = utoa_pad((unsigned int)tm->tm_sec, dst, 3); // secondes
+       if (!dst)
+               return NULL;
        *dst++ = ' ';
        *dst++ = '+';
        *dst++ = '0';
@@ -2956,18 +2989,34 @@ char *localdate2str_log(char *dst, time_t t, struct tm *tm, size_t size)
        gmt_offset = get_gmt_offset(t, tm);
 
        dst = utoa_pad((unsigned int)tm->tm_mday, dst, 3); // day
+       if (!dst)
+               return NULL;
        *dst++ = '/';
+
        memcpy(dst, monthname[tm->tm_mon], 3); // month
        dst += 3;
        *dst++ = '/';
+
        dst = utoa_pad((unsigned int)tm->tm_year+1900, dst, 5); // year
+       if (!dst)
+               return NULL;
        *dst++ = ':';
+
        dst = utoa_pad((unsigned int)tm->tm_hour, dst, 3); // hour
+       if (!dst)
+               return NULL;
        *dst++ = ':';
+
        dst = utoa_pad((unsigned int)tm->tm_min, dst, 3); // minutes
+       if (!dst)
+               return NULL;
        *dst++ = ':';
+
        dst = utoa_pad((unsigned int)tm->tm_sec, dst, 3); // secondes
+       if (!dst)
+               return NULL;
        *dst++ = ' ';
+
        memcpy(dst, gmt_offset, 5); // Offset from local time to GMT
        dst += 5;
        *dst = '\0';