Hi,

I have looked at the upstream changes addressing the problem and I
have generated a patch which seems fix the problem completely:

glaubitz@z6:..debian/ksh-93u+> ksh -l
$ pwd
/home/glaubitz/debian/ksh-93u+
$ cd /etc
$ pwd
/etc
$ cd ..
$ pwd
/
$ cd /home/glaubitz/Videos
$ pwd
/home/glaubitz/Videos
$ cd ../Downloads
$ pwd
/home/glaubitz/Downloads
$ echo $KSH_VERSION
Version JM 93u+ 2012-02-29
$

I am attaching the debdiff which drops Jonathan's patch and adds my
new patch with the upstream changes in the last commit.

If you agree, I'll upload the fixed package for t-p-u.

Cheers,

Adrian

-- 
 .''`.  John Paul Adrian Glaubitz
: :' :  Debian Developer - glaub...@debian.org
`. `'   Freie Universitaet Berlin - glaub...@physik.fu-berlin.de
  `-    GPG: 62FF 8A75 84E0 2956 9546  0006 7426 3B37 F5B5 F913
diff -ru ksh-93u+-1.1/debian/changelog ksh-93u+-1.2/debian/changelog
--- ksh-93u+-1.1/debian/changelog	2012-10-13 23:58:47.000000000 +0200
+++ ksh-93u+-1.2/debian/changelog	2013-01-02 18:41:55.256504333 +0100
@@ -1,3 +1,12 @@
+ksh (93u+-1.2) testing-proposed-updates; urgency=low
+
+  * Non-maintainer upload.
+  * Fix handling of cd ../../.. and similar using
+    the upstream changes from ee4582a commit, drop previous patch
+    by Jonathan Wiltshire <j...@debian.org> (Closes: #679966).
+
+ -- John Paul Adrian Glaubitz <glaub...@physik.fu-berlin.de>  Wed, 02 Jan 2013 18:41:22 +0100
+
 ksh (93u+-1.1) testing-proposed-updates; urgency=low
 
   * Non-maintainer upload.
Only in ksh-93u+-1.1/debian/patches: cddotdot.patch
Only in ksh-93u+-1.2/debian/patches: fix-cd-builtin.patch
diff -ru ksh-93u+-1.1/debian/patches/series ksh-93u+-1.2/debian/patches/series
--- ksh-93u+-1.1/debian/patches/series	2012-10-13 23:54:37.000000000 +0200
+++ ksh-93u+-1.2/debian/patches/series	2013-01-02 18:34:31.359970762 +0100
@@ -2,4 +2,4 @@
 cleanup-man-title.patch
 no-rpath.patch
 handle-removed-working-dir.patch
-cddotdot.patch
+fix-cd-builtin.patch
diff -ru ksh-93u+-1.1/.pc/applied-patches ksh-93u+-1.2/.pc/applied-patches
--- ksh-93u+-1.1/.pc/applied-patches	2013-01-02 18:53:45.594190269 +0100
+++ ksh-93u+-1.2/.pc/applied-patches	2013-01-02 18:34:31.367970552 +0100
@@ -2,4 +2,4 @@
 cleanup-man-title.patch
 no-rpath.patch
 handle-removed-working-dir.patch
-cddotdot.patch
+fix-cd-builtin.patch
Only in ksh-93u+-1.1/.pc: cddotdot.patch
Only in ksh-93u+-1.2/.pc: fix-cd-builtin.patch
diff -ru ksh-93u+-1.1/src/cmd/ksh93/bltins/cd_pwd.c ksh-93u+-1.2/src/cmd/ksh93/bltins/cd_pwd.c
--- ksh-93u+-1.1/src/cmd/ksh93/bltins/cd_pwd.c	2013-01-02 18:53:45.000000000 +0100
+++ ksh-93u+-1.2/src/cmd/ksh93/bltins/cd_pwd.c	2013-01-02 18:34:31.000000000 +0100
@@ -112,23 +112,31 @@
 	if(*dir=='.')
 	{
 		/* test for pathname . ./ .. or ../ */
-		if(*(dp=dir+1) == '.')
-			dp++;
-		if(*dp==0 || *dp=='/')
+		int	n=0;
+		char	*sp;
+		for(dp=dir; *dp=='.'; dp++)
 		{
-			if((dp-dir)==2)
+			if(*++dp=='.' && (*++dp=='/' || *dp==0))
+				n++;
+			else if(*dp && *dp!='/')
+				break;
+			if(*dp==0)
+				break;
+		}
+		if(n)	
+		{
+			cdpath = 0;
+			sp = oldpwd + strlen(oldpwd);
+			while(n--)
 			{
-				char *sp;
-				sfputr(shp->strbuf,oldpwd,0);
-				if(*dp)
-					sfputr(shp->strbuf,dp+1,0);
-				sp = sfstruse(shp->strbuf);
-				*(dir=strrchr(sp,'/'))=0;
-				if(*dp)
-					strcpy(dir,dp);
-				dir = (char*)sp;
+				while(--sp > oldpwd && *sp!='/');
+				if(sp==oldpwd)
+					break;
+				
 			}
-			cdpath = 0;
+			sfwrite(shp->strbuf,oldpwd,sp+1-oldpwd);
+			sfputr(shp->strbuf,dp,0);
+			dir = sfstruse(shp->strbuf);
 		}
 	}
 	rval = -1;
@@ -205,6 +213,8 @@
 	if(*dir != '/')
 		return(0);
 	nv_putval(opwdnod,oldpwd,NV_RDONLY);
+	if(oldpwd)
+		free(oldpwd);
 	flag = strlen(dir);
 	/* delete trailing '/' */
 	while(--flag>0 && dir[flag]=='/')
@@ -215,8 +225,6 @@
 	nv_scan(shp->track_tree,rehash,(void*)0,NV_TAGGED,NV_TAGGED);
 	path_newdir(shp,shp->pathlist);
 	path_newdir(shp,shp->cdpathlist);
-	if(oldpwd)
-		free(oldpwd);
 	return(0);
 }
 
