NetBSD-Bugs archive

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

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

The following reply was made to PR kern/44523; it has been noted by GNATS.

From: Taylor R Campbell <>
Subject: Re: kern/44523 (mount_hfs badly handles file names with slashes in 
Date: Thu, 17 Feb 2011 18:24:38 +0000

    Date: Mon, 14 Feb 2011 01:11:34 +0000 (UTC)
    Before closing this we should also try to get a test written.
 I spent a few minutes today trying to figure out how to build and run
 tests.  I eventually gave up, but here's a trivial test I wrote (and
 haven't tested) for a src/tests/fs/hfs/t_colonslash.c or something, to
 be used with the HFS+ image I made:
 /*     $NetBSD$        */
 #include <sys/types.h>
 #include <sys/mount.h>
 #include <atf-c.h>
 #include <dirent.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <limits.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
 #include <string.h>
 #include <rump/rump.h>
 #include <rump/rump_syscalls.h>
 #include <fs/hfs/hfs.h>
 #include "../../h_macros.h"
 ATF_TC_HEAD(colonslash, tc)
        atf_tc_set_md_var(tc, "descr", "HFS+ colons/slashes (PR kern/44523)");
        atf_tc_set_md_var(tc, "timeout", "2");
 #define IMGNAME "colon.hfs"
 #define FAKEBLK "/dev/blk"
 #define FUNNY_FILENAME "foo:bar"
 ATF_TC_BODY(colonslash, tc)
        struct hfs_args args;
        int dirfd, fd;
        char buf[DIRBLKSIZ];
        struct dirent *dirent;
        int offset, nbytes;
        bool ok = false;
        memset(&args, 0, sizeof args);
        args.fspec = __UNCONST(FAKEBLK);
        if (rump_sys_mkdir("/mp", 0777) == -1)
                atf_tc_fail_errno("cannot create mountpoint");
        rump_pub_etfs_register(FAKEBLK, IMGNAME, RUMP_ETFS_BLK);
        if (rump_sys_mount(MOUNT_HFS, "/mp", 0, &args, sizeof args) == -1)
                atf_tc_fail_errno("rump_sys_mount failed");
        dirfd = rump_sys_open("/mp", O_RDONLY);
        if (dirfd == -1)
                atf_tc_fail_errno("rump_sys_open failed");
        nbytes = rump_sys_getdents(dirfd, buf, sizeof buf);
        if (nbytes == -1)
                atf_tc_fail_errno("rump_sys_getdents failed");
        for (offset = 0; offset < nbytes; offset += dirent->d_reclen) {
                dirent = (struct dirent *)(buf + offset);
                if (!memchr(dirent->d_name, 0, dirent->d_namlen))
                        atf_tc_fail("dirent not null-terminated");
                if (strchr(dirent->d_name, '/'))
                        atf_tc_fail("dirent with slash: %s", dirent->d_name);
                if (0 == strcmp(FUNNY_FILENAME, dirent->d_name))
                        ok = true;
        if (!ok)
                atf_tc_fail("no dirent for file: %s", FUNNY_FILENAME);
        if (rump_sys_close(dirfd) == -1)
                atf_tc_fail_errno("rump_sys_close failed");
        fd = rump_sys_open("/mp/" FUNNY_FILENAME, O_RDONLY);
        if (fd == -1)
                atf_tc_fail_errno("rump_sys_open failed");
        if (rump_sys_close(fd) == -1)
                atf_tc_fail_errno("rump_sys_close failed");
        if (rump_sys_unmount("/mp", 0) == -1)
                atf_tc_fail_errno("rump_sys_unmount failed");
        ATF_TP_ADD_TC(tp, colonslash);
        return 0;

Home | Main Index | Thread Index | Old Index