/dev/stdin for SVR2

Andrew Koenig ark at alice.UUCP
Fri Jun 21 11:04:42 AEST 1985


> This would appear to give write access to read-only files.
> What happens if I say

>	cat </tmp/foo >/dev/stdin

> as root?

If you are root, you already have write access to read-only files.
If not root,

	cat </etc/passwd >/dev/stdin

elicits the error message:

	cat: output - is input

whereas:

	cat >/dev/stdin </etc/passwd

prints the password file on my terminal.

This behavior appears a little less mysterious when you realize that
(a) the standard input is normally connected to the terminal and is
opened for both input and output, and (b) the Shell processes
redirection requests one at a time from left to right.  Thus in the
first case, the Shell first opens /etc/passwd as file descriptor
1, then opens its standard output as dup(1), which results in both
file descriptors being connected to the same file, which cat detects.
In the second case, the Shell connects the standard output to dup(1)
and then (re-) opens the standard input.



More information about the Comp.sources.bugs mailing list