[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: purpose of *-safer?
From: |
Jim Meyering |
Subject: |
Re: purpose of *-safer? |
Date: |
Thu, 27 Jul 2006 10:25:49 +0200 |
Paul Eggert <address@hidden> wrote:
>>> And wouldn't there be an easier workaround: At the beginning of main(),
>>> use fcntl() to determine whether 0,1,2 are closed, and if so, replace
>>> them with open("/dev/null") ?
>>
>> Possibly. And if we did, it would make more sense to open fd 0 as write
>> only and fd 1 as read only, to be more likely to catch attempts to use
>> these streams when the user intended them to be closed.
>
> Jim did that in coreutils/lib/stdopen.c, I think with the idea of
> migrating it into gnulib if there was demand.
Right.
> Hmm, but this code
> currently isn't being used in coreutils. I don't offhand recall why.
It's not needed, now, afaik.
> Here's what I do recall. I swept coreutils for the sort of problem
> that stdopen would cure and fixed then with stdio-safer etc. Jim
> wrote stdopen.c in response, since this would be simpler than all
> those painstaking sweeps.
>
> If I missed nothing in my sweeps (an unlikely prospect!), then
> invoking stdopen merely adds a small amount of bloat to coreutils, and
> is unnecessary. A more-important argument against stdopen is that
> weird invocations like "cat /dev/fd/2 2>&-" would do the wrong thing.
In general, I think it's slightly better from a maintenance standpoint to
use stdopen.c than to make your code use the *-safer modules. The latter
requires constant vigilance, or, better, some automation to guard against
additions of unsafe functions. On the efficiency front, it's a trade-off.
stdopen.c comes with a small but constant overhead, while using the
*_safer functions, you incur the overhead of per-function-call wrappers.
And of course, stdopen.c is not an option in a library context.
- Re: [bug-gnulib] split stdio-safer into fopen-safer, tmpfile-safer, (continued)
- Re: [bug-gnulib] split stdio-safer into fopen-safer, tmpfile-safer, Bruno Haible, 2006/07/26
- Re: split stdio-safer into fopen-safer, tmpfile-safer, Ben Pfaff, 2006/07/26
- Re: split stdio-safer into fopen-safer, tmpfile-safer, Eric Blake, 2006/07/26
- Re: split stdio-safer into fopen-safer, tmpfile-safer, Paul Eggert, 2006/07/27
Re: purpose of *-safer?, Bruno Haible, 2006/07/25
Re: purpose of *-safer?, Paul Eggert, 2006/07/27
Re: purpose of *-safer?,
Jim Meyering <=
Re: split stdio-safer into fopen-safer, tmpfile-safer, Eric Blake, 2006/07/28