Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 15 Mar 2002 12:14:38 +0100 (CET)
From:      Martin.Kraemer@Fujitsu-Siemens.com
To:        FreeBSD-gnats-submit@FreeBSD.org, tcsh@mx.gw.com, tcsh-bugs@mx.gw.com, submit@bugs.debian.org
Cc:        christos@zoulas.com
Subject:   bin/35921: Wrong path reduction of dot-dot paths in dnormalize()
Message-ID:  <200203151114.g2FBEcW12401@deejai2.mch.fsc.net>

next in thread | raw e-mail | index | archive | help

>Number:         35921
>Category:       bin
>Synopsis:       Wrong path reduction of dot-dot paths in dnormalize()
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Mar 15 03:20:01 PST 2002
>Closed-Date:
>Last-Modified:
>Originator:     
>Release:        FreeBSD 4.5-STABLE i386
>Organization:
Fujitsu-Siemens.com
>Environment:
System: FreeBSD deejai2.mch.fsc.net 4.5-STABLE FreeBSD 4.5-STABLE #6: Thu Jan 31 21:40:04 CET 2002 martin@deejai2.mch.fsc.net:/usr/src/sys/compile/DEEJAI4B i386

>Description:
	This patch tries to fix an error which I discovered
	when compiling a source file. I tried
	    % set symlinks = expand
	    % cc -I../.. blah.c
	and was astonished that the compiler complained about
	a nonexistant file "/home/martin".
	See below for the reason and fix.
	
	It manifests for command line arguments which end in
	"/.." (or contain "/../") but which are not valid
	paths, like "-I../..". This error only happens if
	"set symlinks = expand" is set.
	
	    % cd /usr/local/bin
	    % set symlinks = expand
	    % printf "%s\n" -I. -I../.. -I../../.. ../.. ..
	    -I.
	    /usr/local/bin
	    /usr/local
	    /usr
	    /usr/local
	
	Note that for "-I../.." and "-I../../..", something
	*very* strange has happened: their prefix "-I"
	vanished and they were replaced by an (off-by-one
	depth) absolute path. (That is done in dnormalize()
	which assumes that a relative path exists and can be
	shortened/normalized by removing redundant "../something"
	pairs.
	
	The fix tries to test whether it makes sense to call
	dnormalize() -- it only does if the path is a valid
	path in the first place.
	
	The output after applying the fix is:
	
	    % printf "%s\n" -I. -I../.. -I../../.. ../.. ..
	    -I.
	    -I../..
	    -I../../..
	    /usr
	    /usr/local
	which is what I expected.

>How-To-Repeat:
	% cd /usr/local/bin
	% set symlinks = expand
	% echo -I../..
	/usr/local/bin

>Fix:

Index: sh.dir.c
===================================================================
RCS file: /home/cvs/tcsh/sh.dir.c,v
retrieving revision 1.1.1.6
diff -u -r1.1.1.6 sh.dir.c
--- sh.dir.c	15 Mar 2002 10:30:34 -0000	1.1.1.6
+++ sh.dir.c	15 Mar 2002 11:04:23 -0000
@@ -415,6 +415,18 @@
 	        if ((TRM(cwd[(dotdot = (int) Strlen(cwd)) - 1])) == '/')
 		    cwd[--dotdot] = '\0';
 	    }
+	    /* Reduction of ".." following the stuff we collected in buf
+	     * only makes sense if the directory item in buf really exists.
+	     * Avoid reduction of "-I../.." (typical compiler call) to ""
+	     * or "/usr/nonexistant/../bin" to "/usr/bin":
+	     */
+	    if (cwd[0]) {
+	        struct stat exists;
+		if (0 != stat(short2str(cwd), &exists)) {
+		    xfree((ptr_t) cwd);
+		    return Strsave(start);
+		}
+	    }
 	    if (!*cp)
 	        break;
 	}
>Release-Note:
>Audit-Trail:
>Unformatted:
 Package: tcsh
 Version: 6.11.0
 

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200203151114.g2FBEcW12401>