Subject: kern/21915: Linux's mkdir(2) emulation bug
To: None <gnats-bugs@gnats.netbsd.org>
From: None <kazu@iijlab.net>
List: netbsd-bugs
Date: 06/17/2003 05:29:50
>Number:         21915
>Category:       kern
>Synopsis:       Linux's mkdir(2) emulation bug
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    kern-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Jun 17 05:31:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:     Kazu Yamamoto
>Release:        1.6T
>Organization:
IIJ
>Environment:
NetBSD hikari.iij.ad.jp 1.6T NetBSD 1.6T (HIKARI) #0: Fri Jun 13 03:32:39 JST 2003  kazu@hikari.iij.ad.jp:/usr/src/sys/arch/i386/compile/HIKARI i386

>Description:
NetBSD's mkdir(2) causes an error (ENOENT) if the first argment ends
with "/". e.g. mkdir("/foo/", mode)

Linux's mkdir(2) succeeds even if the first argment ends with "/".

The Linux emulator of NetBSD does NOT take care of this difference. Consider a Linux application which call mkdir("/foo/", mode). It runs well
on Linux but not on NetBSD's Linux emulation.

I guess other emulations including FreeBSD optentially have the same bug.
I have no idea of other system calls like stat(), open(), ...

>How-To-Repeat:
Compile the following code on Linux and run it on NetBSD like
"a.out /foo/". This operation must succeed.

#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>

main (int argc, char **argv)
{
        mode_t mode, dir_mode;

        mode = (S_IRWXU | S_IRWXG | S_IRWXO) & ~umask(0);
        dir_mode = mode | S_IWUSR | S_IXUSR;

        if (mkdir(argv[1], dir_mode) == -1) {
                perror("");
        }
}

>Fix:
Import the mkdir(1) hack to the Linux emulation.
>Release-Note:
>Audit-Trail:
>Unformatted: