NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

kern/44523: mount_hfs badly handles file names with slashes in them



>Number:         44523
>Category:       kern
>Synopsis:       mount_hfs badly handles file names with slashes in them
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    kern-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Feb 06 18:00:00 +0000 2011
>Originator:     Taylor R Campbell <campbell+netbsd%mumble.net@localhost>
>Release:        NetBSD 5.1_STABLE
>Organization:
>Environment:
System: NetBSD smalltalk.local 5.1_STABLE NetBSD 5.1_STABLE (RIADEBUG) #0: Tue 
Feb 1 20:28:45 UTC 2011 
root%smalltalk.local@localhost:/home/riastradh/netbsd/5/obj/sys/arch/i386/compile/RIADEBUG
 i386
Architecture: i386
Machine: i386
>Description:

        The kernel's HFS support takes slashes in file names on disk at
        face value and presents them to the userland.  Instead it
        should translate them to colons like Darwin does.

>How-To-Repeat:

        In Finder.app on Mac OS X, create a file in an HFS with a slash
        in its name.  (Alternatively, using any of the BSD subsystem in
        Mac OS X, create a file with a colon in its name.)  Mount the
        file system in NetBSD with mount_hfs or rump_hfs.  Try to use
        the file.  Fail.

>Fix:

        Apply the following patch to hfs_vnops.c to translate between
        slashes and colons: colons are not allowed on disk in the HFS,
        because of the old Macintosh pathname syntax.  (There is some
        trailing whitespace nearby.  If you apply this patch, you may
        want to take the opportunity to fix that while you're at it.)

Index: hfs_vnops.c
===================================================================
RCS file: /cvsroot/src/sys/fs/hfs/hfs_vnops.c,v
retrieving revision 1.18
diff -c -r1.18 hfs_vnops.c
--- hfs_vnops.c 24 Jun 2010 13:03:09 -0000      1.18
+++ hfs_vnops.c 6 Feb 2011 17:48:03 -0000
@@ -399,6 +399,7 @@
        } else {
                hfs_callback_args cbargs;
                uint8_t len;
+               int ni;
 
                hfslib_init_cbargs(&cbargs);
 
@@ -407,6 +408,9 @@
                unicn = malloc(cnp->cn_namelen*sizeof(unicn[0]), M_TEMP, 
M_WAITOK);
                len = utf8_to_utf16(unicn, cnp->cn_namelen,
                                    cnp->cn_nameptr, cnp->cn_namelen, 0, NULL);
+               for (ni = 0; ni < len; ni += 1)
+                       if ((unichar_t)'/' == unicn[ni])
+                               unicn[ni] = (unichar_t)':';
                /* XXX: check conversion errors? */
                if (hfslib_make_catalog_key(VTOH(vdp)->h_rec.u.cnid, len, unicn,
                        &key) == 0) {
@@ -912,6 +916,7 @@
 
 /*printf("numchildren = %i\n", numchildren);*/
        for (curchild = 0; curchild < numchildren && uio->uio_resid>0; 
curchild++) {
+               int ni;
                namlen = utf16_to_utf8(curent.d_name, MAXNAMLEN, 
                                       childnames[curchild].unicode,
                                       childnames[curchild].length,
@@ -921,6 +926,10 @@
                        /* XXX: how to handle name too long? */
                        continue;
                }
+               /* XXX: perhaps check for colons too */
+               for (ni = 0; ni < namlen; ni += 1)
+                       if ('/' == curent.d_name[ni])
+                               curent.d_name[ni] = ':';
                curent.d_namlen = namlen;
                curent.d_reclen = _DIRENT_SIZE(&curent);
                



Home | Main Index | Thread Index | Old Index