Subject: Re: standards/19209: test(1)'s -r, -w, and -x don't match POSIX for root (or 4.4BSD, or even V7)
To: NetBSD Bugs and PR posting List <netbsd-bugs@NetBSD.ORG>
From: David Laight <david@l8s.co.uk>
List: netbsd-bugs
Date: 11/30/2002 09:06:36
> + #if defined(SHELL)
> + extern void * ckmalloc(size_t);
> + #else

Bung that in bltin.h

> + static void * ckmalloc(size_t);

Not needed for static function

> + static void *
> + ckmalloc(size_t nbytes)
> + {
> + 	void *p = malloc(nbytes);
> + 
> + 	if (!p)
> + 		error("Not enough memory!");
> + 	return p;
> + }
> + #endif

It would be traditional to let the test program core dump
if malloc fails!
So bltin.h should probably #define malloc chmalloc, although
making it use the shells 'stack' memory allocater might save
memory leaks...

> + 	euid = geteuid();
> + 	if (euid == 0)

I don't think userspace ought to be checking for 'appropriate
privileges' by checking uid == 0.  It is currently true for
netbsd but isn't portably true.

I haven't considered what 'test -r/w/x' should return!

You certainly can't use open(), it doesn't do the correct
thing for devices (the driver gets to see the open....).

Maybe the code should check that access() gives permission
and that one of the relevant rwx flags is set?

access() certainly 'does what you want' for -x.

	David

-- 
David Laight: david@l8s.co.uk