Re: [PATCH 2/2] libselinux: avoid shadowing 'stat' in load_mmap

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Stephen,

[Re: [PATCH 2/2] libselinux: avoid shadowing 'stat' in load_mmap] On 13.10.21 (Mon 16:36) Stephen Smalley wrote:

> On 10/21/2013 03:16 PM, Joe MacDonald wrote:
> >    label_file.c: In function ‘load_mmap’:
> >    label_file.c:238:81: error: declaration of ‘stat’ shadows a global declaration [-Werror=shadow]
> >    cc1: all warnings being treated as errors
> 
> I don't particularly mind the change, but I neither see this warning nor
> see the underlying issue in the source code - where is the global stat
> declaration?  Is it in some system header file you have on your system?

I'm honestly not sure:

~/external/selinux cscope -L -1 stat
/usr/include/glob.h stat 82 struct stat;
/usr/include/sys/stat.h stat 211 extern int stat (__const char *__restrict __file,
/usr/include/sys/stat.h stat 225 #define stat stat64
/usr/include/sys/stat.h stat 455 __NTH (stat (__const char *__path, struct stat *__statbuf))
/usr/include/bits/stat.h stat 46 struct stat

glob.h is probably implicated, but this test case:

------------------------------------------------------------------------
   #include <glob.h>
   #include <sys/stat.h>

   void testfunc(struct stat *stat)
   {
      ;
   }

   int main (int argc, char *argv)
   {
      struct stat sb;
      testfunc(&sb);
   }
------------------------------------------------------------------------

Compiled with 'gcc -Wshadow foo.c -o foo' builds without warning on my
more recent setup (Debian GNU/Linux 7.2 (wheezy)) but produces the
warning on the older one:

------------------------------------------------------------------------
/tmp gcc -Wshadow foo.c -o foo
foo.c: In function ‘testfunc’:
foo.c:4:28: warning: declaration of ‘stat’ shadows a global declaration [-Wshadow]
/tmp lsb_release -d
Description:    Ubuntu 12.04.3 LTS
------------------------------------------------------------------------

Removing #include <glob.h> doesn't help, though, which I wouldn't really
expect anyway since label_file.c doesn't include it directly anyway.
Maybe it's a gcc version thing?  The failing machine is "gcc
(Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3" whereas the happy one is "gcc
(Debian 4.7.2-5) 4.7.2".

Anyway, as I said in 0/2, I'm confident I'm missing something, I
shouldn't be the first one to trip over this, but I don't know what the
missing piece is, exactly.

-J.

> 
> > 
> > Signed-off-by: Joe MacDonald <joe@xxxxxxxxxxxx>
> > ---
> >  libselinux/src/label_file.c |    8 ++++----
> >  1 file changed, 4 insertions(+), 4 deletions(-)
> > 
> > diff --git a/libselinux/src/label_file.c b/libselinux/src/label_file.c
> > index 51520cf..af7c227 100644
> > --- a/libselinux/src/label_file.c
> > +++ b/libselinux/src/label_file.c
> > @@ -235,7 +235,7 @@ static int process_line(struct selabel_handle *rec,
> >  	return 0;
> >  }
> >  
> > -static int load_mmap(struct selabel_handle *rec, const char *path, struct stat *stat)
> > +static int load_mmap(struct selabel_handle *rec, const char *path, struct stat *sb)
> >  {
> >  	struct saved_data *data = (struct saved_data *)rec->data;
> >  	char mmap_path[PATH_MAX + 1];
> > @@ -266,13 +266,13 @@ static int load_mmap(struct selabel_handle *rec, const char *path, struct stat *
> >  	}
> >  
> >  	/* if mmap is old, ignore it */
> > -	if (mmap_stat.st_mtime < stat->st_mtime) {
> > +	if (mmap_stat.st_mtime < sb->st_mtime) {
> >  		close(mmapfd);
> >  		return -1;
> >  	}
> >  
> > -	if (mmap_stat.st_mtime == stat->st_mtime &&
> > -	    mmap_stat.st_mtim.tv_nsec < stat->st_mtim.tv_nsec) {
> > +	if (mmap_stat.st_mtime == sb->st_mtime &&
> > +	    mmap_stat.st_mtim.tv_nsec < sb->st_mtim.tv_nsec) {
> >  		close(mmapfd);
> >  		return -1;
> >  	}
> > 
> 

-- 
-Joe MacDonald.
:wq

Attachment: signature.asc
Description: Digital signature


[Index of Archives]     [Selinux Refpolicy]     [Linux SGX]     [Fedora Users]     [Fedora Desktop]     [Yosemite Photos]     [Yosemite Camping]     [Yosemite Campsites]     [KDE Users]     [Gnome Users]

  Powered by Linux