At many places, we rely on global.tune.bufsize value instead of using the buffer
size. For now, it is not a problem. But if we want to be able to deal with
buffers of different sizes, it is good to reduce as far as possible dependencies
on the global value. most of time, we can use b_size() or c_size()
functions. The main change is performed on the error snapshot where the buffer
size was added into the error_snapshot structure.
*/
static inline size_t channel_data_limit(const struct channel *chn)
{
- size_t max = (global.tune.bufsize - global.tune.maxrewrite);
+ size_t max;
+
+ if (!c_size(chn))
+ return 0;
+ max = (c_size(chn) - global.tune.maxrewrite);
if (IS_HTX_STRM(chn_strm(chn)))
max -= HTX_BUF_OVERHEAD;
return max;
struct server *srv; /* server associated with the error (or NULL) */
/* @64 */
unsigned int ev_id; /* event number (counter incremented for each capture) */
- /* @68: 4 bytes hole here */
+ unsigned int buf_size; /* buffer size */
+
struct sockaddr_storage src; /* client's address */
/**** protocol-specific part ****/
static inline void sc_need_room(struct stconn *sc, ssize_t room_needed)
{
sc->flags |= SC_FL_NEED_ROOM;
- BUG_ON_HOT(room_needed > (ssize_t)global.tune.bufsize);
+ BUG_ON_HOT(room_needed > (ssize_t)c_size(sc_ic(sc)));
sc->room_needed = room_needed;
}
if (!len)
goto dup;
if (len == -1)
- len = global.tune.bufsize;
+ len = c_size(chn);
if (len < 0) {
lua_pushfstring(L, "length out of range.");
WILL_LJMP(lua_error(L));
if (!len)
goto dup;
if (len == -1)
- len = global.tune.bufsize;
+ len = c_size(chn);
if (len < 0) {
lua_pushfstring(L, "length out of range.");
WILL_LJMP(lua_error(L));
if (!len)
goto dup;
if (len == -1)
- len = global.tune.bufsize;
+ len = c_size(msg->chn);
if (len < 0) {
lua_pushfstring(L, "length out of range.");
WILL_LJMP(lua_error(L));
len = base64dec(txn->auth.method_data.area,
txn->auth.method_data.data,
- http_auth->area, global.tune.bufsize - 1);
+ http_auth->area, http_auth->size -1);
if (len < 0)
return 0;
* a pointer swap and the next read will be doable at once in
* an empty buffer.
*/
- if (max > global.tune.bufsize - global.tune.maxrewrite)
- max = global.tune.bufsize - global.tune.maxrewrite;
+ if (max > b_size(&h1c->ibuf) - global.tune.maxrewrite)
+ max = b_size(&h1c->ibuf) - global.tune.maxrewrite;
}
if (max) {
goto done;
}
- if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) {
+ if ((int)hdr.len < 0 || (int)hdr.len > b_size(&h2c->dbuf)) {
/* RFC7540#3.5: a GOAWAY frame MAY be omitted */
h2c_report_glitch(h2c, 1, "invalid settings frame length");
TRACE_ERROR("invalid settings frame length", H2_EV_RX_FRAME|H2_EV_RX_FHDR|H2_EV_RX_SETTINGS|H2_EV_PROTO_ERR, h2c->conn);
break;
}
- if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) {
+ if ((int)hdr.len < 0 || (int)hdr.len > b_size(&h2c->dbuf)) {
h2c_report_glitch(h2c, 1, "invalid H2 frame length");
TRACE_ERROR("invalid H2 frame length", H2_EV_RX_FRAME|H2_EV_RX_FHDR|H2_EV_PROTO_ERR, h2c->conn);
h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR);
h2c->st0 = H2_CS_FRAME_P;
/* check for minimum basic frame format validity */
- ret = h2_frame_check(h2c->dft, 1, h2c->dsi, h2c->dfl, global.tune.bufsize);
+ ret = h2_frame_check(h2c->dft, 1, h2c->dsi, h2c->dfl, b_size(&h2c->dbuf));
if (ret != H2_ERR_NO_ERROR) {
h2c_report_glitch(h2c, 1, "received invalid H2 frame header");
TRACE_ERROR("received invalid H2 frame header", H2_EV_RX_FRAME|H2_EV_RX_FHDR|H2_EV_PROTO_ERR, h2c->conn);
goto fail;
}
- if ((unsigned)hdr.len > (unsigned)global.tune.bufsize) {
+ if ((unsigned)hdr.len > (unsigned)b_size(&h2c->dbuf)) {
/* RFC7540#4.2: invalid frame length */
h2c_report_glitch(h2c, 1, "too large CONTINUATION frame");
TRACE_STATE("too large CONTINUATION frame", H2_EV_RX_FRAME|H2_EV_RX_FHDR|H2_EV_RX_HDR|H2_EV_RX_CONT|H2_EV_H2C_ERR|H2_EV_PROTO_ERR, h2c->conn);
unsigned int len_size = arg_p[1].data.sint;
unsigned int buf_offset;
unsigned int buf_size = 0;
- struct channel *chn = NULL;
char *head = NULL;
size_t max, data;
int i;
/* buf offset could be absolute or relative to len offset + len size if prefixed by + or - */
if (smp->strm) {
+ struct channel *chn = NULL;
+
/* meaningless for HTX buffers */
if (IS_HTX_STRM(smp->strm))
return 0;
chn = ((smp->opt & SMP_OPT_DIR) == SMP_OPT_DIR_RES) ? &smp->strm->res : &smp->strm->req;
head = ci_head(chn);
data = ci_data(chn);
+ max = c_size(chn);
}
else if (obj_type(smp->sess->origin) == OBJ_TYPE_CHECK) {
struct check *check = __objt_check(smp->sess->origin);
return 0;
head = b_head(&check->bi);
data = b_data(&check->bi);
+ max = b_size(&check->bi);
}
- max = global.tune.bufsize;
+
if (!head)
goto too_short;
chn = ((smp->opt & SMP_OPT_DIR) == SMP_OPT_DIR_RES) ? &smp->strm->res : &smp->strm->req;
head = ci_head(chn);
data = ci_data(chn);
+ max = c_size(chn);
}
else if (obj_type(smp->sess->origin) == OBJ_TYPE_CHECK) {
struct check *check = __objt_check(smp->sess->origin);
return 0;
head = b_head(&check->bi);
data = b_data(&check->bi);
+ max = b_size(&check->bi);
}
- max = global.tune.bufsize;
if (!head)
goto too_short;
if (!es)
return;
+ es->buf_size = buf->size;
es->buf_len = buf_len;
es->ev_id = ev_id;
es->srv ? es->srv->puid : -1,
es->ev_id, pn, port,
es->buf_ofs, es->buf_out,
- global.tune.bufsize - es->buf_out - es->buf_len,
+ es->buf_size - es->buf_out - es->buf_len,
es->buf_len, es->buf_wrap, es->buf_err);
if (es->show)
}
/* OK, ptr >= 0, so we have to dump the current line */
- while (ctx->ptr < es->buf_len && ctx->ptr < global.tune.bufsize) {
+ while (ctx->ptr < es->buf_len && ctx->ptr < es->buf_size) {
int newptr;
int newline;
newline = ctx->bol;
- newptr = dump_text_line(&trash, es->buf, global.tune.bufsize, es->buf_len, &newline, ctx->ptr);
+ newptr = dump_text_line(&trash, es->buf, es->buf_size, es->buf_len, &newline, ctx->ptr);
if (newptr == ctx->ptr) {
applet_fl_set(appctx, APPCTX_FL_OUTBLK_FULL);
goto cant_send_unlock;
* a buffer.
*/
(!b_is_null(&ctx->early_buf)) ?
- global.tune.bufsize - global.tune.maxrewrite : 0);
+ ctx->early_buf.size - global.tune.maxrewrite : 0);
}
#endif