From a9aed2044c6191b93af0199aa77b26ab39cbbad2 Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Mon, 22 Apr 2024 22:40:43 +0200 Subject: 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: 57fc9201cb91 ("Socket: Created control socket & pid file directories.") Link: Tested-by: Andy Postnikov Tested-by: Andrew Clayton Reviewed-by: Andrew Clayton Cc: Liam Crilly Cc: Konstantin Pavlov Signed-off-by: Alejandro Colomar --- src/nxt_fs.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/nxt_fs.c b/src/nxt_fs.c index 6a93c670..788c3ee2 100644 --- a/src/nxt_fs.c +++ b/src/nxt_fs.c @@ -1,5 +1,6 @@ /* * Copyright (C) NGINX, Inc. + * Copyright 2024, Alejandro Colomar */ #include @@ -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; } -- cgit