Skip to content

Commit

Permalink
Stream: fixed processing of zero length UDP packets (ticket #1982).
Browse files Browse the repository at this point in the history
--HG--
branch : nginx
  • Loading branch information
vlhomutov committed Jun 8, 2020
1 parent 16aba52 commit 8180d6e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/os/unix/ngx_udp_sendmsg_chain.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,13 @@ ngx_udp_output_chain_to_iovec(ngx_iovec_t *vec, ngx_chain_t *in, ngx_log_t *log)
return cl;
}

/* zero-sized datagram; pretend to have at least 1 iov */
if (n == 0) {
iov = &vec->iovs[n++];
iov->iov_base = NULL;
iov->iov_len = 0;
}

vec->count = n;
vec->size = total;

Expand Down
3 changes: 2 additions & 1 deletion src/stream/ngx_stream_proxy_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -839,7 +839,7 @@ ngx_stream_proxy_init_upstream(ngx_stream_session_t *s)
u->upstream_buf.last = p;
}

if (c->buffer && c->buffer->pos < c->buffer->last) {
if (c->buffer && c->buffer->pos <= c->buffer->last) {
ngx_log_debug1(NGX_LOG_DEBUG_STREAM, c->log, 0,
"stream proxy add preread buffer: %uz",
c->buffer->last - c->buffer->pos);
Expand All @@ -853,6 +853,7 @@ ngx_stream_proxy_init_upstream(ngx_stream_session_t *s)
*cl->buf = *c->buffer;

cl->buf->tag = (ngx_buf_tag_t) &ngx_stream_proxy_module;
cl->buf->temporary = (cl->buf->pos == cl->buf->last) ? 0 : 1;
cl->buf->flush = 1;

cl->next = u->upstream_out;
Expand Down
3 changes: 2 additions & 1 deletion src/stream/ngx_stream_write_filter_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,8 @@ ngx_stream_write_filter(ngx_stream_session_t *s, ngx_chain_t *in,

if (size == 0
&& !(c->buffered & NGX_LOWLEVEL_BUFFERED)
&& !(last && c->need_last_buf))
&& !(last && c->need_last_buf)
&& !(c->type == SOCK_DGRAM && flush))
{
if (last || flush || sync) {
for (cl = *out; cl; /* void */) {
Expand Down

0 comments on commit 8180d6e

Please sign in to comment.