fs: Correctly handle "/" in nxt_fs_mkdir_dirname()

The previous code attempted to mkdir(""), that is an empty string.
Since "/" necessarily exists, just goto out_free.

Fixes: 57fc9201cb ("Socket: Created control socket & pid file directories.")
Link: <https://github.com/nginx/unit/issues/742>
Tested-by: Andy Postnikov <apostnikov@gmail.com>
Tested-by: Andrew Clayton <a.clayton@nginx.com>
Reviewed-by: Andrew Clayton <a.clayton@nginx.com>
Cc: Liam Crilly <liam@nginx.com>
Cc: Konstantin Pavlov <thresh@nginx.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
This commit is contained in:
Alejandro Colomar 2024-04-22 22:40:43 +02:00
parent 7b7b303a72
commit a9aed2044c
No known key found for this signature in database
GPG key ID: 9E8C1AFBBEFFDB32

View file

@ -1,5 +1,6 @@
/*
* Copyright (C) NGINX, Inc.
* Copyright 2024, Alejandro Colomar <alx@kernel.org>
*/
#include <nxt_main.h>
@ -58,7 +59,7 @@ nxt_fs_mkdir_dirname(const u_char *path, mode_t mode)
ret = NXT_OK;
ptr = strrchr(dir, '/');
if (nxt_slow_path(ptr == NULL)) {
if (ptr == dir || nxt_slow_path(ptr == NULL)) {
goto out_free;
}