mirror of
https://git.proxmox.com/git/mirror_lxc
synced 2025-08-06 13:53:14 +00:00
log: create log files in "fuzzing" mode if it's called outside fuzz targets
to make it possible to run the fuzzers along with the other tests Signed-off-by: Evgeny Vereshchagin <evvers@ya.ru>
This commit is contained in:
parent
1667e14e07
commit
4a6af91855
@ -1932,6 +1932,9 @@ init_lxc_static_CFLAGS = $(AM_CFLAGS) -DNO_LXC_CONF
|
||||
if ENABLE_SANITIZERS
|
||||
init_lxc_static_CFLAGS += -fno-sanitize=address,undefined
|
||||
endif
|
||||
if ENABLE_FUZZERS
|
||||
init_lxc_static_CFLAGS += -fno-sanitize=fuzzer-no-link
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
|
@ -508,7 +508,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 (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)
|
||||
@ -521,10 +524,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 (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);
|
||||
|
||||
@ -534,7 +541,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;
|
||||
}
|
||||
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/vfs.h>
|
||||
@ -271,4 +272,28 @@ static inline __u32 copy_struct_to_client(__u32 client_size, void *dst,
|
||||
return size;
|
||||
}
|
||||
|
||||
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
|
||||
static inline int is_in_comm(const char *s)
|
||||
{
|
||||
__do_free char *buf = NULL;
|
||||
__do_free char *comm = NULL;
|
||||
size_t buf_size;
|
||||
|
||||
buf = file_to_buf("/proc/self/comm", &buf_size);
|
||||
if (!buf)
|
||||
return -1;
|
||||
|
||||
if (buf_size == 0)
|
||||
return -1;
|
||||
|
||||
comm = malloc(buf_size + 1);
|
||||
if (!comm)
|
||||
return -1;
|
||||
memcpy(comm, buf, buf_size);
|
||||
comm[buf_size] = '\0';
|
||||
|
||||
return strstr(comm, s) != NULL;
|
||||
}
|
||||
#endif /* FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION */
|
||||
|
||||
#endif /* __LXC_UTILS_H */
|
||||
|
@ -594,6 +594,15 @@ void test_task_blocks_signal(void)
|
||||
return;
|
||||
}
|
||||
|
||||
void test_is_in_comm(void)
|
||||
{
|
||||
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
|
||||
lxc_test_assert_abort(is_in_comm("fuzz-lxc-") == 0);
|
||||
lxc_test_assert_abort(is_in_comm("lxc-test") == 1);
|
||||
lxc_test_assert_abort(is_in_comm("") == 1);
|
||||
#endif /* FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION */
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
test_lxc_string_replace();
|
||||
@ -606,6 +615,7 @@ int main(int argc, char *argv[])
|
||||
test_parse_byte_size_string();
|
||||
test_lxc_config_net_is_hwaddr();
|
||||
test_task_blocks_signal();
|
||||
test_is_in_comm();
|
||||
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user