]> git.proxmox.com Git - mirror_lxc.git/blobdiff - src/lxc/log.c
github: Update for main branch
[mirror_lxc.git] / src / lxc / log.c
index 4733fcdeb12afa1fcc6666b51dc831c5d51a6ca7..cdd11ff1c084c0cad8bb7f15b702092d0cf38c86 100644 (file)
@@ -1,9 +1,7 @@
 /* SPDX-License-Identifier: LGPL-2.1+ */
 
-#ifndef _GNU_SOURCE
-#define _GNU_SOURCE 1
-#endif
-#define __STDC_FORMAT_MACROS /* Required for PRIu64 to work. */
+#include "config.h"
+
 #include <errno.h>
 #include <fcntl.h>
 #include <inttypes.h>
 #include <syslog.h>
 #include <unistd.h>
 
+#include "lxc.h"
+
 #include "caps.h"
-#include "config.h"
 #include "file_utils.h"
 #include "log.h"
-#include "lxccontainer.h"
 #include "memory_utils.h"
 #include "utils.h"
 
-#ifndef HAVE_STRLCPY
-#include "include/strlcpy.h"
+#if !HAVE_STRLCPY
+#include "strlcpy.h"
 #endif
 
 #if HAVE_DLOG
@@ -492,9 +490,6 @@ static int build_dir(const char *name)
        if (is_empty_string(name))
                return ret_errno(EINVAL);
 
-       if (!abspath(name))
-               return ret_errno(EINVAL);
-
        /* Make copy of the string since we'll be modifying it. */
        n = strdup(name);
        if (!n)
@@ -511,7 +506,10 @@ static int build_dir(const char *name)
 #ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
                ret = lxc_unpriv(mkdir(n, 0755));
 #else
-               ret = errno = EEXIST;
+               if (RUN_ON_OSS_FUZZ || is_in_comm("fuzz-lxc-") > 0)
+                       ret = errno = EEXIST;
+               else
+                       ret = lxc_unpriv(mkdir(n, 0755));
 #endif /*!FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION */
                *p = '/';
                if (ret && errno != EEXIST)
@@ -524,10 +522,14 @@ static int build_dir(const char *name)
 static int log_open(const char *name)
 {
        int newfd = -EBADF;
-#ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
        __do_close int fd = -EBADF;
 
+#ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
        fd = lxc_unpriv(open(name, O_CREAT | O_WRONLY | O_APPEND | O_CLOEXEC, 0660));
+#else
+       if (!RUN_ON_OSS_FUZZ && is_in_comm("fuzz-lxc-") <= 0)
+               fd = lxc_unpriv(open(name, O_CREAT | O_WRONLY | O_APPEND | O_CLOEXEC, 0660));
+#endif /* !FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION */
        if (fd < 0)
                return log_error_errno(-errno, errno, "Failed to open log file \"%s\"", name);
 
@@ -537,7 +539,6 @@ static int log_open(const char *name)
        newfd = fcntl(fd, F_DUPFD_CLOEXEC, STDERR_FILENO);
        if (newfd < 0)
                return log_error_errno(-errno, errno, "Failed to dup log fd %d", fd);
-#endif /* !FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION */
        return newfd;
 }