components/ksh93/patches/270-23319761.patch
author Lijo George<lijo.x.george@oracle.com>
Thu, 23 Feb 2017 01:05:08 -0800
changeset 7683 7955769fefe6
parent 7098 a46c4562925e
permissions -rw-r--r--
20855453 ksh93 echo displaying wrong variable value due to missing EIO handling

This fix comes from the community, this patch ports the relevant 
changes from the upstream 2013-10-10-alpha version which fixed the issue.
--- INIT.2012-08-01.old/src/cmd/ksh93/bltins/cd_pwd.c	2016-06-28 04:05:14.983264679 -0700
+++ INIT.2012-08-01/src/cmd/ksh93/bltins/cd_pwd.c	2016-06-28 04:12:16.937817270 -0700
@@ -109,34 +109,20 @@
 		if(!oldpwd)
 			oldpwd = path_pwd(shp,1);
 	}
-	if(*dir=='.')
+	if(*dir!='/')
 	{
-		/* test for pathname . ./ .. or ../ */
-		int	n=0;
-		char	*sp;
-		for(dp=dir; *dp=='.'; dp++)
+		/* check for leading .. */
+		char *cp;
+		sfprintf(shp->strbuf,"%s",dir);
+		cp = sfstruse(shp->strbuf);
+		pathcanon(cp, 0);
+		if(cp[0]=='.' && cp[1]=='.' && (cp[2]=='/' || cp[2]==0))
 		{
-			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--)
-			{
-				while(--sp > oldpwd && *sp!='/');
-				if(sp==oldpwd)
-					break;
-				
-			}
-			sfwrite(shp->strbuf,oldpwd,sp+1-oldpwd);
-			sfputr(shp->strbuf,dp,0);
-			dir = sfstruse(shp->strbuf);
+			if(!shp->strbuf2)
+				shp->strbuf2 = sfstropen();
+			sfprintf(shp->strbuf2,"%s/%s",oldpwd,cp);
+			dir = sfstruse(shp->strbuf2);
+			pathcanon(dir, 0);
 		}
 	}
 	rval = -1;