Subject: bin/34755: Patch for ksh: Append slash when expanding usernames to home directories
To: None <gnats-admin@netbsd.org, netbsd-bugs@netbsd.org>
From: Christian Biere <christianbiere@gmx.de>
List: netbsd-bugs
Date: 10/08/2006 10:20:00
>Number:         34755
>Category:       bin
>Synopsis:       Patch for ksh: Append slash when expanding usernames to home directories
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Sun Oct 08 10:20:00 +0000 2006
>Originator:     Christian Biere
>Release:        NetBSD 4.99.3
>Environment:
System: NetBSD cyclonus 4.99.3 NetBSD 4.99.3 (STARSCREAM) #0: Mon Oct 2 23:04:22 CEST 2006 src@cyclonus:/o/NetBSD/obj/sys/arch/i386/compile/STARSCREAM i386
Architecture: i386
Machine: i386
>Description:
Tab-completion in ksh doesn't append a slash to home directories when
expanding ~user. Since you have to type "~user" anyway ksh doesn't
try to complete user names unlike bash, this is rather annoying
because you usually want to descent into the directory when hitting
tab there, otherwise you could just hit enter or space.
>How-To-Repeat:
Type

 $ ~user<tab>#
 $ /home/user #

Note the space after the expanded path. That's not really useful.

>Fix:

The following modifies homedir() so that it always returns a path with
a trailing slash.

Index: eval.c
===================================================================
RCS file: /cvsroot/src/bin/ksh/eval.c,v
retrieving revision 1.7
diff -u -p -u -r1.7 eval.c
--- eval.c	13 May 2006 21:48:00 -0000	1.7
+++ eval.c	8 Oct 2006 10:09:21 -0000
@@ -1302,11 +1302,19 @@ homedir(name)
 		return NULL;
 #else /* OS2 */
 		struct passwd *pw;
+		size_t n;
 
 		pw = getpwnam(name);
 		if (pw == NULL)
 			return NULL;
-		ap->val.s = str_save(pw->pw_dir, APERM);
+		n = strlen(pw->pw_dir);
+		if (n > 0 && '/' != pw->pw_dir[n - 1]) {
+			ap->val.s = str_nsave(pw->pw_dir, n + 1, APERM);
+			ap->val.s[n] = '/';
+			ap->val.s[n + 1] = '\0';
+		} else {
+			ap->val.s = str_save(pw->pw_dir, APERM);
+		}
 		ap->flag |= DEFINED|ISSET|ALLOC;
 #endif /* OS2 */
 	}