summaryrefslogtreecommitdiffhomepage
path: root/src/nxt_unit.c
diff options
context:
space:
mode:
authorMax Romanov <max.romanov@nginx.com>2018-08-07 17:57:06 +0300
committerMax Romanov <max.romanov@nginx.com>2018-08-07 17:57:06 +0300
commit9015b8b25db03be892f1d1344ae75b8318d398df (patch)
tree746e55e58e86a0f49976e39b3c470a7852414b3f /src/nxt_unit.c
parent257283cc389a8f453cbf4ebd028af79e9b23258b (diff)
downloadunit-9015b8b25db03be892f1d1344ae75b8318d398df.tar.gz
unit-9015b8b25db03be892f1d1344ae75b8318d398df.tar.bz2
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).
Diffstat (limited to 'src/nxt_unit.c')
-rw-r--r--src/nxt_unit.c14
1 files changed, 14 insertions, 0 deletions
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;