Skip to content

Commit

Permalink
Merge pull request #720 from giuseppe/nul-terminate-readlinkat-buffer
Browse files Browse the repository at this point in the history
utils: NUL terminate readlinkat buffer
  • Loading branch information
giuseppe authored Aug 25, 2021
2 parents c84d519 + 5399935 commit 139dc69
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- linux: treat pidfd_open failures EINVAL as ESRCH
- cgroup: add support for setting memory.use_hierarchy on cgroup v1.
- Makefile.am: fix link error when using directly libcrun.
- Fix symlink target mangling for tmpcopyup targets.

* crun-0.21

Expand Down
10 changes: 5 additions & 5 deletions src/libcrun/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -1906,18 +1906,18 @@ copy_recursive_fd_to_fd (int srcdirfd, int dfd, const char *srcname, const char
break;

case S_IFLNK:
buf_size = st_size + 1;
target_buf = xmalloc (buf_size);

buf_size = st_size;
do
{
buf_size += 1024;
if (target_buf != NULL)
buf_size += 1024;

target_buf = xrealloc (target_buf, buf_size);
target_buf = xrealloc (target_buf, buf_size + 1);

size = readlinkat (dirfd (dsrcfd), de->d_name, target_buf, buf_size);
if (UNLIKELY (size < 0))
return crun_make_error (err, errno, "readlink `%s/%s`", srcname, de->d_name);
target_buf[size] = '\0';
} while (size == buf_size);

ret = symlinkat (target_buf, destdirfd, de->d_name);
Expand Down

0 comments on commit 139dc69

Please sign in to comment.