in reply to Two-arg open() considered dangerous
Careful thought about that venerable security hole:
open(INPUT, param("input"));
demonstrates the truth of what you say. Essentially any API which make data and metadata easily confused should be viewed with suspicion.
But given that the 3 argument open is not documented as of 5.005_03, I would be cautious about suggesting that people use it in any code whose use is meant to be portable. People will have to use sysopen instead, but now you have to go through extra hoops to pull in the right values of your flags from Fcntl.
Re: Two-arg open() considered dangerous
by Dominus (Parson) on Dec 12, 2001 at 21:05 UTC
|
| [reply] |
Re (chip): Two-arg open() considered dangerous
by chip (Curate) on Dec 12, 2001 at 03:53 UTC
|
Incidentally, I'd say that this tilly quote deserves preservation:
Any API which make data and metadata easily confused should be viewed with suspicion.
-- tilly
-- Chip Salzenberg, Free-Floating Agent of Chaos | [reply] |
Re (chip): Two-arg open() considered dangerous
by chip (Curate) on Dec 12, 2001 at 03:50 UTC
|
I agree that three-arg open is a bit new to depend on, but
sysopen may not be inconvenient. Specifically,
it's guaranteed{1} that O_RDONLY,
O_WRONLY, and O_RDWR have the values
zero, one, and two, respectively. So sysopen FOO, $file, 0
should work everywhere in the known universe.
{1} This is OK to count on because the C function open()
originates with Unix, and for backwards compatibility with
ancient UNIX code, the second parameter of open() must accept
zero/one/two.
-- Chip Salzenberg, Free-Floating Agent of Chaos | [reply] [d/l] [select] |
|
It is not guaranteed. From 'perldoc -f sysopen' on 5.005_03 I get:
=item sysopen FILEHANDLE,FILENAME,MODE
=item sysopen FILEHANDLE,FILENAME,MODE,PERMS
[ snip ]
The possible values and flag bits of the MODE parameter are
system-dependent; they are available via the standard module C<Fcntl>.
For historical reasons, some values work on almost every system
supported by perl: zero means read-only, one means write-only, and two
means read/write. We know that these values do I<not> work under
OS/390 & VM/ESA Unix and on the Macintosh; you probably don't want to
use them in new code.
So those values probably work. But not always. | [reply] [d/l] |
|
| [reply] |
|
|
|