mirror of
https://github.com/haproxy/haproxy.git
synced 2026-07-16 04:13:18 -04:00
MINOR: htx: Add a field to save the headers data size
The size of headers present in an HTX message are now counted. A dedicated field was added in the HTX structure to do so. This patch is quite simple but it will be mandatory to be able to perform some tests on headers. One of them is to be sure headers never exceed the regular buffer size, even when a large buffer is used.
This commit is contained in:
parent
ac37158a6d
commit
baec1a9c37
3 changed files with 18 additions and 6 deletions
|
|
@ -258,7 +258,7 @@ struct htx {
|
|||
uint32_t data; /* the data size, in bytes. To known to total size used by all allocated
|
||||
* blocks (blocks and their contents), you need to add size used by blocks,
|
||||
* i.e. [ used * sizeof(struct htx_blk *) ] */
|
||||
|
||||
uint32_t hdrs_data;
|
||||
int32_t tail; /* newest inserted block. -1 if the HTX message is empty */
|
||||
int32_t head; /* oldest inserted block. -1 if the HTX message is empty */
|
||||
int32_t first; /* position of the first block to (re)start the analyse. -1 if unset. */
|
||||
|
|
@ -269,8 +269,6 @@ struct htx {
|
|||
|
||||
uint32_t flags; /* HTX_FL_* */
|
||||
|
||||
/* XXX 4 bytes unused */
|
||||
|
||||
/* Blocks representing the HTTP message itself */
|
||||
char blocks[VAR_ARRAY] ALIGNED(8);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -374,6 +374,8 @@ static inline void htx_change_blk_value_len(struct htx *htx, struct htx_blk *blk
|
|||
|
||||
/* Update HTTP message */
|
||||
delta = (newlen - oldlen);
|
||||
if (type < HTX_BLK_EOH)
|
||||
htx->hdrs_data += delta;
|
||||
htx->data += delta;
|
||||
if (blk->addr+sz == htx->tail_addr)
|
||||
htx->tail_addr += delta;
|
||||
|
|
@ -687,7 +689,7 @@ static inline int htx_almost_full(const struct htx *htx)
|
|||
static inline void htx_reset(struct htx *htx)
|
||||
{
|
||||
htx->tail = htx->head = htx->first = -1;
|
||||
htx->data = 0;
|
||||
htx->data = htx->hdrs_data = 0;
|
||||
htx->tail_addr = htx->head_addr = htx->end_addr = 0;
|
||||
htx->flags = HTX_FL_NONE;
|
||||
}
|
||||
|
|
@ -871,9 +873,9 @@ static inline void htx_dump(struct buffer *chunk, const struct htx *htx, int ful
|
|||
{
|
||||
int32_t pos;
|
||||
|
||||
chunk_appendf(chunk, " htx=%p(size=%u,data=%u,used=%u,wrap=%s,flags=0x%08x,"
|
||||
chunk_appendf(chunk, " htx=%p(size=%u,data=%u,hdrs=%u,used=%u,wrap=%s,flags=0x%08x,"
|
||||
"first=%d,head=%d,tail=%d,tail_addr=%d,head_addr=%d,end_addr=%d)",
|
||||
htx, htx->size, htx->data, htx_nbblks(htx), (!htx->head_addr) ? "NO" : "YES",
|
||||
htx, htx->size, htx->data, htx->hdrs_data, htx_nbblks(htx), (!htx->head_addr) ? "NO" : "YES",
|
||||
htx->flags, htx->first, htx->head, htx->tail,
|
||||
htx->tail_addr, htx->head_addr, htx->end_addr);
|
||||
|
||||
|
|
|
|||
12
src/htx.c
12
src/htx.c
|
|
@ -347,6 +347,8 @@ struct htx_blk *htx_add_blk(struct htx *htx, enum htx_blk_type type, uint32_t bl
|
|||
BUG_ON(blk->addr > htx->size);
|
||||
|
||||
blk->info = (type << 28);
|
||||
if (type < HTX_BLK_EOH)
|
||||
htx->hdrs_data += blksz;
|
||||
return blk;
|
||||
}
|
||||
|
||||
|
|
@ -376,6 +378,8 @@ struct htx_blk *htx_remove_blk(struct htx *htx, struct htx_blk *blk)
|
|||
addr = blk->addr;
|
||||
if (type != HTX_BLK_UNUSED) {
|
||||
/* Mark the block as unused, decrement allocated size */
|
||||
if (type < HTX_BLK_EOH)
|
||||
htx->hdrs_data -= sz;
|
||||
htx->data -= htx_get_blksz(blk);
|
||||
blk->info = ((uint32_t)HTX_BLK_UNUSED << 28);
|
||||
}
|
||||
|
|
@ -719,6 +723,10 @@ struct htx_blk *htx_replace_blk_value(struct htx *htx, struct htx_blk *blk,
|
|||
htx_memcpy(htx_get_blk_ptr(htx, blk), b_orig(chunk), b_data(chunk));
|
||||
free_trash_chunk(chunk);
|
||||
}
|
||||
|
||||
if (htx_get_blk_type(blk) < HTX_BLK_EOH)
|
||||
htx->hdrs_data += delta;
|
||||
|
||||
return blk;
|
||||
}
|
||||
|
||||
|
|
@ -1030,6 +1038,8 @@ struct htx_blk *htx_replace_header(struct htx *htx, struct htx_blk *blk,
|
|||
htx->data += delta;
|
||||
}
|
||||
|
||||
htx->hdrs_data += delta;
|
||||
|
||||
/* Finally, copy data. */
|
||||
ptr = htx_get_blk_ptr(htx, blk);
|
||||
ist2bin_lc(ptr, name);
|
||||
|
|
@ -1079,6 +1089,8 @@ struct htx_sl *htx_replace_stline(struct htx *htx, struct htx_blk *blk, const st
|
|||
htx->data += delta;
|
||||
}
|
||||
|
||||
htx->hdrs_data += delta;
|
||||
|
||||
/* Restore start-line info and flags and copy parts of the start-line */
|
||||
sl = htx_get_blk_ptr(htx, blk);
|
||||
sl->info = tmp.info;
|
||||
|
|
|
|||
Loading…
Reference in a new issue