From 5c50329f8edcbf3b56d9ffbc207eae64ca72e0fb Mon Sep 17 00:00:00 2001 From: Valentin Bartenev Date: Fri, 20 Sep 2019 14:31:19 +0300 Subject: Fixed segfault if an inappropriate file system object is requested. Found by Coverity (CID 349483). --- src/nxt_http_static.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/nxt_http_static.c b/src/nxt_http_static.c index 44b85389..4679af5b 100644 --- a/src/nxt_http_static.c +++ b/src/nxt_http_static.c @@ -209,7 +209,6 @@ nxt_http_static_handler(nxt_task_t *task, nxt_http_request_t *r, /* Not a file. */ nxt_file_close(task, f); - f = NULL; if (nxt_slow_path(!nxt_is_dir(&fi))) { nxt_log(task, NXT_LOG_ERR, "\"%FN\" is not a regular file", @@ -218,6 +217,8 @@ nxt_http_static_handler(nxt_task_t *task, nxt_http_request_t *r, return NULL; } + f = NULL; + r->status = NXT_HTTP_MOVED_PERMANENTLY; r->resp.content_length_n = 0; -- cgit From c416933171810a85b4e4e8fa6778820e1746b003 Mon Sep 17 00:00:00 2001 From: Sergey Kandaurov Date: Mon, 23 Sep 2019 11:56:31 +0000 Subject: PHP: zeroing the whole file_handle structure. Fixes segfaults with PHP 7.4. --- src/nxt_php_sapi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/nxt_php_sapi.c b/src/nxt_php_sapi.c index f5f115f5..7a5e0a3b 100644 --- a/src/nxt_php_sapi.c +++ b/src/nxt_php_sapi.c @@ -668,10 +668,10 @@ nxt_php_request_handler(nxt_unit_request_info_t *req) SG(request_info).path_translated = NULL; + nxt_memzero(&file_handle, sizeof(file_handle)); + file_handle.type = ZEND_HANDLE_FILENAME; file_handle.filename = (char *) ctx->script_filename.start; - file_handle.free_filename = 0; - file_handle.opened_path = NULL; nxt_unit_req_debug(req, "handle.filename = '%s'", ctx->script_filename.start); -- cgit From 514f34144a491832db1647c84a7271120ba7e7d6 Mon Sep 17 00:00:00 2001 From: Valentin Bartenev Date: Tue, 24 Sep 2019 15:33:42 +0300 Subject: Static: returning 404 for Unix domain sockets. It's now similar to how attempts to access other non-regular files are handled. --- src/nxt_errno.h | 1 + src/nxt_http_static.c | 11 +++++++++++ 2 files changed, 12 insertions(+) (limited to 'src') diff --git a/src/nxt_errno.h b/src/nxt_errno.h index e3ce8349..1b29ef2f 100644 --- a/src/nxt_errno.h +++ b/src/nxt_errno.h @@ -16,6 +16,7 @@ typedef int nxt_err_t; #define NXT_ENOPATH ENOENT #define NXT_ESRCH ESRCH #define NXT_EINTR EINTR +#define NXT_ENXIO ENXIO #define NXT_ECHILD ECHILD #define NXT_ENOMEM ENOMEM #define NXT_EACCES EACCES diff --git a/src/nxt_http_static.c b/src/nxt_http_static.c index 4679af5b..48a989cf 100644 --- a/src/nxt_http_static.c +++ b/src/nxt_http_static.c @@ -94,9 +94,20 @@ nxt_http_static_handler(nxt_task_t *task, nxt_http_request_t *r, if (nxt_slow_path(ret != NXT_OK)) { switch (f->error) { + /* + * For Unix domain sockets "errno" is set to: + * - ENXIO on Linux; + * - EOPNOTSUPP on *BSD, MacOSX, and Solaris. + */ + case NXT_ENOENT: case NXT_ENOTDIR: case NXT_ENAMETOOLONG: +#if (NXT_LINUX) + case NXT_ENXIO: +#else + case NXT_EOPNOTSUPP: +#endif level = NXT_LOG_ERR; status = NXT_HTTP_NOT_FOUND; break; -- cgit From 7f389c814a46d86c3294466826058cd2ed7b2f98 Mon Sep 17 00:00:00 2001 From: Tiago Natel Date: Fri, 20 Sep 2019 13:16:33 +0000 Subject: Closing leaking file descriptor. Found by Coverity (CID 349484). --- src/nxt_clone.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src') diff --git a/src/nxt_clone.c b/src/nxt_clone.c index 0fddd6c7..a2c376a3 100644 --- a/src/nxt_clone.c +++ b/src/nxt_clone.c @@ -127,9 +127,13 @@ nxt_clone_proc_map_write(nxt_task_t *task, const char *mapfile, pid_t pid, nxt_errno); } + close(mapfd); + return NXT_ERROR; } + close(mapfd); + return NXT_OK; } -- cgit From 20628c74fa315a1dae6bea64ad365d544bf80510 Mon Sep 17 00:00:00 2001 From: Tiago Natel Date: Fri, 20 Sep 2019 13:12:04 +0000 Subject: Releasing init struct in case of errors. Found by Coverity (CID 349485). --- src/nxt_main_process.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/nxt_main_process.c b/src/nxt_main_process.c index 44deb272..3ec44d83 100644 --- a/src/nxt_main_process.c +++ b/src/nxt_main_process.c @@ -661,7 +661,7 @@ nxt_main_start_worker_process(nxt_task_t *task, nxt_runtime_t *rt, ret = nxt_user_cred_get(task, init->user_cred, group); if (ret != NXT_OK) { - return NXT_ERROR; + goto fail; } } else { @@ -670,7 +670,7 @@ nxt_main_start_worker_process(nxt_task_t *task, nxt_runtime_t *rt, { nxt_alert(task, "cannot set user \"%V\" for app \"%V\": " "missing capabilities", &app_conf->user, &app_conf->name); - return NXT_ERROR; + goto fail; } if (app_conf->group.length > 0 @@ -680,7 +680,7 @@ nxt_main_start_worker_process(nxt_task_t *task, nxt_runtime_t *rt, nxt_alert(task, "cannot set group \"%V\" for app \"%V\": " "missing capabilities", &app_conf->group, &app_conf->name); - return NXT_ERROR; + goto fail; } last = nxt_pointer_to(init, sizeof(nxt_process_init_t)); @@ -702,10 +702,16 @@ nxt_main_start_worker_process(nxt_task_t *task, nxt_runtime_t *rt, ret = nxt_init_set_isolation(task, init, app_conf->isolation); if (nxt_slow_path(ret != NXT_OK)) { - return NXT_ERROR; + goto fail; } return nxt_main_create_worker_process(task, rt, init); + +fail: + + nxt_free(init); + + return NXT_ERROR; } -- cgit From 93ead878105883dd5c70751f06dae13ef7a13c03 Mon Sep 17 00:00:00 2001 From: Tiago Natel Date: Fri, 20 Sep 2019 13:08:04 +0000 Subject: Removed linux/sched.h include. The is already included by nxt_unix.h. This closes #314 PR on GitHub. --- src/nxt_main_process.c | 4 ---- 1 file changed, 4 deletions(-) (limited to 'src') diff --git a/src/nxt_main_process.c b/src/nxt_main_process.c index 3ec44d83..b9e7ab96 100644 --- a/src/nxt_main_process.c +++ b/src/nxt_main_process.c @@ -14,10 +14,6 @@ #include #endif -#ifdef NXT_LINUX -#include -#endif - typedef struct { nxt_socket_t socket; -- cgit From 9c06bfdf2c30d4a414ae803bf36543a9c9a40f66 Mon Sep 17 00:00:00 2001 From: Valentin Bartenev Date: Thu, 26 Sep 2019 16:03:01 +0300 Subject: Fixed descriptors leak on process creation. The leak has been introduced in 325b315e48c4. This closes #322 issue in GitHub. --- src/nxt_process.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src') diff --git a/src/nxt_process.c b/src/nxt_process.c index 638765a4..d83eed28 100644 --- a/src/nxt_process.c +++ b/src/nxt_process.c @@ -166,6 +166,14 @@ nxt_process_create(nxt_task_t *task, nxt_process_t *process) init->name, nxt_errno); #endif + if (nxt_slow_path(close(pipefd[0]) != 0)) { + nxt_alert(task, "failed to close pipe: %E", nxt_errno); + } + + if (nxt_slow_path(close(pipefd[1]) != 0)) { + nxt_alert(task, "failed to close pipe: %E", nxt_errno); + } + return pid; } @@ -230,6 +238,10 @@ nxt_process_create(nxt_task_t *task, nxt_process_t *process) goto fail_cleanup; } + if (nxt_slow_path(close(pipefd[1]) != 0)) { + nxt_alert(task, "failed to close pipe: %E", nxt_errno); + } + process->pid = pid; nxt_runtime_process_add(task, process); -- cgit From f2c0f2899a5c7b853fee716c53795db3b098727a Mon Sep 17 00:00:00 2001 From: Valentin Bartenev Date: Thu, 26 Sep 2019 16:03:02 +0300 Subject: Refactored nxt_process_create() for more explicit pipe closing. --- src/nxt_process.c | 69 +++++++++++++++++++++++-------------------------------- 1 file changed, 29 insertions(+), 40 deletions(-) (limited to 'src') diff --git a/src/nxt_process.c b/src/nxt_process.c index d83eed28..0cc9ccc4 100644 --- a/src/nxt_process.c +++ b/src/nxt_process.c @@ -42,7 +42,8 @@ nxt_bool_t nxt_proc_remove_notify_matrix[NXT_PROCESS_MAX][NXT_PROCESS_MAX] = { static nxt_int_t -nxt_process_worker_setup(nxt_task_t *task, nxt_process_t *process, int parentfd) { +nxt_process_worker_setup(nxt_task_t *task, nxt_process_t *process, int parentfd) +{ pid_t rpid, pid; ssize_t n; nxt_int_t parent_status; @@ -87,11 +88,6 @@ nxt_process_worker_setup(nxt_task_t *task, nxt_process_t *process, int parentfd) return NXT_ERROR; } - if (nxt_slow_path(close(parentfd) == -1)) { - nxt_alert(task, "failed to close reader pipe fd"); - return NXT_ERROR; - } - if (nxt_slow_path(parent_status != NXT_OK)) { return parent_status; } @@ -152,37 +148,26 @@ nxt_process_create(nxt_task_t *task, nxt_process_t *process) init = process->init; #if (NXT_HAVE_CLONE) - pid = nxt_clone(SIGCHLD|init->isolation.clone.flags); -#else - pid = fork(); -#endif - + pid = nxt_clone(SIGCHLD | init->isolation.clone.flags); if (nxt_slow_path(pid < 0)) { -#if (NXT_HAVE_CLONE) nxt_alert(task, "clone() failed while creating \"%s\" %E", init->name, nxt_errno); + goto cleanup; + } #else + pid = fork(); + if (nxt_slow_path(pid < 0)) { nxt_alert(task, "fork() failed while creating \"%s\" %E", init->name, nxt_errno); -#endif - - if (nxt_slow_path(close(pipefd[0]) != 0)) { - nxt_alert(task, "failed to close pipe: %E", nxt_errno); - } - - if (nxt_slow_path(close(pipefd[1]) != 0)) { - nxt_alert(task, "failed to close pipe: %E", nxt_errno); - } - - return pid; + goto cleanup; } +#endif if (pid == 0) { /* Child. */ if (nxt_slow_path(close(pipefd[1]) == -1)) { nxt_alert(task, "failed to close writer pipe fd"); - return NXT_ERROR; } ret = nxt_process_worker_setup(task, process, pipefd[0]); @@ -190,6 +175,10 @@ nxt_process_create(nxt_task_t *task, nxt_process_t *process) exit(1); } + if (nxt_slow_path(close(pipefd[0]) == -1)) { + nxt_alert(task, "failed to close writer pipe fd"); + } + /* * Explicitly return 0 to notice the caller function this is the child. * The caller must return to the event engine work queue loop. @@ -199,10 +188,6 @@ nxt_process_create(nxt_task_t *task, nxt_process_t *process) /* Parent. */ - if (nxt_slow_path(close(pipefd[0]) != 0)) { - nxt_alert(task, "failed to close pipe: %E", nxt_errno); - } - /* * At this point, the child process is blocked reading the * pipe fd to get its real pid (rpid). @@ -219,14 +204,14 @@ nxt_process_create(nxt_task_t *task, nxt_process_t *process) if (nxt_slow_path(write(pipefd[1], &pid, sizeof(pid)) == -1)) { nxt_alert(task, "failed to write real pid"); - goto fail_cleanup; + goto fail; } #if (NXT_HAVE_CLONE_NEWUSER) if ((init->isolation.clone.flags & CLONE_NEWUSER) == CLONE_NEWUSER) { ret = nxt_clone_proc_map(task, pid, &init->isolation.clone); if (nxt_slow_path(ret != NXT_OK)) { - goto fail_cleanup; + goto fail; } } #endif @@ -235,20 +220,16 @@ nxt_process_create(nxt_task_t *task, nxt_process_t *process) if (nxt_slow_path(write(pipefd[1], &ret, sizeof(ret)) == -1)) { nxt_alert(task, "failed to write status"); - goto fail_cleanup; - } - - if (nxt_slow_path(close(pipefd[1]) != 0)) { - nxt_alert(task, "failed to close pipe: %E", nxt_errno); + goto fail; } process->pid = pid; nxt_runtime_process_add(task, process); - return pid; + goto cleanup; -fail_cleanup: +fail: ret = NXT_ERROR; @@ -256,13 +237,21 @@ fail_cleanup: nxt_alert(task, "failed to write status"); } - if (nxt_slow_path(close(pipefd[1]) != 0)) { + waitpid(pid, NULL, 0); + + pid = -1; + +cleanup: + + if (nxt_slow_path(close(pipefd[0]) != 0)) { nxt_alert(task, "failed to close pipe: %E", nxt_errno); } - waitpid(pid, NULL, 0); + if (nxt_slow_path(close(pipefd[1]) != 0)) { + nxt_alert(task, "failed to close pipe: %E", nxt_errno); + } - return -1; + return pid; } -- cgit From f2b280aa0c1e4838c56c9960c717e975a938b1d1 Mon Sep 17 00:00:00 2001 From: Max Romanov Date: Mon, 30 Sep 2019 16:39:08 +0300 Subject: Fixed exiting if a signal arrives during discovery. When Unit starts, the main process waits for module discovery message for a while. If a QUIT signal arrives at this time, the router and controller processes created by main and Unit stay running. Also, the main process doesn't stop them after the second QUIT signal is received in this case. --- src/nxt_main_process.c | 73 ++++++++++++++++++++++++++------------------------ 1 file changed, 38 insertions(+), 35 deletions(-) (limited to 'src') diff --git a/src/nxt_main_process.c b/src/nxt_main_process.c index b9e7ab96..85685fbc 100644 --- a/src/nxt_main_process.c +++ b/src/nxt_main_process.c @@ -1014,52 +1014,50 @@ nxt_main_cleanup_worker_process(nxt_task_t *task, nxt_pid_t pid) nxt_process_close_ports(task, process); - if (!nxt_exiting) { - nxt_runtime_process_each(rt, process) { - - if (process->pid == nxt_pid - || process->pid == pid - || nxt_queue_is_empty(&process->ports)) - { - continue; - } - - port = nxt_process_port_first(process); + if (nxt_exiting) { + if (rt->nprocesses <= 2) { + nxt_runtime_quit(task, 0); + } - if (nxt_proc_remove_notify_matrix[ptype][port->type] == 0) { - continue; - } + return; + } - buf = nxt_buf_mem_ts_alloc(task, task->thread->engine->mem_pool, - sizeof(pid)); - if (nxt_slow_path(buf == NULL)) { - continue; - } + nxt_runtime_process_each(rt, process) { - buf->mem.free = nxt_cpymem(buf->mem.free, &pid, sizeof(pid)); + if (process->pid == nxt_pid + || process->pid == pid + || nxt_queue_is_empty(&process->ports)) + { + continue; + } - nxt_port_socket_write(task, port, NXT_PORT_MSG_REMOVE_PID, - -1, init->stream, 0, buf); - } nxt_runtime_process_loop; - } + port = nxt_process_port_first(process); - if (nxt_exiting) { + if (nxt_proc_remove_notify_matrix[ptype][port->type] == 0) { + continue; + } - if (rt->nprocesses == 2) { - nxt_runtime_quit(task, 0); + buf = nxt_buf_mem_ts_alloc(task, task->thread->engine->mem_pool, + sizeof(pid)); + if (nxt_slow_path(buf == NULL)) { + continue; } - } else if (init != NULL) { - if (init->restart != NULL) { - if (init->type == NXT_PROCESS_ROUTER) { - nxt_main_stop_worker_processes(task, rt); - } + buf->mem.free = nxt_cpymem(buf->mem.free, &pid, sizeof(pid)); - init->restart(task, rt, init); + nxt_port_socket_write(task, port, NXT_PORT_MSG_REMOVE_PID, + -1, init->stream, 0, buf); + } nxt_runtime_process_loop; - } else { - nxt_free(init); + if (init->restart != NULL) { + if (init->type == NXT_PROCESS_ROUTER) { + nxt_main_stop_worker_processes(task, rt); } + + init->restart(task, rt, init); + + } else { + nxt_free(init); } } } @@ -1313,6 +1311,11 @@ nxt_main_port_modules_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg) return; } + if (nxt_exiting) { + nxt_debug(task, "ignoring discovered modules, exiting"); + return; + } + port = nxt_runtime_port_find(task->thread->runtime, msg->port_msg.pid, msg->port_msg.reply_port); -- cgit From 2791c00cf2df1b4c86179756f7c56064219f482f Mon Sep 17 00:00:00 2001 From: Igor Sysoev Date: Mon, 30 Sep 2019 17:17:31 +0300 Subject: Fixed error processing in SSL operations. Before this fix EWOULDBLOCK error was fatal for SSL write operation. This closes #325 issue on GitHub. --- src/nxt_openssl.c | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/nxt_openssl.c b/src/nxt_openssl.c index c01f92c8..53ed0381 100644 --- a/src/nxt_openssl.c +++ b/src/nxt_openssl.c @@ -599,7 +599,6 @@ nxt_openssl_conn_handshake(nxt_task_t *task, void *obj, void *data) default: case NXT_ERROR: - c->socket.error = err; nxt_openssl_conn_error(task, err, "SSL_do_handshake(%d) failed", c->socket.fd); @@ -644,7 +643,6 @@ nxt_openssl_conn_io_recvbuf(nxt_conn_t *c, nxt_buf_t *b) n = nxt_openssl_conn_test_error(c->socket.task, c, ret, err, NXT_OPENSSL_READ); if (n == NXT_ERROR) { - c->socket.error = err; nxt_openssl_conn_error(c->socket.task, err, "SSL_read(%d, %p, %uz) failed", c->socket.fd, b->mem.free, size); @@ -684,13 +682,7 @@ nxt_openssl_conn_io_send(nxt_task_t *task, nxt_sendbuf_t *sb, void *buf, ret = SSL_write(tls->session, buf, size); - if (ret <= 0) { - err = nxt_socket_errno; - sb->error = err; - - } else { - err = 0; - } + err = (ret <= 0) ? nxt_socket_errno : 0; nxt_debug(task, "SSL_write(%d, %p, %uz): %d err:%d", sb->socket, buf, size, ret, err); @@ -701,15 +693,13 @@ nxt_openssl_conn_io_send(nxt_task_t *task, nxt_sendbuf_t *sb, void *buf, c = tls->conn; c->socket.write_ready = sb->ready; - c->socket.error = sb->error; n = nxt_openssl_conn_test_error(task, c, ret, err, NXT_OPENSSL_WRITE); sb->ready = c->socket.write_ready; - sb->error = c->socket.error; if (n == NXT_ERROR) { - sb->error = err; + sb->error = c->socket.error; nxt_openssl_conn_error(task, err, "SSL_write(%d, %p, %uz) failed", sb->socket, buf, size); } @@ -825,7 +815,6 @@ nxt_openssl_conn_io_shutdown(nxt_task_t *task, void *obj, void *data) default: case NXT_ERROR: - c->socket.error = err; nxt_openssl_conn_error(task, err, "SSL_shutdown(%d) failed", c->socket.fd); handler = c->write_state->error_handler; @@ -886,6 +875,7 @@ nxt_openssl_conn_test_error(nxt_task_t *task, nxt_conn_t *c, int ret, nxt_debug(task, "ERR_peek_error(): %l", lib_err); if (sys_err != 0 || lib_err != 0) { + c->socket.error = sys_err; return NXT_ERROR; } -- cgit From 2dbda125db743f71d4dd104b29fa58620eb49de2 Mon Sep 17 00:00:00 2001 From: Valentin Bartenev Date: Mon, 30 Sep 2019 19:11:17 +0300 Subject: HTTP parser: normalization of paths ending with "." or "..". Earlier, the paths were normalized only if there was a "/" at the end, which is wrong according to section 5.2.4 of RFC 3986 and hypothetically may allow to the directory above the document root. --- src/nxt_http_parse.c | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/nxt_http_parse.c b/src/nxt_http_parse.c index 5b009d96..63fd5130 100644 --- a/src/nxt_http_parse.c +++ b/src/nxt_http_parse.c @@ -970,9 +970,11 @@ nxt_http_parse_complex_target(nxt_http_request_parse_t *rp) state = sw_quoted; continue; case '?': + u--; args = p; goto args; case '#': + u--; goto done; default: state = sw_normal; @@ -991,30 +993,42 @@ nxt_http_parse_complex_target(nxt_http_request_parse_t *rp) } switch (ch) { + case '/': - state = sw_slash; + case '?': + case '#': u -= 5; + for ( ;; ) { if (u < rp->path.start) { return NXT_HTTP_PARSE_INVALID; } + if (*u == '/') { u++; break; } + u--; } + + if (ch == '?') { + args = p; + goto args; + } + + if (ch == '#') { + goto done; + } + + state = sw_slash; break; case '%': saved_state = state; state = sw_quoted; continue; - case '?': - args = p; - goto args; - case '#': - goto done; + default: state = sw_normal; *u++ = ch; @@ -1097,8 +1111,14 @@ nxt_http_parse_complex_target(nxt_http_request_parse_t *rp) } } - if (state >= sw_quoted) { - return NXT_HTTP_PARSE_INVALID; + if (state >= sw_dot) { + if (state >= sw_quoted) { + return NXT_HTTP_PARSE_INVALID; + } + + /* "/." and "/.." must be normalized similar to "/./" and "/../". */ + ch = '/'; + goto again; } args: -- cgit From f7d3db314da88be47eeed0a3509368cbe4c5f04f Mon Sep 17 00:00:00 2001 From: Valentin Bartenev Date: Mon, 30 Sep 2019 19:11:17 +0300 Subject: HTTP parser: removed unused "exten" field. This field was intended for MIME type lookup by file extension when serving static files, but this use case is too narrow; only a fraction of requests targets static content, and the URI presumably isn't rewritten. Moreover, current implementation uses the entire filename for MIME type lookup if the file has no extension. Instead of extracting filenames and extensions when parsing requests, it's easier to obtain them right before serving static content; this behavior is already implemented. Thus, we can drop excessive logic from parser. --- src/nxt_http_parse.c | 23 ++--------------------- src/nxt_http_parse.h | 1 - src/test/nxt_http_parse_test.c | 22 ---------------------- 3 files changed, 2 insertions(+), 44 deletions(-) (limited to 'src') diff --git a/src/nxt_http_parse.c b/src/nxt_http_parse.c index 63fd5130..e6e91454 100644 --- a/src/nxt_http_parse.c +++ b/src/nxt_http_parse.c @@ -162,7 +162,7 @@ static nxt_int_t nxt_http_parse_request_line(nxt_http_request_parse_t *rp, u_char **pos, u_char *end) { - u_char *p, ch, *after_slash, *exten, *args; + u_char *p, ch, *after_slash, *args; nxt_int_t rc; nxt_bool_t rest; nxt_http_ver_t ver; @@ -255,7 +255,6 @@ nxt_http_parse_request_line(nxt_http_request_parse_t *rp, u_char **pos, rp->target_start = p; after_slash = p + 1; - exten = NULL; args = NULL; rest = 0; @@ -274,7 +273,6 @@ continue_target: } after_slash = p + 1; - exten = NULL; continue; case NXT_HTTP_TARGET_DOT: @@ -283,7 +281,6 @@ continue_target: goto rest_of_target; } - exten = p + 1; continue; case NXT_HTTP_TARGET_ARGS_MARK: @@ -459,11 +456,6 @@ space_after_target: rp->path.length = rp->target_end - rp->target_start; } - if (exten != NULL) { - rp->exten.length = (rp->path.start + rp->path.length) - exten; - rp->exten.start = exten; - } - return nxt_http_parse_field_name(rp, pos, end); } @@ -846,7 +838,7 @@ static const uint8_t nxt_http_normal[32] nxt_aligned(32) = { static nxt_int_t nxt_http_parse_complex_target(nxt_http_request_parse_t *rp) { - u_char *p, *u, c, ch, high, *exten, *args; + u_char *p, *u, c, ch, high, *args; enum { sw_normal = 0, @@ -872,7 +864,6 @@ nxt_http_parse_complex_target(nxt_http_request_parse_t *rp) rp->path.start = u; high = '\0'; - exten = NULL; args = NULL; while (p < rp->target_end) { @@ -892,7 +883,6 @@ nxt_http_parse_complex_target(nxt_http_request_parse_t *rp) switch (ch) { case '/': - exten = NULL; state = sw_slash; *u++ = ch; continue; @@ -905,10 +895,6 @@ nxt_http_parse_complex_target(nxt_http_request_parse_t *rp) goto args; case '#': goto done; - case '.': - exten = u + 1; - *u++ = ch; - continue; default: *u++ = ch; continue; @@ -1138,11 +1124,6 @@ done: rp->path.length = u - rp->path.start; - if (exten) { - rp->exten.length = u - exten; - rp->exten.start = exten; - } - return NXT_OK; } diff --git a/src/nxt_http_parse.h b/src/nxt_http_parse.h index a307ea73..d7ce5e4f 100644 --- a/src/nxt_http_parse.h +++ b/src/nxt_http_parse.h @@ -44,7 +44,6 @@ struct nxt_http_request_parse_s { nxt_str_t path; nxt_str_t args; - nxt_str_t exten; nxt_http_ver_t version; diff --git a/src/test/nxt_http_parse_test.c b/src/test/nxt_http_parse_test.c index 5498cb1f..8dcbc061 100644 --- a/src/test/nxt_http_parse_test.c +++ b/src/test/nxt_http_parse_test.c @@ -11,7 +11,6 @@ typedef struct { nxt_str_t method; nxt_str_t target; - nxt_str_t exten; nxt_str_t args; u_char version[8]; @@ -66,7 +65,6 @@ static nxt_http_parse_test_case_t nxt_http_test_cases[] = { nxt_string("GET"), nxt_string("/"), nxt_null_string, - nxt_null_string, "HTTP/1.0", 0, 0, 0 }} @@ -78,7 +76,6 @@ static nxt_http_parse_test_case_t nxt_http_test_cases[] = { { .request_line = { nxt_string("XXX-METHOD"), nxt_string("/d.ir/fi+le.ext?key=val"), - nxt_string("ext"), nxt_string("key=val"), "HTTP/1.2", 0, 0, 0 @@ -91,7 +88,6 @@ static nxt_http_parse_test_case_t nxt_http_test_cases[] = { { .request_line = { nxt_string("GET"), nxt_string("/di.r/?"), - nxt_null_string, nxt_string(""), "HTTP/1.0", 0, 0, 0 @@ -135,7 +131,6 @@ static nxt_http_parse_test_case_t nxt_http_test_cases[] = { nxt_string("GET"), nxt_string("/."), nxt_null_string, - nxt_null_string, "HTTP/1.0", 1, 0, 0 }} @@ -148,7 +143,6 @@ static nxt_http_parse_test_case_t nxt_http_test_cases[] = { nxt_string("GET"), nxt_string("/#"), nxt_null_string, - nxt_null_string, "HTTP/1.0", 1, 0, 0 }} @@ -160,7 +154,6 @@ static nxt_http_parse_test_case_t nxt_http_test_cases[] = { { .request_line = { nxt_string("GET"), nxt_string("/?#"), - nxt_null_string, nxt_string(""), "HTTP/1.0", 1, 0, 0 @@ -174,7 +167,6 @@ static nxt_http_parse_test_case_t nxt_http_test_cases[] = { nxt_string("GET"), nxt_string("//"), nxt_null_string, - nxt_null_string, "HTTP/1.0", 1, 0, 0 }} @@ -187,7 +179,6 @@ static nxt_http_parse_test_case_t nxt_http_test_cases[] = { nxt_string("GET"), nxt_string("/%20"), nxt_null_string, - nxt_null_string, "HTTP/1.0", 0, 1, 0 }} @@ -200,7 +191,6 @@ static nxt_http_parse_test_case_t nxt_http_test_cases[] = { nxt_string("GET"), nxt_string("/ a"), nxt_null_string, - nxt_null_string, "HTTP/1.0", 0, 0, 1 }} @@ -212,7 +202,6 @@ static nxt_http_parse_test_case_t nxt_http_test_cases[] = { { .request_line = { nxt_string("GET"), nxt_string("/na %20me.ext?args"), - nxt_string("ext"), nxt_string("args"), "HTTP/1.0", 0, 1, 1 @@ -225,7 +214,6 @@ static nxt_http_parse_test_case_t nxt_http_test_cases[] = { { .request_line = { nxt_string("GET"), nxt_string("/ HTTP/1.0"), - nxt_string("0"), nxt_null_string, "HTTP/1.1", 0, 0, 1 @@ -740,16 +728,6 @@ nxt_http_parse_test_request_line(nxt_http_request_parse_t *rp, return NXT_ERROR; } - if (rp->exten.start != test->exten.start - && !nxt_strstr_eq(&rp->exten, &test->exten)) - { - nxt_log_alert(log, "http parse test case failed:\n" - " - request:\n\"%V\"\n" - " - exten: \"%V\" (expected: \"%V\")", - request, &rp->exten, &test->exten); - return NXT_ERROR; - } - if (rp->args.start != test->args.start && !nxt_strstr_eq(&rp->args, &test->args)) { -- cgit From f8ff71b917452589bdac38ca6e51293fb05f2e8a Mon Sep 17 00:00:00 2001 From: Valentin Bartenev Date: Mon, 30 Sep 2019 19:11:17 +0300 Subject: HTTP: corrected allocation size for tail chunk. --- src/nxt_h1proto.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/nxt_h1proto.c b/src/nxt_h1proto.c index 39be4315..541fcb44 100644 --- a/src/nxt_h1proto.c +++ b/src/nxt_h1proto.c @@ -1293,7 +1293,7 @@ nxt_h1p_chunk_create(nxt_task_t *task, nxt_http_request_t *r, nxt_buf_t *out) for (b = out; b != NULL; b = b->next) { if (nxt_buf_is_last(b)) { - tail = nxt_http_buf_mem(task, r, chunk_size); + tail = nxt_http_buf_mem(task, r, sizeof(tail_chunk)); if (nxt_slow_path(tail == NULL)) { return NULL; } -- cgit From 2eb6f35ef5a5e72e3b16649dc52c55df617d3f0e Mon Sep 17 00:00:00 2001 From: Max Romanov Date: Tue, 1 Oct 2019 19:53:18 +0300 Subject: Go: fixing header buffer size calculation. Header names and values are stored 0-terminated for ease of use in different languages, so magic number 2 should be added to each name-value pair size. --- src/go/unit/response.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/go/unit/response.go b/src/go/unit/response.go index 767d66b7..bb326ea5 100644 --- a/src/go/unit/response.go +++ b/src/go/unit/response.go @@ -63,7 +63,7 @@ func (r *response) WriteHeader(code int) { for k, vv := range r.header { for _, v := range vv { fields++ - fields_size += len(k) + len(v) + fields_size += len(k) + len(v) + 2 } } -- cgit From 73f096f79614403b93f23e7397f312eea49b0938 Mon Sep 17 00:00:00 2001 From: Valentin Bartenev Date: Wed, 2 Oct 2019 20:04:52 +0300 Subject: Added response status code to error page body. Also the error page markup is now valid according to HTML5 specification. All optional tags were omitted. --- src/nxt_http_error.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/nxt_http_error.c b/src/nxt_http_error.c index 1dcd8783..8e8b80f1 100644 --- a/src/nxt_http_error.c +++ b/src/nxt_http_error.c @@ -16,8 +16,12 @@ static const nxt_http_request_state_t nxt_http_request_send_error_body_state; static const char error[] = - "Error" - "Error.\r\n"; + "" + "Error %03d" + "

Error %03d.\r\n"; + +/* Two %03d (4 chars) patterns are replaced by status code (3 chars). */ +#define NXT_HTTP_ERROR_LEN (nxt_length(error) - 2) void @@ -49,7 +53,7 @@ nxt_http_request_error(nxt_task_t *task, nxt_http_request_t *r, nxt_http_field_set(content_type, "Content-Type", "text/html"); r->resp.content_length = NULL; - r->resp.content_length_n = nxt_length(error); + r->resp.content_length_n = NXT_HTTP_ERROR_LEN; r->state = &nxt_http_request_send_error_body_state; @@ -80,15 +84,13 @@ nxt_http_request_send_error_body(nxt_task_t *task, void *obj, void *data) nxt_debug(task, "http request send error body"); - out = nxt_http_buf_mem(task, r, 0); + out = nxt_http_buf_mem(task, r, NXT_HTTP_ERROR_LEN); if (nxt_slow_path(out == NULL)) { goto fail; } - out->mem.start = (u_char *) error; - out->mem.pos = out->mem.start; - out->mem.free = out->mem.start + nxt_length(error); - out->mem.end = out->mem.free; + out->mem.free = nxt_sprintf(out->mem.pos, out->mem.end, error, + r->status, r->status); out->next = nxt_http_buf_last(r); -- cgit From aa910b276ebb06da216232978c295d80359a5316 Mon Sep 17 00:00:00 2001 From: Igor Sysoev Date: Thu, 3 Oct 2019 16:13:13 +0300 Subject: Ignoring EINTR error in kqueue. --- src/nxt_kqueue_engine.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/nxt_kqueue_engine.c b/src/nxt_kqueue_engine.c index 0212b331..9edbc346 100644 --- a/src/nxt_kqueue_engine.c +++ b/src/nxt_kqueue_engine.c @@ -705,7 +705,10 @@ nxt_kqueue_poll(nxt_event_engine_t *engine, nxt_msec_t timeout) nxt_log(&engine->task, level, "kevent(%d) failed %E", engine->u.kqueue.fd, err); - nxt_kqueue_error(engine); + if (err != NXT_EINTR) { + nxt_kqueue_error(engine); + } + return; } -- cgit