]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MEDIUM: unique_id: junk in log on empty unique_id
authorWilliam Lallemand <wlallemand@exceliance.fr>
Wed, 28 Aug 2013 13:44:19 +0000 (15:44 +0200)
committerWilly Tarreau <w@1wt.eu>
Sat, 31 Aug 2013 06:01:14 +0000 (08:01 +0200)
When a request fail, the unique_id was allocated but not generated.
The string was not initialized and junk was printed in the log with %ID.

This patch changes the behavior of the unique_id. The unique_id is now
generated when a request failed.

This bug was reported by Patrick Hemmer.

src/log.c
src/proto_http.c

index 369dc34b197094ecac4a5f464ef5e0a2eea685d5..f1fe40c82d403a0d0ce142e776924e9e927326b8 100644 (file)
--- a/src/log.c
+++ b/src/log.c
@@ -1488,8 +1488,10 @@ int build_logline(struct session *s, char *dst, size_t maxsize, struct list *lis
                                break;
 
                        case LOG_FMT_UNIQUEID: // %ID
+                               ret = NULL;
                                src = s->unique_id;
-                               ret = lf_text(tmplog, src, maxsize - (tmplog - dst), tmp);
+                               if (src)
+                                       ret = lf_text(tmplog, src, maxsize - (tmplog - dst), tmp);
                                if (ret == NULL)
                                        goto out;
                                tmplog = ret;
@@ -1541,6 +1543,12 @@ void sess_log(struct session *s)
                        level = LOG_ERR;
        }
 
+       /* if unique-id was not generated */
+       if (!s->unique_id && !LIST_ISEMPTY(&s->fe->format_unique_id)) {
+               if ((s->unique_id = pool_alloc2(pool2_uniqueid)) != NULL)
+                       build_logline(s, s->unique_id, UNIQUEID_LEN, &s->fe->format_unique_id);
+       }
+
        tmplog = update_log_hdr();
        size = tmplog - logline;
        size += build_logline(s, tmplog, sizeof(logline) - size, &s->fe->logformat);
index 8d6eaf51912d7d3d430b439c54e4383f2d3edfe0..6ab2676f6104e763274229bb253313c75d4f27fa 100644 (file)
@@ -2635,9 +2635,6 @@ int http_wait_for_request(struct session *s, struct channel *req, int an_bit)
                }
        }
 
-       if (!LIST_ISEMPTY(&s->fe->format_unique_id))
-               s->unique_id = pool_alloc2(pool2_uniqueid);
-
        /* 4. We may have to convert HTTP/0.9 requests to HTTP/1.0 */
        if (unlikely(msg->sl.rq.v_l == 0) && !http_upgrade_v09_to_v10(txn))
                goto return_bad_req;
@@ -3950,8 +3947,12 @@ int http_process_request(struct session *s, struct channel *req, int an_bit)
 
        /* add unique-id if "header-unique-id" is specified */
 
-       if (!LIST_ISEMPTY(&s->fe->format_unique_id))
+       if (!LIST_ISEMPTY(&s->fe->format_unique_id)) {
+               if ((s->unique_id = pool_alloc2(pool2_uniqueid)) == NULL)
+                       goto return_bad_req;
+               s->unique_id[0] = '\0';
                build_logline(s, s->unique_id, UNIQUEID_LEN, &s->fe->format_unique_id);
+       }
 
        if (s->fe->header_unique_id && s->unique_id) {
                chunk_printf(&trash, "%s: %s", s->fe->header_unique_id, s->unique_id);