From 7ae5c14d2b4cc2dce023dac9bdf6020962c7bcec Mon Sep 17 00:00:00 2001 From: midipix Date: Tue, 13 Apr 2021 16:46:12 +0000 Subject: library: replace all uses of stat() and lstat() with fstatat() counterparts. --- src/logic/slbt_exec_execute.c | 7 ++++++- src/logic/slbt_exec_install.c | 23 ++++++++++++++++------- src/logic/slbt_exec_link.c | 22 +++++++++++++--------- src/logic/slbt_exec_uninstall.c | 11 ++++++++--- 4 files changed, 43 insertions(+), 20 deletions(-) (limited to 'src/logic') diff --git a/src/logic/slbt_exec_execute.c b/src/logic/slbt_exec_execute.c index bcf0913..91a1cb7 100644 --- a/src/logic/slbt_exec_execute.c +++ b/src/logic/slbt_exec_execute.c @@ -12,6 +12,7 @@ #include #include "slibtool_spawn_impl.h" +#include "slibtool_driver_impl.h" #include "slibtool_errinfo_impl.h" int slbt_exec_execute( @@ -19,6 +20,7 @@ int slbt_exec_execute( struct slbt_exec_ctx * ectx) { int ret; + int fdcwd; char * program; char * script; char * base; @@ -66,8 +68,11 @@ int slbt_exec_execute( mark = exeref + (base - script); sprintf(mark,".libs/%s",base); + /* fdcwd */ + fdcwd = slbt_driver_fdcwd(dctx); + /* swap vector */ - if (!(stat(script,&st)) && !(stat(wrapper,&st))) { + if (!fstatat(fdcwd,script,&st,0) && !fstatat(fdcwd,wrapper,&st,0)) { ectx->cargv[0] = wrapper; ectx->cargv[1] = program; ectx->cargv[2] = exeref; diff --git a/src/logic/slbt_exec_install.c b/src/logic/slbt_exec_install.c index 4aafd0f..5adfd34 100644 --- a/src/logic/slbt_exec_install.c +++ b/src/logic/slbt_exec_install.c @@ -70,12 +70,15 @@ static int slbt_exec_install_init_dstdir( struct argv_entry * last, char * dstdir) { + int fdcwd; struct stat st; char * slash; size_t len; - (void)dctx; + /* fdcwd */ + fdcwd = slbt_driver_fdcwd(dctx); + /* last */ if (dest) last = dest; @@ -95,7 +98,7 @@ static int slbt_exec_install_init_dstdir( return 0; /* is DEST a directory? */ - if (!(stat(dstdir,&st))) + if (!fstatat(fdcwd,dstdir,&st,0)) if (S_ISDIR(st.st_mode)) return 0; @@ -335,6 +338,7 @@ static int slbt_exec_install_entry( char ** dst) { int ret; + int fdcwd; char * dot; char * base; char * slash; @@ -359,10 +363,15 @@ static int slbt_exec_install_entry( entry->arg) >= sizeof(slnkname)) return SLBT_BUFFER_ERROR(dctx); - fexe = stat(slnkname,&st) + /* fdcwd */ + fdcwd = slbt_driver_fdcwd(dctx); + + /* fexe */ + fexe = fstatat(fdcwd,slnkname,&st,0) ? false : true; + /* argument suffix */ dot = strrchr(entry->arg,'.'); /* .lai --> .la */ @@ -389,7 +398,7 @@ static int slbt_exec_install_entry( srcfile) >= sizeof(slnkname)) return SLBT_BUFFER_ERROR(dctx); - if (!stat(slnkname,&st)) { + if (!fstatat(fdcwd,slnkname,&st,0)) { if (slbt_readlink(slnkname,target,sizeof(target)) < 0) return SLBT_SYSTEM_ERROR(dctx,slnkname); @@ -436,7 +445,7 @@ static int slbt_exec_install_entry( /* libfoo.a --> libfoo.so.release */ sprintf(dot,"%s.release",dsosuffix); - frelease = stat(slnkname,&st) ? false : true; + frelease = fstatat(fdcwd,slnkname,&st,0) ? false : true; /* libfoo.a --> libfoo.so */ strcpy(dot,dsosuffix); @@ -460,7 +469,7 @@ static int slbt_exec_install_entry( slnkname) >= sizeof(dstfile)) return SLBT_BUFFER_ERROR(dctx); - fpe = stat(dstfile,&st) ? false : true; + fpe = fstatat(fdcwd,dstfile,&st,0) ? false : true; /* basename */ if ((base = strrchr(slnkname,'/'))) @@ -475,7 +484,7 @@ static int slbt_exec_install_entry( return 0; /* -avoid-version? */ - if (stat(slnkname,&st)) + if (fstatat(fdcwd,slnkname,&st,0)) return SLBT_SYSTEM_ERROR(dctx,slnkname); /* dstfile */ diff --git a/src/logic/slbt_exec_link.c b/src/logic/slbt_exec_link.c index 8b8efa2..e5376b3 100644 --- a/src/logic/slbt_exec_link.c +++ b/src/logic/slbt_exec_link.c @@ -97,6 +97,9 @@ static int slbt_get_deps_meta( struct slbt_map_info * mapinfo; char depfile[PATH_MAX]; + /* fdcwd */ + fdcwd = slbt_driver_fdcwd(dctx); + /* -rpath */ if ((size_t)snprintf(depfile,sizeof(depfile), "%s.slibtool.rpath", @@ -105,7 +108,7 @@ static int slbt_get_deps_meta( return SLBT_BUFFER_ERROR(dctx); /* -Wl,%s */ - if (!(lstat(depfile,&st))) { + if (!fstatat(fdcwd,depfile,&st,AT_SYMLINK_NOFOLLOW)) { depsmeta->infolen += st.st_size + 4; depsmeta->infolen++; } @@ -117,9 +120,6 @@ static int slbt_get_deps_meta( >= sizeof(depfile)) return SLBT_BUFFER_ERROR(dctx); - /* fdcwd */ - fdcwd = slbt_driver_fdcwd(dctx); - /* mapinfo */ if (!(mapinfo = slbt_map_file(fdcwd,depfile,SLBT_MAP_INPUT))) return (fexternal && (errno == ENOENT)) @@ -535,7 +535,7 @@ static int slbt_exec_link_adjust_argument_vector( /* -rpath */ sprintf(rpathlnk,"%s.slibtool.rpath",*carg); - if (!(lstat(rpathlnk,&st))) { + if (!fstatat(fdcwd,rpathlnk,&st,AT_SYMLINK_NOFOLLOW)) { if (slbt_readlink( rpathlnk,\ rpathdir, @@ -590,7 +590,7 @@ static int slbt_exec_link_adjust_argument_vector( } } - if (dpath && !stat(dpath,&st)) { + if (dpath && !fstatat(fdcwd,dpath,&st,0)) { if (!(mapinfo = slbt_map_file( fdcwd,dpath, SLBT_MAP_INPUT))) @@ -975,7 +975,7 @@ static int slbt_exec_link_create_dep_file( mark = strrchr(mark,'.'); strcpy(mark,dctx->cctx->settings.dsosuffix); - fdyndep = !stat(depfile,&st); + fdyndep = !fstatat(fdcwd,depfile,&st,0); /* [-L... as needed] */ if (fdyndep && (ectx->ldirdepth >= 0)) { @@ -1229,9 +1229,13 @@ static int slbt_exec_link_create_noop_symlink( const char * arfilename) { struct stat st; + int fdcwd; + + /* fdcwd */ + fdcwd = slbt_driver_fdcwd(dctx); /* file exists? */ - if (!(lstat(arfilename,&st))) + if (!fstatat(fdcwd,arfilename,&st,AT_SYMLINK_NOFOLLOW)) return 0; /* needed? */ @@ -1752,7 +1756,7 @@ static int slbt_exec_link_create_executable( &depsmeta, SLBT_NESTED_ERROR(dctx)); - if (stat(wrapper,&st)) + if (fstatat(fdcwd,wrapper,&st,0)) return slbt_exec_link_exit( &depsmeta, SLBT_SYSTEM_ERROR(dctx,wrapper)); diff --git a/src/logic/slbt_exec_uninstall.c b/src/logic/slbt_exec_uninstall.c index 28a73b2..9f2521c 100644 --- a/src/logic/slbt_exec_uninstall.c +++ b/src/logic/slbt_exec_uninstall.c @@ -68,13 +68,18 @@ static int slbt_exec_uninstall_fs_entry( uint32_t flags) { struct stat st; + int fdcwd; char * slash; char dpath[PATH_MAX]; + /* fdcwd */ + fdcwd = slbt_driver_fdcwd(dctx); + /* needed? */ - if (stat(path,&st) && (errno == ENOENT)) - if (lstat(path,&st) && (errno == ENOENT)) - return 0; + if (fstatat(fdcwd,path,&st,0) && (errno == ENOENT)) + if (fstatat(fdcwd,path,&st,AT_SYMLINK_NOFOLLOW)) + if (errno == ENOENT) + return 0; /* output */ *parg = path; -- cgit v1.2.3