Subject: bin/37549: ssshfs in netbsd-4 creates wrong symlinks
To: None <gnats-admin@netbsd.org, netbsd-bugs@netbsd.org>
From: None <dieter.NetBSD@pandora.be>
List: netbsd-bugs
Date: 12/16/2007 12:25:00
>Number:         37549
>Category:       bin
>Synopsis:       ssshfs in netbsd-4 creates wrong symlinks
>Confidential:   no
>Severity:       critical
>Priority:       low
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Dec 16 12:25:00 +0000 2007
>Originator:     dieter roelants
>Release:        NetBSD 4.0_RC4
>Organization:
>Environment:
NetBSD netbsd-u.inflamm.able.be 4.0_RC4 NetBSD 4.0_RC4 (INFLAMM-U) #0: Tue Nov 27 12:46:35 CET 2007  dieter@netbsd-u.inflamm.able.be:/build/obj/sys/arch/i386/compile/INFLAMM-U i386
Architecture: i386
Machine: i386
>Description:
	When creating a symbolic link in a mounted ssshfs (as found
	in share/examples/puffs/ssshfs) the resulting link (if
	there at all) has name and target switched and always points
	to an absolute path.

>How-To-Repeat:

$ mount | grep sss
puffs:ssshfs on /tmp/d type puffs
$ pwd
/tmp/d/mmm
$ ls -l
$ ln -s target symlink
$ ls -l                
total 0
lrwxr-xr-x  1 dieter  wheel  18 Dec 16 13:06 target -> /tmp/d/mmm/symlink

>Fix:
Index: ssshfs.c
===================================================================
RCS file: /cvsroot/src/share/examples/puffs/ssshfs/Attic/ssshfs.c,v
retrieving revision 1.9
diff -u -r1.9 ssshfs.c
--- ssshfs.c	1 Dec 2006 12:50:52 -0000	1.9
+++ ssshfs.c	16 Dec 2007 12:16:10 -0000
@@ -578,18 +578,12 @@
 	if (sftp_proto_version(sftpc) < 3)
 		return EOPNOTSUPP;
 
-	if (*link_target == '/') {
-		strcpy(buf, link_target);
-	} else {
-		strcpy(buf, ssd->name);
-		strcat(buf, "/");
-		strcat(buf, link_target);
-	}
+	strcpy(buf, link_target);
 
 	newssn = makenewnode(ssd, pcn->pcn_name, NULL);
 	puffs_setvattr(&newssn->va, va);
 	a = vattrtoAttrib(va);
-	if ((rv = do_symlink(sftpc, newssn->name, buf)) != 0)
+	if ((rv = do_symlink(sftpc, buf, newssn->name)) != 0)
 		return EIO;
 
 	ssd->dcache |= DCACHE_CHANGED;