Stream: fixed processing of zero length UDP packets (ticket #1982).

This commit is contained in:
Vladimir Homutov 2020-06-08 11:40:34 +03:00
parent 2d4f04bba0
commit 58d1412f0d
3 changed files with 11 additions and 2 deletions

View File

@ -189,6 +189,13 @@ ngx_udp_output_chain_to_iovec(ngx_iovec_t *vec, ngx_chain_t *in, ngx_log_t *log)
return cl; 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->count = n;
vec->size = total; vec->size = total;

View File

@ -839,7 +839,7 @@ ngx_stream_proxy_init_upstream(ngx_stream_session_t *s)
u->upstream_buf.last = p; 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, ngx_log_debug1(NGX_LOG_DEBUG_STREAM, c->log, 0,
"stream proxy add preread buffer: %uz", "stream proxy add preread buffer: %uz",
c->buffer->last - c->buffer->pos); c->buffer->last - c->buffer->pos);
@ -853,6 +853,7 @@ ngx_stream_proxy_init_upstream(ngx_stream_session_t *s)
*cl->buf = *c->buffer; *cl->buf = *c->buffer;
cl->buf->tag = (ngx_buf_tag_t) &ngx_stream_proxy_module; 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->buf->flush = 1;
cl->next = u->upstream_out; cl->next = u->upstream_out;

View File

@ -234,7 +234,8 @@ ngx_stream_write_filter(ngx_stream_session_t *s, ngx_chain_t *in,
if (size == 0 if (size == 0
&& !(c->buffered & NGX_LOWLEVEL_BUFFERED) && !(c->buffered & NGX_LOWLEVEL_BUFFERED)
&& !(last && c->need_last_buf)) && !(last && c->need_last_buf)
&& !(c->type == SOCK_DGRAM && flush))
{ {
if (last || flush || sync) { if (last || flush || sync) {
for (cl = *out; cl; /* void */) { for (cl = *out; cl; /* void */) {