mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Samuel Holland <samuel@sholland.org>
To: Rich Felker <dalias@libc.org>, musl@lists.openwall.com
Cc: Samuel Holland <samuel@sholland.org>
Subject: [PATCH] use the correct stat structure in the fstat path
Date: Sat, 20 Jul 2019 23:52:26 -0500	[thread overview]
Message-ID: <20190721045226.48772-1-samuel@sholland.org> (raw)

commit 01ae3fc6d48f4a45535189b7a6db286535af08ca modified fstatat to
translate the kernel's struct stat ("kstat") into the libc struct stat.
To do this, it created a local kstat object, and copied its contents
into the user-provided object.

However, the commit neglected to update the fstat compatibility path and
its fallbacks. They continued to pass the user-supplied object to the
kernel, later overwiting it with the uninitialized memory in the local
temporary.
---
 src/stat/fstatat.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/stat/fstatat.c b/src/stat/fstatat.c
index 7de75462..d915fa10 100644
--- a/src/stat/fstatat.c
+++ b/src/stat/fstatat.c
@@ -67,16 +67,16 @@ static int fstatat_kstat(int fd, const char *restrict path, struct stat *restric
 	struct kstat kst;
 
 	if (flag==AT_EMPTY_PATH && fd>=0 && !*path) {
-		ret = __syscall(SYS_fstat, fd, st);
+		ret = __syscall(SYS_fstat, fd, &kst);
 		if (ret==-EBADF && __syscall(SYS_fcntl, fd, F_GETFD)>=0) {
-			ret = __syscall(SYS_fstatat, fd, path, st, flag);
+			ret = __syscall(SYS_fstatat, fd, path, &kst, flag);
 			if (ret==-EINVAL) {
 				char buf[15+3*sizeof(int)];
 				__procfdname(buf, fd);
 #ifdef SYS_stat
-				ret = __syscall(SYS_stat, buf, st);
+				ret = __syscall(SYS_stat, buf, &kst);
 #else
-				ret = __syscall(SYS_fstatat, AT_FDCWD, buf, st, 0);
+				ret = __syscall(SYS_fstatat, AT_FDCWD, buf, &kst, 0);
 #endif
 			}
 		}
-- 
2.21.0



                 reply	other threads:[~2019-07-21  4:52 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190721045226.48772-1-samuel@sholland.org \
    --to=samuel@sholland.org \
    --cc=dalias@libc.org \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).