The Unix Heritage Society mailing list
 help / color / mirror / Atom feed
* [TUHS] There is turmoil in Linux-land - When did rm first avoid going upwards?
@ 2017-04-25  1:34 Noel Chiappa
  0 siblings, 0 replies; 14+ messages in thread
From: Noel Chiappa @ 2017-04-25  1:34 UTC (permalink / raw)


    > From: Kurt H Maier

    > /etc/glob, which appears to report no-match if the first character is .

So I couldn't be bothered to work out how 'glob' worked exactly, so I just did
an experiment: I created a hacked version of 'rm' that had the directory
handling call to glob call 'echo' instead of 'rm'; it also printed 'tried'
instead of the actual unlink call, and printed 'cd' when it changed
directories.

I then set up two subsidiary directors, foo and .bar, with one containing
'.foo0 foo1' and the other '.bar0 bar1'.

Saying 'xrm -r -f .*' produced this:

  cd: .
  -r -f foo xrm xrm.c
  cd: ..
  -r -f foo xrm xrm.c
  cd: .bar
  -r -f bar1 

(This system has /tmp on a mounted file system, which is why the 'cd ..' was a
NOP. And a very good thing, too; at one point the phone rang, and it
distracted me, and I automatically typed 'rm', not 'xrm'... see below for what
happened. No biggie, there were only my test files there.  The output lines
are "-r -f foo xrm xrm.c" because that's what 'glob' passed to 'echo'.)

Saying 'xrm -r -f *' produced this:

  cd: foo
  -r -f foo1
  xrm: tried
  xrm.c: tried     

So apparently 'glob', when presented with '*' , ignores entries starting with
'.', but '.*' does not.


When I stupidly typed 'rm -r -f .*', it did more or les what I originally
thought it would: deleted all the files in all the directories (but only on
the /tmp device, because .. linked to the itself in /tmp, so it didn't escape
from that volume); leaving all the directories, but empty, except for the
files .foo0 and .bar0. So files and inferior directories with names starting
with '.' would have escaped, but nothing else.

	Noel


^ permalink raw reply	[flat|nested] 14+ messages in thread
* [TUHS] There is turmoil in Linux-land - When did rm first avoid going upwards?
@ 2017-04-25  0:59 Noel Chiappa
  0 siblings, 0 replies; 14+ messages in thread
From: Noel Chiappa @ 2017-04-25  0:59 UTC (permalink / raw)


    > From: "Ron Natalie"

    > Actually, it's the shell that calls glob.

Yes, in the initial expansion of the command line, but V6 'rm' also uses
'glob' internally; if the '-r' flag is given, and the current name in the
command argument list is a directory, viz.:

	if ((buf->mode & 060000) == 040000) {
		if (rflg) {
			...
			execl("/etc/glob", "glob", "rm", "-r", 
					    fflg? "-f": "*", fflg? "*": p, 0);
			printf("%s: no glob\n", arg);
			exit();
			}			

(where 'p' is 0 - no idea why the writer didn't just say '"*": 0, 0').

So "rm -f foo*", where the current directory contains file 'foo0 foo1 foo2'
and directoty 'foobar', and directory 'foobar' contains 'bar0 bar1 bar2', the
first instance of 'glob' (run by the shell) expands the 'foo0 foo1 foo2 foobar'
and the second instance (run by 'rm') expands the 'bar0 bar1 bar2'.


     > Glob then invokes the command (in this case rm).

I don't totally grok 'glob', but it is prepared to exec() either the command
name, /bin/{command} or /usr/bin/{command}; but if that file is not executable
it tries feeding it to the shell, on the assumption it must be a shell command
list:
	   
	execv(file, arg);
	if (errno==ENOEXEC) {
		arg[0] = file;
		*--arg = "/bin/sh";
		execv(*arg, arg);
		}

I guess (too lazy to look) that the execv() must return a different error
number if the file doesn't exist at all, so it only tries the shell if the
file existed, but wasn't executable.

	Noel


^ permalink raw reply	[flat|nested] 14+ messages in thread
* [TUHS] There is turmoil in Linux-land - When did rm first avoid going upwards?
@ 2017-04-24 22:06 Noel Chiappa
  2017-04-24 22:18 ` Josh Good
  0 siblings, 1 reply; 14+ messages in thread
From: Noel Chiappa @ 2017-04-24 22:06 UTC (permalink / raw)


    > From: Josh Good

    > Would the command "cd /tmp ; rm -rf .*" be able to kill a V6 ... system?

Looking at the vanilla 'rm' source for V6, it cannot/does not delete
directories; one has to use the special 'rmdir' command for that. But,
somewhat to my surprise, it does support both the '-r' and '-f' flags, which I
thought were later. (Although not as 'stacked' flags, so you'd have to say
'rm -r -f'.)

So, assuming one did that, _and_ (important caveat!) _performed that command
as root_, it probably would empty out the entire directory tree. (I checked,
and "cd /tmp ; echo .*" evaluates to ". .." on V6.

	Noel


^ permalink raw reply	[flat|nested] 14+ messages in thread
* [TUHS] There is turmoil in Linux-land - When did rm first avoid going upwards?
@ 2017-04-24 21:42 Josh Good
  2017-04-24 21:48 ` Alec Muffett
  2017-04-24 22:10 ` Kurt H Maier
  0 siblings, 2 replies; 14+ messages in thread
From: Josh Good @ 2017-04-24 21:42 UTC (permalink / raw)


Hello all.

It's off-topic for this list, but there is turmoil in Linux-land. A bug
was discovered in systemd, whereby systemd re-implemented "rm"
functionality without following POSIX "rm" behaviour. This could kill a
system, as explained here: https://github.com/systemd/systemd/issues/5644

The reference POSIX "rm" behaviour is that "rm -rf .*" should NOT delete
the current and parent directories, as stated here:
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/rm.html#tag_20_111_16

So, to get on-topic, I have a question for UNIX historians: when was it
first defined in the UNIX realm that "rm -r .*" should NOT delete the
current and parent directories? Would the command "cd /tmp ; rm -rf .*"
be able to kill a V6 or V7 UNIX system?

Regards,

-- 
Josh Good



^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2017-04-25  1:34 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-25  1:34 [TUHS] There is turmoil in Linux-land - When did rm first avoid going upwards? Noel Chiappa
  -- strict thread matches above, loose matches on Subject: below --
2017-04-25  0:59 Noel Chiappa
2017-04-24 22:06 Noel Chiappa
2017-04-24 22:18 ` Josh Good
2017-04-24 23:23   ` Kurt H Maier
2017-04-25  0:06     ` Ron Natalie
2017-04-25  0:18       ` Kurt H Maier
2017-04-25  0:22         ` ron minnich
2017-04-25  0:24           ` Kurt H Maier
2017-04-25  0:26             ` ron minnich
2017-04-24 21:42 Josh Good
2017-04-24 21:48 ` Alec Muffett
2017-04-24 21:59   ` Arthur Krewat
2017-04-24 22:10 ` Kurt H Maier

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).