From ae3578ca432bb1c179ad7370ca317f1d76d347d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=90o=C3=A0n=20Tr=E1=BA=A7n=20C=C3=B4ng=20Danh?= Date: Sun, 14 Jun 2020 21:49:01 +0700 Subject: [PATCH 1/2] lstat: correct lstat prototype While we're at it, fix a use-after-free for abs_filename. --- src/lstat.c | 9 +++++---- src/lstat.h | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/lstat.c b/src/lstat.c index 3f6d819f..209142d2 100644 --- a/src/lstat.c +++ b/src/lstat.c @@ -28,19 +28,20 @@ #include "lstat.h" -wrapper(lstat, int, (int ver, const char * filename, struct stat * buf)) +wrapper(lstat, int, (const char * filename, struct stat * buf)) { - debug("lstat(%d, \"%s\", &buf)", ver, filename); + char abs_filename[FAKECHROOT_PATH_MAX]; + + debug("lstat(\"%s\", &buf)", filename); if (!fakechroot_localdir(filename)) { if (filename != NULL) { - char abs_filename[FAKECHROOT_PATH_MAX]; rel2abs(filename, abs_filename); filename = abs_filename; } } - return lstat_rel(ver, filename, buf); + return lstat_rel(filename, buf); } diff --git a/src/lstat.h b/src/lstat.h index 751c1ead..ee483033 100644 --- a/src/lstat.h +++ b/src/lstat.h @@ -26,7 +26,7 @@ #ifndef HAVE___LXSTAT -wrapper_proto(lstat, int, (int, const char *, struct stat *)); +wrapper_proto(lstat, int, (const char *, struct stat *)); int lstat_rel(const char *, struct stat *); From dc8b88ddf551ffd96f908fdf9f2cb5c7d2a44be0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=90o=C3=A0n=20Tr=E1=BA=A7n=20C=C3=B4ng=20Danh?= Date: Sun, 14 Jun 2020 21:06:14 +0700 Subject: [PATCH 2/2] stat: allocate common buffer for fakechroot --- src/stat.c | 2 ++ src/stat64.c | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/stat.c b/src/stat.c index 78456620..7b377933 100644 --- a/src/stat.c +++ b/src/stat.c @@ -33,6 +33,8 @@ wrapper(stat, int, (const char * file_name, struct stat * buf)) { + char fakechroot_abspath[FAKECHROOT_PATH_MAX]; + char fakechroot_buf[FAKECHROOT_PATH_MAX]; debug("stat(\"%s\", &buf)", file_name); expand_chroot_path(file_name); return nextcall(stat)(file_name, buf); diff --git a/src/stat64.c b/src/stat64.c index aac9c75f..a360f66f 100644 --- a/src/stat64.c +++ b/src/stat64.c @@ -34,6 +34,8 @@ wrapper(stat64, int, (const char * file_name, struct stat64 * buf)) { + char fakechroot_abspath[FAKECHROOT_PATH_MAX]; + char fakechroot_buf[FAKECHROOT_PATH_MAX]; debug("stat64(\"%s\", &buf)", file_name); expand_chroot_path(file_name); return nextcall(stat64)(file_name, buf);