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).
This commit is contained in:
Max Romanov
2018-08-07 17:57:06 +03:00
parent 257283cc38
commit 9015b8b25d

View File

@@ -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;