Skip to content

Commit

Permalink
utils: add O_NOFOLLOW
Browse files Browse the repository at this point in the history
Signed-off-by: Erik Sjölund <[email protected]>
  • Loading branch information
eriksjolund committed Feb 7, 2025
1 parent 4e51077 commit 6598c99
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/libcrun/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -2110,11 +2110,11 @@ copy_recursive_fd_to_fd (int srcdirfd, int dfd, const char *srcname, const char
switch (mode & S_IFMT)
{
case S_IFREG:
srcfd = openat (dirfd (dsrcfd), de->d_name, O_NONBLOCK | O_RDONLY | O_CLOEXEC);
srcfd = openat (dirfd (dsrcfd), de->d_name, O_NONBLOCK | O_RDONLY | O_CLOEXEC | O_NOFOLLOW);
if (UNLIKELY (srcfd < 0))
return crun_make_error (err, errno, "open `%s/%s`", srcname, de->d_name);

destfd = openat (destdirfd, de->d_name, O_RDWR | O_CREAT | O_CLOEXEC, 0777);
destfd = openat (destdirfd, de->d_name, O_RDWR | O_CREAT | O_CLOEXEC | O_NOFOLLOW, 0777);
if (UNLIKELY (destfd < 0))
return crun_make_error (err, errno, "open `%s/%s`", destname, de->d_name);

Expand All @@ -2137,11 +2137,11 @@ copy_recursive_fd_to_fd (int srcdirfd, int dfd, const char *srcname, const char
if (UNLIKELY (ret < 0))
return crun_make_error (err, errno, "mkdir `%s/%s`", destname, de->d_name);

srcfd = openat (dirfd (dsrcfd), de->d_name, O_DIRECTORY | O_CLOEXEC);
srcfd = openat (dirfd (dsrcfd), de->d_name, O_DIRECTORY | O_CLOEXEC | O_NOFOLLOW);
if (UNLIKELY (srcfd < 0))
return crun_make_error (err, errno, "open directory `%s/%s`", srcname, de->d_name);

destfd = openat (destdirfd, de->d_name, O_DIRECTORY | O_CLOEXEC);
destfd = openat (destdirfd, de->d_name, O_DIRECTORY | O_CLOEXEC | O_NOFOLLOW);
if (UNLIKELY (destfd < 0))
return crun_make_error (err, errno, "open directory `%s/%s`", srcname, de->d_name);

Expand Down

0 comments on commit 6598c99

Please sign in to comment.