From 46409d50e5632b28b88cfa4991fffef9adaa490d Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Wed, 15 Jun 2016 15:47:01 -0500 Subject: Add readlink0() and readlinkat0() which null terminate the data. --- toys/posix/cp.c | 3 +-- toys/posix/ps.c | 14 +++++--------- 2 files changed, 6 insertions(+), 11 deletions(-) (limited to 'toys/posix') diff --git a/toys/posix/cp.c b/toys/posix/cp.c index 77e7f132..eafabcd1 100644 --- a/toys/posix/cp.c +++ b/toys/posix/cp.c @@ -251,8 +251,7 @@ 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 && !(toybuf[i] = '\0') && + ? ((i = readlinkat0(tfd, try->name, toybuf, sizeof(toybuf))) && !symlinkat(toybuf, cfd, catch)) : !mknodat(cfd, catch, try->st.st_mode, try->st.st_rdev)) { diff --git a/toys/posix/ps.c b/toys/posix/ps.c index 8ac6eef7..773f40c4 100644 --- a/toys/posix/ps.c +++ b/toys/posix/ps.c @@ -751,9 +751,8 @@ static int get_ps(struct dirtree *new) if (TT.threadparent && TT.threadparent->extra) ptb = (void *)TT.threadparent->extra; - if (j==3 && !ptb) { - if ((len = readlinkat(fd, buf, buf, len))<1) len = 0; - } else { + if (j==3 && !ptb) len = readlinkat0(fd, buf, buf, len); + else { if (j==3) i = strlen(s = ptb->str+ptb->offset[3]); else { if (!ptb || tb->slot[SLOT_argv0len]) ptb = tb; @@ -766,8 +765,8 @@ static int get_ps(struct dirtree *new) } if (i