From 9015b8b25db03be892f1d1344ae75b8318d398df Mon Sep 17 00:00:00 2001 From: Max Romanov Date: Tue, 7 Aug 2018 17:57:06 +0300 Subject: [PATCH] Improved 'invalid file descriptor' diagnostic. Unit router process may send mmap file decritptor to the application process for further information exchange. During this process there may be various errors, which should be described in application error log. If file descriptor cannot be properly transferred with 'new mmap' message, fd variable will be assigned to -1 and further syscalls using this file descriptor will fail. For 'new port' message fd is checked in the same way. This commit adds early 'invalid file descriptor' diagnostic and write corresponding message to error log. Found by Coverity (CID 308515). --- src/nxt_unit.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/nxt_unit.c b/src/nxt_unit.c index b7ac9b61..ba0d912d 100644 --- a/src/nxt_unit.c +++ b/src/nxt_unit.c @@ -598,6 +598,13 @@ nxt_unit_process_msg(nxt_unit_ctx_t *ctx, nxt_unit_port_id_t *port_id, goto fail; } + if (nxt_slow_path(fd < 0)) { + nxt_unit_alert(ctx, "#%"PRIu32": invalid fd %d for new port", + port_msg->stream, fd); + + goto fail; + } + new_port_msg = recv_msg.start; nxt_unit_debug(ctx, "#%"PRIu32": new_port: %d,%d fd %d", @@ -622,6 +629,13 @@ nxt_unit_process_msg(nxt_unit_ctx_t *ctx, nxt_unit_port_id_t *port_id, break; case _NXT_PORT_MSG_MMAP: + if (nxt_slow_path(fd < 0)) { + nxt_unit_alert(ctx, "#%"PRIu32": invalid fd %d for mmap", + port_msg->stream, fd); + + goto fail; + } + rc = nxt_unit_incoming_mmap(ctx, port_msg->pid, fd); break;