From 2efbbb33fd4a7774a30722fb73934810dfe37f91 Mon Sep 17 00:00:00 2001 From: Kyungsik Lee Date: Thu, 9 Jun 2016 18:36:34 +0900 Subject: Fix dangling link after cp command "toybuf" should be initialized before calling symlinkat() or dangling link could occur. --- toys/posix/cp.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'toys') 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; -- cgit v1.2.3