RPM Community Forums

Mailing List Message of <rpm-devel>

Re: [CVS] RPM: rpm/lib/ fs.c

From: Jeff Johnson <n3npq@mac.com>
Date: Sat 11 Oct 2008 - 21:05:08 CEST
Message-id: <4247D61F-F2D9-4858-9851-C8C74BA69FB3@mac.com>
There's likely a few more details on non-linux persuasions of accessing
the mount table that might need filtering.

Still, I'd rather see general errno filtering than discuss uglix  
leakage issues
because rpm is (correctly imho) printing stat(2) failures that are  
"annoying".

73 de Jeff

On Oct 11, 2008, at 2:53 PM, Jeff Johnson wrote:

>   RPM Package Manager, CVS Repository
>   http://rpm5.org/cvs/
>    
> ______________________________________________________________________ 
> ______
>
>   Server: rpm5.org                         Name:   Jeff Johnson
>   Root:   /v/rpm/cvs                       Email:  jbj@rpm5.org
>   Module: rpm                              Date:   11-Oct-2008  
> 20:53:38
>   Branch: HEAD                             Handle: 2008101118533800
>
>   Modified files:
>     rpm/lib                 fs.c
>
>   Log:
>     - jbj: use a switch on errno to make leakage pathology  
> filtering easier.
>     - jbj: use Stat(2) for --rpmiodebug tracing.
>
>   Summary:
>     Revision    Changes     Path
>     2.68        +26 -18     rpm/lib/fs.c
>    
> ______________________________________________________________________ 
> ______
>
>   patch -p0 <<'@@ .'
>   Index: rpm/lib/fs.c
>    
> ====================================================================== 
> ======
>   $ cvs diff -u -r2.67 -r2.68 fs.c
>   --- rpm/lib/fs.c	11 Oct 2008 18:29:45 -0000	2.67
>   +++ rpm/lib/fs.c	11 Oct 2008 18:53:38 -0000	2.68
>   @@ -112,14 +112,19 @@
>    	filesystems[i].mntPoint = fsnames[i] = fsn;
>    	
>    #if defined(RPM_VENDOR_OPENPKG) /* always-skip-proc-filesystem */
>   -	if (!(strcmp(filesystems[i].mntPoint, "/proc") == 0)) {
>   +	if (!(strcmp(fsn, "/proc") == 0)) {
>    #endif
>   -	if (stat(filesystems[i].mntPoint, &sb)) {
>   -	    rpmlog(RPMLOG_ERR, _("failed to stat %s: %s\n"), fsnames[i],
>   +	if (Stat(fsn, &sb) < 0) {
>   +	    switch(errno) {
>   +	    default:
>   +		rpmlog(RPMLOG_ERR, _("failed to stat %s: %s\n"), fsn,
>    			strerror(errno));
>   -
>   -	    rpmFreeFilesystems();
>   -	    return 1;
>   +		rpmFreeFilesystems();
>   +		return 1;
>   +	    case ENOENT:	/* XXX avoid /proc if leaked into *BSD jails. */
>   +		sb.st_dev = 0;	/* XXXX make sure st_dev is initialized. */
>   +		/*@switchbreak@*/ break;
>   +	    }
>    	}
>    	
>    	filesystems[i].dev = sb.st_dev;
>   @@ -225,7 +230,7 @@
>    		continue;
>    #endif
>
>   -	if (stat(mntdir, &sb)) {
>   +	if (Stat(mntdir, &sb) < 0) {
>    	    switch(errno) {
>    	    default:
>    		rpmlog(RPMLOG_ERR, _("failed to stat %s: %s\n"), mntdir,
>   @@ -308,10 +313,11 @@
>        int lastfs = 0;
>        dev_t lastDev = (dev_t)-1;		/* I hope nobody uses -1 for a  
> st_dev */
>        struct stat sb;
>   +    int rc = 1;		/* assume failure */
>
>        if (!fsnames)
>    	if (getFilesystemList())
>   -	    return 1;
>   +	    return rc;
>
>        usages = xcalloc(numFilesystems, sizeof(*usages));
>
>   @@ -346,13 +352,15 @@
>    	if (strcmp(lastDir, buf)) {
>    	    strcpy(dirName, buf);
>    	    chptr = dirName + strlen(dirName) - 1;
>   -	    while (stat(dirName, &sb)) {
>   -		if (errno != ENOENT) {
>   +	    while (Stat(dirName, &sb) < 0) {
>   +		switch(errno) {
>   +		default:
>    		    rpmlog(RPMLOG_ERR, _("failed to stat %s: %s\n"), buf,
>    				strerror(errno));
>   -		    sourceDir = _free(sourceDir);
>   -		    usages = _free(usages);
>   -		    return 1;
>   +		    goto exit;
>   +		    /*@notreached@*/ /*@switchbreak@*/ break;
>   +		case ENOENT:	/* XXX paths in empty chroot's don't exist. */
>   +		    /*@switchbreak@*/ break;
>    		}
>
>    		/* cut off last directory part, because it was not found. */
>   @@ -372,9 +380,7 @@
>    		if (j == numFilesystems) {
>    		    rpmlog(RPMLOG_ERR,
>    				_("file %s is on an unknown device\n"), buf);
>   -		    sourceDir = _free(sourceDir);
>   -		    usages = _free(usages);
>   -		    return 1;
>   +		    goto exit;
>    		}
>
>    		lastfs = j;
>   @@ -385,14 +391,16 @@
>    	strcpy(lastDir, buf);
>    	usages[lastfs] += fssizes[i];
>        }
>   +    rc = 0;
>
>   +exit:
>        sourceDir = _free(sourceDir);
>
>   -    if (usagesPtr)
>   +    if (rc == 0 && usagesPtr)
>    	*usagesPtr = usages;
>        else
>    	usages = _free(usages);
>
>   -    return 0;
>   +    return rc;
>    }
>    /*@=usereleased =onlytrans@*/
>   @@ .
> ______________________________________________________________________
> RPM Package Manager                                    http://rpm5.org
> CVS Sources Repository                                rpm-cvs@rpm5.org
Received on Sat Oct 11 21:05:22 2008
Driven by Jeff Johnson and the RPM project team.
Hosted by OpenPKG and Ralf S. Engelschall.
Powered by FreeBSD and OpenPKG.