]> git.kaiwu.me - nginx.git/commitdiff
Core: working_directory validation
authorSergey Kandaurov <pluknet@nginx.com>
Mon, 19 Oct 2026 15:53:30 +0000 (15:53 +0000)
committerSergey Kandaurov <pluknet@nginx.com>
Wed, 21 Oct 2026 07:48:28 +0000 (11:48 +0400)
Previously, an invalid working_directory was only detected on worker
process startup: if chdir() failed, worker processes exited and were
not respawned, while "nginx -t" reported success.

Now the directory is checked during configuration parsing.  Note that
this doesn't cover insufficient permissions for worker processes.

src/core/nginx.c

index 88f22483f1677f308ebab531690d1d70a53e66cb..464911f60614ce39e94c6dc98ab7c00c1e93994e 100644 (file)
@@ -1232,9 +1232,25 @@ ngx_core_module_init_conf(ngx_cycle_t *cycle, void *conf)
 
 
     if (ccf->working_directory.len) {
+        ngx_file_info_t  fi;
+
         if (ngx_conf_full_name(cycle, &ccf->working_directory, 0) != NGX_OK) {
             return NGX_CONF_ERROR;
         }
+
+        if (ngx_file_info(ccf->working_directory.data, &fi) == NGX_FILE_ERROR) {
+            ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
+                          ngx_file_info_n " \"%s\" failed",
+                          ccf->working_directory.data);
+            return NGX_CONF_ERROR;
+        }
+
+        if (!ngx_is_dir(&fi)) {
+            ngx_log_error(NGX_LOG_EMERG, cycle->log, 0,
+                          "\"%s\" is not a directory",
+                          ccf->working_directory.data);
+            return NGX_CONF_ERROR;
+        }
     }