Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/libcrun/chroot_realpath.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

#define MAX_READLINKS 32

char *chroot_realpath(const char *chroot, const char *path, char resolved_path[])
char *chroot_realpath(const char *chroot, const char *path, char resolved_path[],size_t size_resolved_path)
{
char copy_path[PATH_MAX];
char link_path[PATH_MAX];
Expand Down Expand Up @@ -135,7 +135,7 @@ char *chroot_realpath(const char *chroot, const char *path, char resolved_path[]
if (n < 0) {
/* If a component doesn't exist, then return what we could translate. */
if (errno == ENOENT) {
int ret = snprintf (resolved_path, PATH_MAX, "%s%s%s", got_path, path[0] == '/' || path[0] == '\0' ? "" : "/", path);
int ret = snprintf (resolved_path, size_resolved_path, "%s%s%s", got_path, path[0] == '/' || path[0] == '\0' ? "" : "/", path);
if (ret >= PATH_MAX) {
__set_errno(ENAMETOOLONG);
return NULL;
Expand Down
6 changes: 3 additions & 3 deletions src/libcrun/criu.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
# endif

/* Defined in chroot_realpath.c */
char *chroot_realpath (const char *chroot, const char *path, char resolved_path[]);
char *chroot_realpath (const char *chroot, const char *path, char resolved_path[], size_t size_resolved_path);

static const char *console_socket = NULL;

Expand Down Expand Up @@ -640,7 +640,7 @@ libcrun_container_checkpoint_linux_criu (libcrun_container_status_t *status, lib
if (nofollow)
return crun_make_error (err, 0, "CRIU does not support `src-nofollow` for bind mounts");

dest_in_root = chroot_realpath (status->rootfs, def->mounts[i]->destination, buf);
dest_in_root = chroot_realpath (status->rootfs, def->mounts[i]->destination, buf, sizeof (buf));
if (UNLIKELY (dest_in_root == NULL))
{
if (errno != ENOENT)
Expand Down Expand Up @@ -971,7 +971,7 @@ libcrun_container_restore_linux_criu (libcrun_container_status_t *status, libcru
if (nofollow)
return crun_make_error (err, 0, "CRIU does not support `src-nofollow` for bind mounts");

dest_in_root = chroot_realpath (status->rootfs, def->mounts[i]->destination, buf);
dest_in_root = chroot_realpath (status->rootfs, def->mounts[i]->destination, buf, sizeof (buf));
if (UNLIKELY (dest_in_root == NULL))
{
if (errno != ENOENT)
Expand Down
18 changes: 9 additions & 9 deletions src/libcrun/ebpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,32 +61,32 @@ struct bpf_program
#ifdef HAVE_EBPF

# define BPF_ALU32_IMM(OP, DST, IMM) \
((struct bpf_insn) { .code = BPF_ALU | BPF_OP (OP) | BPF_K, .dst_reg = DST, .src_reg = 0, .off = 0, .imm = IMM })
((struct bpf_insn){ .code = BPF_ALU | BPF_OP (OP) | BPF_K, .dst_reg = DST, .src_reg = 0, .off = 0, .imm = IMM })

# define BPF_LDX_MEM(SIZE, DST, SRC, OFF) \
((struct bpf_insn) { \
((struct bpf_insn){ \
.code = BPF_LDX | BPF_SIZE (SIZE) | BPF_MEM, .dst_reg = DST, .src_reg = SRC, .off = OFF, .imm = 0 })

# define BPF_MOV64_REG(DST, SRC) \
((struct bpf_insn) { .code = BPF_ALU64 | BPF_MOV | BPF_X, .dst_reg = DST, .src_reg = SRC, .off = 0, .imm = 0 })
((struct bpf_insn){ .code = BPF_ALU64 | BPF_MOV | BPF_X, .dst_reg = DST, .src_reg = SRC, .off = 0, .imm = 0 })

# define BPF_JMP_A(OFF) \
((struct bpf_insn) { .code = BPF_JMP | BPF_JA, .dst_reg = 0, .src_reg = 0, .off = OFF, .imm = 0 })
((struct bpf_insn){ .code = BPF_JMP | BPF_JA, .dst_reg = 0, .src_reg = 0, .off = OFF, .imm = 0 })

# define BPF_JMP_IMM(OP, DST, IMM, OFF) \
((struct bpf_insn) { .code = BPF_JMP | BPF_OP (OP) | BPF_K, .dst_reg = DST, .src_reg = 0, .off = OFF, .imm = IMM })
((struct bpf_insn){ .code = BPF_JMP | BPF_OP (OP) | BPF_K, .dst_reg = DST, .src_reg = 0, .off = OFF, .imm = IMM })

# define BPF_JMP_REG(OP, DST, SRC, OFF) \
((struct bpf_insn) { .code = BPF_JMP | BPF_OP (OP) | BPF_X, .dst_reg = DST, .src_reg = SRC, .off = OFF, .imm = 0 })
((struct bpf_insn){ .code = BPF_JMP | BPF_OP (OP) | BPF_X, .dst_reg = DST, .src_reg = SRC, .off = OFF, .imm = 0 })

# define BPF_MOV64_IMM(DST, IMM) \
((struct bpf_insn) { .code = BPF_ALU64 | BPF_MOV | BPF_K, .dst_reg = DST, .src_reg = 0, .off = 0, .imm = IMM })
((struct bpf_insn){ .code = BPF_ALU64 | BPF_MOV | BPF_K, .dst_reg = DST, .src_reg = 0, .off = 0, .imm = IMM })

# define BPF_MOV32_REG(DST, SRC) \
((struct bpf_insn) { .code = BPF_ALU | BPF_MOV | BPF_X, .dst_reg = DST, .src_reg = SRC, .off = 0, .imm = 0 })
((struct bpf_insn){ .code = BPF_ALU | BPF_MOV | BPF_X, .dst_reg = DST, .src_reg = SRC, .off = 0, .imm = 0 })

# define BPF_EXIT_INSN() \
((struct bpf_insn) { .code = BPF_JMP | BPF_EXIT, .dst_reg = 0, .src_reg = 0, .off = 0, .imm = 0 })
((struct bpf_insn){ .code = BPF_JMP | BPF_EXIT, .dst_reg = 0, .src_reg = 0, .off = 0, .imm = 0 })
#endif

#ifdef HAVE_EBPF
Expand Down
10 changes: 5 additions & 5 deletions src/libcrun/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ close_and_replace (int *oldfd, int newfd)
}

/* Defined in chroot_realpath.c */
char *chroot_realpath (const char *chroot, const char *path, char resolved_path[]);
char *chroot_realpath (const char *chroot, const char *path, char resolved_path[], size_t size_resolved_path);

static int
safe_openat_fallback (int dirfd, const char *rootfs, const char *path, int flags,
Expand All @@ -359,7 +359,7 @@ safe_openat_fallback (int dirfd, const char *rootfs, const char *path, int flags
size_t rootfs_len = strlen (rootfs);
int ret;

path_in_chroot = chroot_realpath (rootfs, path, buffer);
path_in_chroot = chroot_realpath (rootfs, path, buffer, sizeof (buffer));
if (path_in_chroot == NULL)
return crun_make_error (err, errno, "cannot resolve `%s` under rootfs", path);

Expand Down Expand Up @@ -2297,9 +2297,9 @@ copy_recursive_fd_to_fd (int srcdirfd, int dfd, const char *srcname, const char
if (UNLIKELY (ret < 0))
return crun_make_error (err, errno, "fchownat `%s/%s`", destname, de->d_name);

/*
* ALLPERMS is not defined by POSIX
*/
/*
* ALLPERMS is not defined by POSIX
*/
#ifndef ALLPERMS
# define ALLPERMS (S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO)
#endif
Expand Down
2 changes: 1 addition & 1 deletion tests/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ memhog (int megabytes)
while (1)
{
/* change one page each 0.1 seconds */
nanosleep ((const struct timespec[]) { { 0, 100000000L } }, NULL);
nanosleep ((const struct timespec[]){ { 0, 100000000L } }, NULL);
buf[pos] = 'c';
pos += sysconf (_SC_PAGESIZE);
if (pos > megabytes * 1024 * 1024)
Expand Down
6 changes: 3 additions & 3 deletions tests/tests_libcrun_fuzzer.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ test_generate_ebpf (uint8_t *buf, size_t len)
return 0;
}

char *chroot_realpath (const char *chroot, const char *path, char resolved_path[]);
char *chroot_realpath (const char *chroot, const char *path, char resolved_path[], size_t size_resolved_path);

static int
test_chroot_realpath (uint8_t *buf, size_t len)
Expand All @@ -123,7 +123,7 @@ test_chroot_realpath (uint8_t *buf, size_t len)
if (path == NULL)
return 0;

chroot_realpath (".", path, resolved_path);
chroot_realpath (".", path, resolved_path, sizeof (resolved_path));
(void) resolved_path;
return 0;
}
Expand Down Expand Up @@ -496,7 +496,7 @@ main (int argc, char **argv)
return LLVMFuzzerTestOneInput (content, len);
}
#ifdef FUZZER
extern void HF_ITER (uint8_t **buf, size_t *len);
extern void HF_ITER (uint8_t * *buf, size_t * len);
for (;;)
{
size_t len;
Expand Down
Loading