From: Nicholas Nethercote Date: Wed, 20 May 2009 02:02:30 +0000 (+0000) Subject: Merge r9993, r9995 (comment changes about vg_stat) from the DARWIN branch, X-Git-Tag: svn/VALGRIND_3_5_0~655 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=7f19e9cb795ed568b9e12805a76012c4135a81bb;p=thirdparty%2Fvalgrind.git Merge r9993, r9995 (comment changes about vg_stat) from the DARWIN branch, and rename all the vg_stat fields to avoid problems that the old names cause on Darwin. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@9996 --- diff --git a/coregrind/m_commandline.c b/coregrind/m_commandline.c index 60c4d3dcc1..e4ab751661 100644 --- a/coregrind/m_commandline.c +++ b/coregrind/m_commandline.c @@ -67,14 +67,14 @@ static HChar* read_dot_valgrindrc ( HChar* dir ) if ( !sr_isError(fd) ) { Int res = VG_(fstat)( sr_Res(fd), &stat_buf ); // Ignore if not owned by current user or world writeable (CVE-2008-4865) - if (!res && stat_buf.st_uid == VG_(geteuid)() - && (!(stat_buf.st_mode & VKI_S_IWOTH))) { - if ( stat_buf.st_size > 0 ) { - f_clo = VG_(malloc)("commandline.rdv.1", stat_buf.st_size+1); + if (!res && stat_buf.uid == VG_(geteuid)() + && (!(stat_buf.mode & VKI_S_IWOTH))) { + if ( stat_buf.size > 0 ) { + f_clo = VG_(malloc)("commandline.rdv.1", stat_buf.size+1); vg_assert(f_clo); - n = VG_(read)(sr_Res(fd), f_clo, stat_buf.st_size); + n = VG_(read)(sr_Res(fd), f_clo, stat_buf.size); if (n == -1) n = 0; - vg_assert(n >= 0 && n <= stat_buf.st_size+1); + vg_assert(n >= 0 && n <= stat_buf.size+1); f_clo[n] = '\0'; } } diff --git a/coregrind/m_debuginfo/debuginfo.c b/coregrind/m_debuginfo/debuginfo.c index 1aa6125e26..d9d9217771 100644 --- a/coregrind/m_debuginfo/debuginfo.c +++ b/coregrind/m_debuginfo/debuginfo.c @@ -645,7 +645,7 @@ ULong VG_(di_notify_mmap)( Addr a, Bool allow_SkFileV ) /* stat dereferences symlinks, so we don't expect it to succeed and yet produce something that is a symlink. */ - vg_assert(sr_isError(statres) || ! VKI_S_ISLNK(statbuf.st_mode)); + vg_assert(sr_isError(statres) || ! VKI_S_ISLNK(statbuf.mode)); /* Don't let the stat call fail silently. Filter out some known sources of noise before complaining, though. */ @@ -662,7 +662,7 @@ ULong VG_(di_notify_mmap)( Addr a, Bool allow_SkFileV ) /* Finally, the point of all this stattery: if it's not a regular file, don't try to read debug info from it. */ - if (! VKI_S_ISREG(statbuf.st_mode)) + if (! VKI_S_ISREG(statbuf.mode)) return 0; /* no uses of statbuf below here. */ @@ -905,7 +905,7 @@ void VG_(di_notify_pdb_debuginfo)( Int fd_obj, Addr avma_obj, if (r == -1) goto out; /* stat failed ?! */ vg_assert(r == 0); - obj_mtime = stat_buf.st_mtime; + obj_mtime = stat_buf.mtime; /* and get its name into exename[]. */ vg_assert(VKI_PATH_MAX > 100); /* to ensure /proc/self/fd/%d is safe */ @@ -954,7 +954,7 @@ void VG_(di_notify_pdb_debuginfo)( Int fd_obj, Addr avma_obj, VG_(message)(Vg_UserMsg, "LOAD_PDB_DEBUGINFO: missing: %s", pdbname); goto out; } - pdb_mtime = stat_buf.st_mtime; + pdb_mtime = stat_buf.mtime; if (pdb_mtime < obj_mtime ) { /* PDB file is older than PE file - ignore it or we will either (a) print wrong stack traces or more likely (b) crash. */ @@ -971,7 +971,7 @@ void VG_(di_notify_pdb_debuginfo)( Int fd_obj, Addr avma_obj, /* Looks promising; go on to try and read stuff from it. */ fd_pdbimage = sr_Res(sres); - n_pdbimage = stat_buf.st_size; + n_pdbimage = stat_buf.size; sres = VG_(am_mmap_file_float_valgrind)( n_pdbimage, VKI_PROT_READ, fd_pdbimage, 0 ); if (sr_isError(sres)) { diff --git a/coregrind/m_debuginfo/readelf.c b/coregrind/m_debuginfo/readelf.c index 6a0329de0f..f80edd6f44 100644 --- a/coregrind/m_debuginfo/readelf.c +++ b/coregrind/m_debuginfo/readelf.c @@ -930,7 +930,7 @@ Addr open_debug_file( Char* name, UInt crc, /*OUT*/UWord* size ) if (VG_(clo_verbosity) > 1) VG_(message)(Vg_DebugMsg, "Reading debug info from %s ..", name); - *size = stat_buf.st_size; + *size = stat_buf.size; sres = VG_(am_mmap_file_float_valgrind) ( *size, VKI_PROT_READ, sr_Res(fd), 0 ); diff --git a/coregrind/m_libcfile.c b/coregrind/m_libcfile.c index 87c1bc85af..0a28224e14 100644 --- a/coregrind/m_libcfile.c +++ b/coregrind/m_libcfile.c @@ -162,22 +162,22 @@ OffT VG_(lseek) ( Int fd, OffT offset, Int whence ) #define TRANSLATE_TO_vg_stat(_p_vgstat, _p_vkistat) \ do { \ - (_p_vgstat)->st_dev = (ULong)( (_p_vkistat)->st_dev ); \ - (_p_vgstat)->st_ino = (ULong)( (_p_vkistat)->st_ino ); \ - (_p_vgstat)->st_nlink = (ULong)( (_p_vkistat)->st_nlink ); \ - (_p_vgstat)->st_mode = (UInt) ( (_p_vkistat)->st_mode ); \ - (_p_vgstat)->st_uid = (UInt) ( (_p_vkistat)->st_uid ); \ - (_p_vgstat)->st_gid = (UInt) ( (_p_vkistat)->st_gid ); \ - (_p_vgstat)->st_rdev = (ULong)( (_p_vkistat)->st_rdev ); \ - (_p_vgstat)->st_size = (Long) ( (_p_vkistat)->st_size ); \ - (_p_vgstat)->st_blksize = (ULong)( (_p_vkistat)->st_blksize ); \ - (_p_vgstat)->st_blocks = (ULong)( (_p_vkistat)->st_blocks ); \ - (_p_vgstat)->st_atime = (ULong)( (_p_vkistat)->st_atime ); \ - (_p_vgstat)->st_atime_nsec = (ULong)( (_p_vkistat)->st_atime_nsec ); \ - (_p_vgstat)->st_mtime = (ULong)( (_p_vkistat)->st_mtime ); \ - (_p_vgstat)->st_mtime_nsec = (ULong)( (_p_vkistat)->st_mtime_nsec ); \ - (_p_vgstat)->st_ctime = (ULong)( (_p_vkistat)->st_ctime ); \ - (_p_vgstat)->st_ctime_nsec = (ULong)( (_p_vkistat)->st_ctime_nsec ); \ + (_p_vgstat)->dev = (ULong)( (_p_vkistat)->st_dev ); \ + (_p_vgstat)->ino = (ULong)( (_p_vkistat)->st_ino ); \ + (_p_vgstat)->nlink = (ULong)( (_p_vkistat)->st_nlink ); \ + (_p_vgstat)->mode = (UInt) ( (_p_vkistat)->st_mode ); \ + (_p_vgstat)->uid = (UInt) ( (_p_vkistat)->st_uid ); \ + (_p_vgstat)->gid = (UInt) ( (_p_vkistat)->st_gid ); \ + (_p_vgstat)->rdev = (ULong)( (_p_vkistat)->st_rdev ); \ + (_p_vgstat)->size = (Long) ( (_p_vkistat)->st_size ); \ + (_p_vgstat)->blksize = (ULong)( (_p_vkistat)->st_blksize ); \ + (_p_vgstat)->blocks = (ULong)( (_p_vkistat)->st_blocks ); \ + (_p_vgstat)->atime = (ULong)( (_p_vkistat)->st_atime ); \ + (_p_vgstat)->atime_nsec = (ULong)( (_p_vkistat)->st_atime_nsec ); \ + (_p_vgstat)->mtime = (ULong)( (_p_vkistat)->st_mtime ); \ + (_p_vgstat)->mtime_nsec = (ULong)( (_p_vkistat)->st_mtime_nsec ); \ + (_p_vgstat)->ctime = (ULong)( (_p_vkistat)->st_ctime ); \ + (_p_vgstat)->ctime_nsec = (ULong)( (_p_vkistat)->st_ctime_nsec ); \ } while (0) SysRes VG_(stat) ( const Char* file_name, struct vg_stat* vgbuf ) @@ -215,12 +215,12 @@ SysRes VG_(stat) ( const Char* file_name, struct vg_stat* vgbuf ) VKI_STX_NORMAL); if (!sr_isError(res)) { VG_(memset)(vgbuf, 0, sizeof(*vgbuf)); - vgbuf->st_dev = (ULong)buf.st_dev; - vgbuf->st_ino = (ULong)buf.st_ino; - vgbuf->st_mode = (UInt)buf.st_mode; - vgbuf->st_uid = (UInt)buf.st_uid; - vgbuf->st_gid = (UInt)buf.st_gid; - vgbuf->st_size = (Long)buf.st_size; + vgbuf->dev = (ULong)buf.st_dev; + vgbuf->ino = (ULong)buf.st_ino; + vgbuf->mode = (UInt)buf.st_mode; + vgbuf->uid = (UInt)buf.st_uid; + vgbuf->gid = (UInt)buf.st_gid; + vgbuf->size = (Long)buf.st_size; } return res; } @@ -271,7 +271,7 @@ Long VG_(fsize) ( Int fd ) { struct vg_stat buf; Int res = VG_(fstat)( fd, &buf ); - return (res == -1) ? (-1LL) : buf.st_size; + return (res == -1) ? (-1LL) : buf.size; } Bool VG_(is_dir) ( HChar* f ) @@ -279,7 +279,7 @@ Bool VG_(is_dir) ( HChar* f ) struct vg_stat buf; SysRes res = VG_(stat)(f, &buf); return sr_isError(res) ? False - : VKI_S_ISDIR(buf.st_mode) ? True : False; + : VKI_S_ISDIR(buf.mode) ? True : False; } SysRes VG_(dup) ( Int oldfd ) @@ -464,19 +464,19 @@ Int VG_(check_executable)(/*OUT*/Bool* is_setuid, return sr_Err(res); } - if ( (st.st_mode & (VKI_S_ISUID | VKI_S_ISGID)) && !allow_setuid ) { + if ( (st.mode & (VKI_S_ISUID | VKI_S_ISGID)) && !allow_setuid ) { if (is_setuid) *is_setuid = True; return VKI_EACCES; } - if (VG_(geteuid)() == st.st_uid) { - if (!(st.st_mode & VKI_S_IXUSR)) + if (VG_(geteuid)() == st.uid) { + if (!(st.mode & VKI_S_IXUSR)) return VKI_EACCES; } else { Int grpmatch = 0; - if (VG_(getegid)() == st.st_gid) + if (VG_(getegid)() == st.gid) grpmatch = 1; else { UInt groups[32]; @@ -484,7 +484,7 @@ Int VG_(check_executable)(/*OUT*/Bool* is_setuid, Int i; /* ngrp will be -1 if VG_(getgroups) failed. */ for (i = 0; i < ngrp; i++) { - if (groups[i] == st.st_gid) { + if (groups[i] == st.gid) { grpmatch = 1; break; } @@ -492,10 +492,10 @@ Int VG_(check_executable)(/*OUT*/Bool* is_setuid, } if (grpmatch) { - if (!(st.st_mode & VKI_S_IXGRP)) { + if (!(st.mode & VKI_S_IXGRP)) { return VKI_EACCES; } - } else if (!(st.st_mode & VKI_S_IXOTH)) { + } else if (!(st.mode & VKI_S_IXOTH)) { return VKI_EACCES; } } diff --git a/coregrind/m_ume/main.c b/coregrind/m_ume/main.c index b2fb502a9e..a32bec7ee5 100644 --- a/coregrind/m_ume/main.c +++ b/coregrind/m_ume/main.c @@ -235,7 +235,7 @@ static Int do_exec_shell_followup(Int ret, HChar* exe_name, ExeInfo* info) // Was it a directory? res = VG_(stat)(exe_name, &st); - if (!sr_isError(res) && VKI_S_ISDIR(st.st_mode)) { + if (!sr_isError(res) && VKI_S_ISDIR(st.mode)) { VG_(printf)("valgrind: %s: is a directory\n", exe_name); // Was it not executable? diff --git a/include/pub_tool_libcfile.h b/include/pub_tool_libcfile.h index 63fb0b39a5..ad1fd04dc3 100644 --- a/include/pub_tool_libcfile.h +++ b/include/pub_tool_libcfile.h @@ -43,24 +43,29 @@ specific vki_stat{,64} kernel structure will work and is consistently available on different architectures on Linux, so we have to use this 'struct vg_stat' impedance-matching type - instead. */ + instead. + + Also note that the fieldnames aren't prefixed with "st_". This is because + st_atime et al are macros in sys/stat.h on Darwin, and using those names + screws things up. +*/ struct vg_stat { - ULong st_dev; - ULong st_ino; - ULong st_nlink; - UInt st_mode; - UInt st_uid; - UInt st_gid; - ULong st_rdev; - Long st_size; - ULong st_blksize; - ULong st_blocks; - ULong st_atime; - ULong st_atime_nsec; - ULong st_mtime; - ULong st_mtime_nsec; - ULong st_ctime; - ULong st_ctime_nsec; + ULong dev; + ULong ino; + ULong nlink; + UInt mode; + UInt uid; + UInt gid; + ULong rdev; + Long size; + ULong blksize; + ULong blocks; + ULong atime; + ULong atime_nsec; + ULong mtime; + ULong mtime_nsec; + ULong ctime; + ULong ctime_nsec; }; extern SysRes VG_(open) ( const Char* pathname, Int flags, Int mode );