Skip to content

Commit 42043b4

Browse files
committed
gRPC: limited allocations due to ping and settings frames.
1 parent 60b9359 commit 42043b4

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/http/modules/ngx_http_grpc_module.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ typedef struct {
7878

7979
ngx_uint_t id;
8080

81+
ngx_uint_t pings;
82+
ngx_uint_t settings;
83+
8184
ssize_t send_window;
8285
size_t recv_window;
8386

@@ -3584,6 +3587,12 @@ ngx_http_grpc_parse_settings(ngx_http_request_t *r, ngx_http_grpc_ctx_t *ctx,
35843587
ctx->rest);
35853588
return NGX_ERROR;
35863589
}
3590+
3591+
if (ctx->free == NULL && ctx->settings++ > 1000) {
3592+
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
3593+
"upstream sent too many settings frames");
3594+
return NGX_ERROR;
3595+
}
35873596
}
35883597

35893598
for (p = b->pos; p < last; p++) {
@@ -3736,6 +3745,12 @@ ngx_http_grpc_parse_ping(ngx_http_request_t *r,
37363745
"upstream sent ping frame with ack flag");
37373746
return NGX_ERROR;
37383747
}
3748+
3749+
if (ctx->free == NULL && ctx->pings++ > 1000) {
3750+
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
3751+
"upstream sent too many ping frames");
3752+
return NGX_ERROR;
3753+
}
37393754
}
37403755

37413756
for (p = b->pos; p < last; p++) {

0 commit comments

Comments
 (0)