mirror of
https://github.com/sonertari/SSLproxy
synced 2024-11-02 15:40:19 +00:00
Handle out of memory conditions correctly
This commit is contained in:
parent
2f0e574f09
commit
2aeec751e0
34
protohttp.c
34
protohttp.c
@ -397,6 +397,10 @@ protohttp_filter_request_header(struct evbuffer *inbuf, struct evbuffer *outbuf,
|
||||
#ifdef DEBUG_PROXY
|
||||
log_dbg_level_printf(LOG_DBG_MODE_FINER, "protohttp_filter_request_header: REMOVE= %s, fd=%d\n", line, ctx->fd);
|
||||
#endif /* DEBUG_PROXY */
|
||||
|
||||
if (ctx->conn->enomem) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
free(line);
|
||||
|
||||
@ -417,10 +421,7 @@ protohttp_filter_request_header(struct evbuffer *inbuf, struct evbuffer *outbuf,
|
||||
protohttp_ocsp_deny(ctx, http_ctx);
|
||||
}
|
||||
|
||||
// @todo Fix this
|
||||
/* out of memory condition? */
|
||||
if (ctx->conn->enomem) {
|
||||
pxy_conn_free(ctx->conn, 1);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -466,6 +467,9 @@ protohttp_bev_readcb_src(struct bufferevent *bev, void *arg)
|
||||
#endif /* DEBUG_PROXY */
|
||||
|
||||
protohttp_filter_request_header(inbuf, outbuf, ctx, http_ctx);
|
||||
if (ctx->enomem) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
#ifdef DEBUG_PROXY
|
||||
log_dbg_level_printf(LOG_DBG_MODE_FINEST, "protohttp_bev_readcb_src: HTTP Request Body, size=%zu, fd=%d\n", evbuffer_get_length(inbuf), ctx->fd);
|
||||
@ -583,18 +587,15 @@ protohttp_filter_response_header(struct evbuffer *inbuf, struct evbuffer *outbuf
|
||||
#ifdef DEBUG_PROXY
|
||||
log_dbg_level_printf(LOG_DBG_MODE_FINER, "protohttp_filter_response_header: REMOVE= %s, fd=%d\n", line, ctx->fd);
|
||||
#endif /* DEBUG_PROXY */
|
||||
|
||||
if (ctx->conn->enomem) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
free(line);
|
||||
}
|
||||
|
||||
if (http_ctx->seen_resp_header) {
|
||||
// @todo Fix this
|
||||
/* out of memory condition? */
|
||||
if (ctx->conn->enomem) {
|
||||
pxy_conn_free(ctx->conn, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
/* no data left after parsing headers? */
|
||||
if (evbuffer_get_length(inbuf) == 0) {
|
||||
return;
|
||||
@ -628,6 +629,9 @@ protohttp_bev_readcb_dst(struct bufferevent *bev, void *arg)
|
||||
#endif /* DEBUG_PROXY */
|
||||
|
||||
protohttp_filter_response_header(inbuf, outbuf, ctx, http_ctx);
|
||||
if (ctx->enomem) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
#ifdef DEBUG_PROXY
|
||||
log_dbg_level_printf(LOG_DBG_MODE_FINEST, "protohttp_bev_readcb_dst: HTTP Response Body, size=%zu, fd=%d\n", evbuffer_get_length(inbuf), ctx->fd);
|
||||
@ -675,6 +679,9 @@ protohttp_bev_readcb_src_child(struct bufferevent *bev, void *arg)
|
||||
|
||||
// @todo Just remove SSLproxy line, do not filter response on the server side?
|
||||
protohttp_filter_request_header(inbuf, outbuf, (pxy_conn_ctx_t *)ctx, http_ctx);
|
||||
if (ctx->conn->enomem) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
#ifdef DEBUG_PROXY
|
||||
log_dbg_level_printf(LOG_DBG_MODE_FINEST, "protohttp_bev_readcb_src_child: HTTP Request Body, size=%zu, child fd=%d, fd=%d\n",
|
||||
@ -713,6 +720,9 @@ protohttp_bev_readcb_dst_child(struct bufferevent *bev, void *arg)
|
||||
|
||||
// @todo Do not filter response on the server side?
|
||||
protohttp_filter_response_header(inbuf, outbuf, (pxy_conn_ctx_t *)ctx, http_ctx);
|
||||
if (ctx->conn->enomem) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
#ifdef DEBUG_PROXY
|
||||
log_dbg_level_printf(LOG_DBG_MODE_FINEST, "protohttp_bev_readcb_dst_child: HTTP Response Body, size=%zu, child fd=%d, fd=%d\n",
|
||||
@ -743,6 +753,10 @@ protohttp_bev_readcb(struct bufferevent *bev, void *arg)
|
||||
return;
|
||||
}
|
||||
|
||||
if (ctx->enomem) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!seen_resp_header_on_entry && http_ctx->seen_resp_header) {
|
||||
/* response header complete: log connection */
|
||||
if (WANT_CONNECT_LOG(ctx->conn) || ctx->opts->statslog) {
|
||||
|
10
pxyconn.c
10
pxyconn.c
@ -1229,6 +1229,11 @@ pxy_bev_readcb(struct bufferevent *bev, void *arg)
|
||||
|
||||
ctx->atime = time(NULL);
|
||||
ctx->protoctx->bev_readcb(bev, ctx);
|
||||
|
||||
/* out of memory condition? */
|
||||
if (ctx->enomem) {
|
||||
pxy_conn_free(ctx, (bev == ctx->src.bev));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
@ -1259,6 +1264,11 @@ pxy_bev_readcb_child(struct bufferevent *bev, void *arg)
|
||||
|
||||
ctx->conn->atime = time(NULL);
|
||||
ctx->protoctx->bev_readcb(bev, ctx);
|
||||
|
||||
/* out of memory condition? */
|
||||
if (ctx->conn->enomem) {
|
||||
pxy_conn_free(ctx->conn, (bev == ctx->src.bev));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
Loading…
Reference in New Issue
Block a user