aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--toys/posix/cp.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/toys/posix/cp.c b/toys/posix/cp.c
index 06c537eb..77e7f132 100644
--- a/toys/posix/cp.c
+++ b/toys/posix/cp.c
@@ -252,7 +252,8 @@ int cp_node(struct dirtree *try)
// make symlink, or make block/char/fifo/socket
if (S_ISLNK(try->st.st_mode)
? (0 < (i = readlinkat(tfd, try->name, toybuf, sizeof(toybuf))) &&
- sizeof(toybuf) > i && !symlinkat(toybuf, cfd, catch))
+ sizeof(toybuf) > i && !(toybuf[i] = '\0') &&
+ !symlinkat(toybuf, cfd, catch))
: !mknodat(cfd, catch, try->st.st_mode, try->st.st_rdev))
{
err = 0;