Description: fix-cd-builtin
 This patch integrates the changes from the upstream commit
 ee4582a which fixes the built-in cd command which caused
 'cd ..' when the parent directory was the root directory.
 .
 ksh (93u+-1.2) testing-proposed-updates; urgency=low
 .
   * Non-maintainer upload.
   * Fix handling of cd ../../.. and similar using
     the upstream changes from ee4582a commit, drop previous patch
     by Jonathan Wiltshire <j...@debian.org> (Closes: #679966).
Author: John Paul Adrian Glaubitz <glaub...@physik.fu-berlin.de>
Bug-Debian: http://bugs.debian.org/679966

---
The information above should follow the Patch Tagging Guidelines, please
checkout http://dep.debian.net/deps/dep3/ to learn about the format. Here
are templates for supplementary fields that you might want to add:

Origin: <vendor|upstream|other>, <url of original patch>
Bug: <url in upstream bugtracker>
Bug-Debian: http://bugs.debian.org/<bugnumber>
Bug-Ubuntu: https://launchpad.net/bugs/<bugnumber>
Forwarded: <no|not-needed|url proving that it has been forwarded>
Reviewed-By: <name and email of someone who approved the patch>
Last-Update: <YYYY-MM-DD>

--- ksh-93u+.orig/src/cmd/ksh93/bltins/cd_pwd.c
+++ ksh-93u+/src/cmd/ksh93/bltins/cd_pwd.c
@@ -112,20 +112,31 @@ int	b_cd(int argc, char *argv[],Shbltin_
 	if(*dir=='.')
 	{
 		/* test for pathname . ./ .. or ../ */
-		if(*(dp=dir+1) == '.')
-			dp++;
-		if(*dp==0 || *dp=='/')
+		int	n=0;
+		char	*sp;
+		for(dp=dir; *dp=='.'; dp++)
 		{
-			struct stat statb;
-			if((dp-dir)==2)
+			if(*++dp=='.' && (*++dp=='/' || *dp==0))
+				n++;
+			else if(*dp && *dp!='/')
+				break;
+			if(*dp==0)
+				break;
+		}
+		if(n)	
+		{
+			cdpath = 0;
+			sp = oldpwd + strlen(oldpwd);
+			while(n--)
 			{
-				sfprintf(shp->strbuf,oldpwd);
-				dp = sfstruse(shp->strbuf);
-				*strrchr(dp,'/')=0;
-				if(*dp)
-					dir = (char*)dp;
+				while(--sp > oldpwd && *sp!='/');
+				if(sp==oldpwd)
+					break;
+				
 			}
-			cdpath = 0;
+			sfwrite(shp->strbuf,oldpwd,sp+1-oldpwd);
+			sfputr(shp->strbuf,dp,0);
+			dir = sfstruse(shp->strbuf);
 		}
 	}
 	rval = -1;

Reply via email to