4 ms·
> That means that you have to write everything to temporary files first. Using the example from the post, echo "($(ldap-query-for-valid-users))" > "/tmp/a
by kps 10y ago
> That means that you have to write everything to temporary files first.
Using the example from the post,
echo "($(ldap-query-for-valid-users))" > "/tmp/all-users.sexp"
you have at least a couple alternatives to an additional temporary file.
if ! valid__users=$(ldap-query-for-valid-users)
then
... failure case ...
fi
echo "($valid__users)" >/tmp/all-users.sexp
or
{
echo -n '('
if ! ldap-query-for-valid-users
then
... failure case ...
fi
echo ')'
} >/tmp/all-users.sexp
- jstimpfle 10y agoAs an aside, command substitution can't handle binary, and it strips all trailing newlines.
- btilly 10y agoAnd when multiple bash scripts do that, it is easy to have them accidentally overwrite each other's temp files. Plus an attacker can play with temp files in a number of interesting ways to turn their use into an attack.
- kps 10y agoI was just illustrating the error checking using commands functionally equivalent to the original post. Temporary files are best avoided entirely unless some command actually requires a seekable file, in which case use mktemp(1) or equivalent (and 'trap 0' to clean up after yourself).