Avoid a segfault in nxt_conn_io_sendbuf()

This is a simple temporary fix (doesn't address the underlying problem)
for an issue reported by a user on GitHub whereby downloading of files
from a PHP application would cause the router process to crash.

This is actually a generic problem that will affect anything sending
data via nxt_unit_response_write().

This is just a simple fix for the 1.32 release, after which the full
correct fix will be worked out.

Link: <https://github.com/nginx/unit/issues/1125>
Reported-by: rustedsword <https://github.com/rustedsword>
Co-developed-by: rustedsword <https://github.com/rustedsword>
Tested-by: rustedsword <https://github.com/rustedsword>
Tested-by: Andrew Clayton <a.clayton@nginx.com>
Reviewed-by: Zhidao Hong <z.hong@f5.com>
Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
This commit is contained in:
Andrew Clayton
2024-02-19 15:20:51 +00:00
parent 0c98353091
commit 30b410e490

View File

@@ -172,6 +172,13 @@ nxt_conn_io_sendbuf(nxt_task_t *task, nxt_sendbuf_t *sb)
return 0; return 0;
} }
/*
* XXX Temporary fix for <https://github.com/nginx/unit/issues/1125>
*/
if (niov == 0 && sb->buf == NULL) {
return 0;
}
if (niov == 0 && nxt_buf_is_file(sb->buf)) { if (niov == 0 && nxt_buf_is_file(sb->buf)) {
return nxt_conn_io_sendfile(task, sb); return nxt_conn_io_sendfile(task, sb);
} }