]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: http/sample: gmtime/localtime can fail
authorThierry FOURNIER <tfournier@arpalert.org>
Tue, 7 Jul 2015 22:15:20 +0000 (00:15 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 20 Jul 2015 10:21:35 +0000 (12:21 +0200)
The man said that gmtime() and localtime() can return a NULL value.
This is not tested. It appears that all the values of a 32 bit integer
are valid, but it is better to check the return of these functions.

However, if the integer move from 32 bits to 64 bits, some 64 values
can be unsupported.

src/proto_http.c
src/sample.c

index 0ebc2c409991382b8c82f6c273169d696a7cbf59..69ad908def07d9f442935e871bb74639ba15c246 100644 (file)
@@ -12084,6 +12084,8 @@ static int sample_conv_http_date(const struct arg *args, struct sample *smp, voi
                curr_date += args[0].data.sint;
 
        tm = gmtime(&curr_date);
+       if (!tm)
+               return 0;
 
        temp = get_trash_chunk();
        temp->len = snprintf(temp->str, temp->size - temp->len,
index 6088869b50fad3bd65cc627114882fd8692338ed..0a09012adca09fd20aae8c3d63e8377df308a1fa 100644 (file)
@@ -1519,13 +1519,17 @@ static int sample_conv_ltime(const struct arg *args, struct sample *smp, void *p
 {
        struct chunk *temp;
        time_t curr_date = smp->data.uint;
+       struct tm *tm;
 
        /* add offset */
        if (args[1].type == ARGT_SINT || args[1].type == ARGT_UINT)
                curr_date += args[1].data.sint;
 
+       tm = localtime(&curr_date);
+       if (!tm)
+               return 0;
        temp = get_trash_chunk();
-       temp->len = strftime(temp->str, temp->size, args[0].data.str.str, localtime(&curr_date));
+       temp->len = strftime(temp->str, temp->size, args[0].data.str.str, tm);
        smp->data.str = *temp;
        smp->type = SMP_T_STR;
        return 1;
@@ -1549,13 +1553,17 @@ static int sample_conv_utime(const struct arg *args, struct sample *smp, void *p
 {
        struct chunk *temp;
        time_t curr_date = smp->data.uint;
+       struct tm *tm;
 
        /* add offset */
        if (args[1].type == ARGT_SINT || args[1].type == ARGT_UINT)
                curr_date += args[1].data.sint;
 
+       tm = gmtime(&curr_date);
+       if (!tm)
+               return 0;
        temp = get_trash_chunk();
-       temp->len = strftime(temp->str, temp->size, args[0].data.str.str, gmtime(&curr_date));
+       temp->len = strftime(temp->str, temp->size, args[0].data.str.str, tm);
        smp->data.str = *temp;
        smp->type = SMP_T_STR;
        return 1;