uint32_t info; /* information about the block (type, length) */
};
+/* Maximum length of the name and the value of a header or a trailer. For these
+ * blocks, the <info> field above encodes the name length on 8 bits and the
+ * value length on 20 bits. Above these limits, the lengths would silently
+ * overflow on the other fields, corrupting the block. So these limits must
+ * always be checked when a header or a trailer is added or updated.
+ */
+#define HTX_HDR_NAME_MAX_LEN 255
+#define HTX_HDR_VALUE_MAX_LEN 1048575
+
/* Composite return value used by some HTX functions */
struct htx_ret {
int32_t ret; /* A numerical value */
switch (type) {
case HTX_BLK_HDR:
case HTX_BLK_TLR:
- BUG_ON(newlen > 1048575);
+ BUG_ON(newlen > HTX_HDR_VALUE_MAX_LEN);
oldlen = (blk->info >> 8) & 0xfffff;
blk->info = (type << 28) + (newlen << 8) + (blk->info & 0xff);
break;
switch (type) {
case HTX_BLK_HDR:
case HTX_BLK_TLR:
- BUG_ON(vlen > 1048575);
+ BUG_ON(vlen > HTX_HDR_VALUE_MAX_LEN);
blk->info = (type << 28) + (vlen << 8) + (blk->info & 0xff);
break;
case HTX_BLK_REQ_SL:
{
struct htx_blk *blk, *tailblk;
- if (name.len > 255 || value.len > 1048575)
+ if (name.len > HTX_HDR_NAME_MAX_LEN || value.len > HTX_HDR_VALUE_MAX_LEN)
return NULL;
tailblk = htx_get_tail_blk(htx);
{
struct htx_blk *blk, *tailblk;
- if (name.len > 255 || value.len > 1048575)
+ if (name.len > HTX_HDR_NAME_MAX_LEN || value.len > HTX_HDR_VALUE_MAX_LEN)
return NULL;
tailblk = htx_get_tail_blk(htx);
* must not overflow on the other fields of the block descriptor.
*/
if (unlikely((type == HTX_BLK_HDR || type == HTX_BLK_TLR) &&
- v.len + delta > 1048575))
+ v.len + delta > HTX_HDR_VALUE_MAX_LEN))
return NULL;
if (unlikely(type < HTX_BLK_EOH && htx_hdrs_too_big(htx, delta)))
if (type != HTX_BLK_HDR)
return NULL;
- if (name.len > 255 || value.len > 1048575)
+ if (name.len > HTX_HDR_NAME_MAX_LEN || value.len > HTX_HDR_VALUE_MAX_LEN)
return NULL;
delta = name.len + value.len - htx_get_blksz(blk);