[comp.sys.att] C compiler bugs on 386 and 3B2

friedl@mtndew.Tustin.CA.US (Steve Friedl) (09/21/90)

Hi folks,

     Two problems with the C compiler on the 386 (AT&T SVR3.2.1)
and the 3B2 (SVR3.2).  First, try this as root from some subdirectory:

	# cc foo.c -o ../bin

where you *really* mean

	# cc foo.c -o ../bin/foo

It trashes the mentioned directory and requires an fsck to
reattach the files previously found underneath.  Strictly
speaking it's not a bug because it *did* do what I asked, but it
is still unfriendly behavior.

Bug 2 is found on both 3B2 and 386 compilers.  Make a file with just:

	static char	foo[] = (char *)"foo";

This causes a core dump on the 386 and a "compiler error" on the
3B2.  This sequence came out by accident, but it still shouldn't
core dump.

     Steve

-- 
Stephen J. Friedl, KA8CMY / I speak for me only / Tustin, CA / 3B2-kind-of-guy
+1 714 544 6561  / friedl@mtndew.Tustin.CA.US  / {uunet,attmail}!mtndew!friedl

Jesse Helms for U.S. Supreme Court Justice

kevin@cfctech.cfc.com (Kevin Darcy) (09/22/90)

In article <522@mtndew.Tustin.CA.US> friedl@mtndew.Tustin.CA.US (Steve Friedl) writes:
>Hi folks,
>
>     Two problems with the C compiler on the 386 (AT&T SVR3.2.1)
>and the 3B2 (SVR3.2).  First, try this as root from some subdirectory:
>
>	# cc foo.c -o ../bin
>
>where you *really* mean
>
>	# cc foo.c -o ../bin/foo
>
>It trashes the mentioned directory and requires an fsck to
>reattach the files previously found underneath.  Strictly
>speaking it's not a bug because it *did* do what I asked, but it
>is still unfriendly behavior.

I just tested this myself (3B2/1000 Model 80, 3.2.2), and... ZOWIE!! It's way 
beyond unfriendly! It breaks one of the "sacred" rules of Unix - no direct 
writes to (block-device, mounted) filesystem directories. This is one of the 
few things which is (usually) denied even to root. For instance,

(/bin/sh)

# cd /tmp
# mkdir if_you_dare
# >if_you_dare

yields

if_you_dare: cannot create

even to root. Errno 21 ("Is a directory") exists purely for this purpose. But 
somehow, ld bypasses the safeguards. Is ld writing on the raw device? Why??

I hope AT&T is listening...

------------------------------------------------------------------------------
kevin@cfctech.cfc.com 		  | Kevin Darcy, Unix Systems Administrator
...sharkey!cfctech!kevin          | Technical Services (CFC)
Voice: (313) 948-4863 		  | Chrysler Corporation
Fax:   (313) 948-4975 		  | 27777 Franklin, Southfield, MI 48034
------------------------------------------------------------------------------

davidsen@sixhub.UUCP (Wm E. Davidsen Jr) (09/23/90)

In article <522@mtndew.Tustin.CA.US> friedl@mtndew.Tustin.CA.US (Steve Friedl) writes:

| Bug 2 is found on both 3B2 and 386 compilers.  Make a file with just:
| 
| 	static char	foo[] = (char *)"foo";
| 
| This causes a core dump on the 386 and a "compiler error" on the
| 3B2.  

  I tried it on V.4 (386) and it worked fine.

worked = compiler says this is garbage in and terminates normally.
-- 
bill davidsen - davidsen@sixhub.uucp (uunet!crdgw1!sixhub!davidsen)
    sysop *IX BBS and Public Access UNIX
    moderator of comp.binaries.ibm.pc and 80386 mailing list
"Stupidity, like virtue, is its own reward" -me

guy@auspex.auspex.com (Guy Harris) (09/25/90)

>I just tested this myself (3B2/1000 Model 80, 3.2.2), and... ZOWIE!! It's way 
>beyond unfriendly! It breaks one of the "sacred" rules of Unix - no direct 
>writes to (block-device, mounted) filesystem directories.

All "ld" has to do to produce that behavior is to unlink any existing
target file and create a new one; most versions of UNIX allow the
super-user to unlink directories (yes, I know, SunOS doesn't; however,
it doesn't disallow making hard links to directories - if it's going to
disallow removing hard links to them, it should bloody well disallow
making them in the first place).  It most definitely doesn't have to do
"direct writes to ...  directories".

>This is one of the few things which is (usually) denied even to root.

Writing to directories is.  Unlinking them isn't.

>But somehow, ld bypasses the safeguards.

There is no safeguard to bypass.

>Is ld writing on the raw device?

Probably not; there's no reason for it to do so (unless you ask it do,
somehow).

kevin@cfctech.cfc.com (Kevin Darcy) (09/28/90)

In article <4087@auspex.auspex.com> guy@auspex.auspex.com (Guy Harris) writes:
>>I just tested this myself (3B2/1000 Model 80, 3.2.2), and... ZOWIE!! It's way 
>>beyond unfriendly! It breaks one of the "sacred" rules of Unix - no direct 
>>writes to (block-device, mounted) filesystem directories.
>
>All "ld" has to do to produce that behavior is to unlink any existing
>target file and create a new one; most versions of UNIX allow the
>super-user to unlink directories (yes, I know, SunOS doesn't; however,
>it doesn't disallow making hard links to directories - if it's going to
>disallow removing hard links to them, it should bloody well disallow
>making them in the first place).  It most definitely doesn't have to do
>"direct writes to ...  directories".

(Point well taken about SunOS, btw. I've been bitten by that one.)

Yes, of course you're right. I was unwittingly giving AT&T the benefit of the 
doubt. It's hard to believe that a system utility would go OUT OF ITS WAY to
unlink a directory with files in it...

If this EVER happens to me accidentally, I'm calling it in, though.

------------------------------------------------------------------------------
kevin@cfctech.cfc.com 		  | Kevin Darcy, Unix Systems Administrator
...sharkey!cfctech!kevin          | Technical Services (CFC)
Voice: (313) 948-4863 		  | Chrysler Corporation
Fax:   (313) 948-4975 		  | 27777 Franklin, Southfield, MI 48034
------------------------------------------------------------------------------