From a7d6cf24fb11b723f926e6e562f6c8e97b2935d3 Mon Sep 17 00:00:00 2001 From: Christopher Faulet Date: Thu, 15 Apr 2021 10:25:35 +0200 Subject: [PATCH] BUG/MINOR: http_htx: Remove BUG_ON() from http_get_stline() function The http_get_stline() was designed to be called from HTTP analyzers. Thus before any data forwarding. To prevent any invalid usage, two BUG_ON() statements were added. However, it is not a good idea because it is pretty hard to be sure no HTTP sample fetch will never be called outside the analyzers context. Especially because there is at least one possible area where it may happens. An HTTP sample fetch may be used inside the unique-id format string. On the normal case, it is generated in AN_REQ_HTTP_INNER analyzer. But if an error is reported too early, the id is generated when the log is emitted. So, it is safer to remove the BUG_ON() statements and consider the normal behavior is to return NULL if the first block is not a start-line. Of course, this means all calling functions must test the return value or be sure the start-line is really there. This patch must be backported as far as 2.0. --- src/http_htx.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/http_htx.c b/src/http_htx.c index 53732d146..2ddc50e42 100644 --- a/src/http_htx.c +++ b/src/http_htx.c @@ -64,11 +64,9 @@ struct htx_sl *http_get_stline(const struct htx *htx) { struct htx_blk *blk; - BUG_ON(htx->first == -1); blk = htx_get_first_blk(htx); - if (!blk) + if (!blk || (htx_get_blk_type(blk) != HTX_BLK_REQ_SL && htx_get_blk_type(blk) != HTX_BLK_RES_SL)) return NULL; - BUG_ON(htx_get_blk_type(blk) != HTX_BLK_REQ_SL && htx_get_blk_type(blk) != HTX_BLK_RES_SL); return htx_get_blk_ptr(htx, blk); }