diff options
author | Kyungsik Lee <kyungsik.lee@lge.com> | 2016-06-09 18:36:34 +0900 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2016-06-09 14:46:46 -0500 |
commit | 2efbbb33fd4a7774a30722fb73934810dfe37f91 (patch) | |
tree | 2b91f0b6b33a90a71aafcfce0054d77264110424 /toys | |
parent | 2009d0af7081bb42e35db6ff4eb4e39e7474c10c (diff) | |
download | toybox-2efbbb33fd4a7774a30722fb73934810dfe37f91.tar.gz |
Fix dangling link after cp command
"toybuf" should be initialized before calling symlinkat() or
dangling link could occur.
Diffstat (limited to 'toys')
-rw-r--r-- | toys/posix/cp.c | 3 |
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; |