Handle '-' consistently
In general, POSIX does not define /dev/std{in, out, err} because it does not want to depend on the dev-filesystem. For utilities, it thus introduced the '-'-keyword to denote standard input (and output in some cases) and the programs have to deal with it accordingly. Sadly, the design of many tools doesn't allow strict shell-redirections and many scripts don't even use this feature when possible. Thus, we made the decision to implement it consistently across all tools where it makes sense (namely those which read files). Along the way, I spotted some behavioural bugs in libutil/crypt.c and others where it was forgotten to fshut the files after use.
This commit is contained in:
@@ -126,18 +126,24 @@ cryptmain(int argc, char *argv[], struct crypt_ops *ops, uint8_t *md, size_t sz)
|
||||
mdprint(md, "<stdin>", sz);
|
||||
} else {
|
||||
for (; *argv; argc--, argv++) {
|
||||
if (!(fp = fopen(*argv, "r"))) {
|
||||
if ((*argv)[0] == '-' && !(*argv)[1]) {
|
||||
*argv = "<stdin>";
|
||||
fp = stdin;
|
||||
} else if (!(fp = fopen(*argv, "r"))) {
|
||||
weprintf("fopen %s:", *argv);
|
||||
ret = 1;
|
||||
continue;
|
||||
}
|
||||
if (cryptsum(ops, fp, *argv, md) == 1)
|
||||
if (cryptsum(ops, fp, *argv, md)) {
|
||||
ret = 1;
|
||||
else
|
||||
} else {
|
||||
mdprint(md, *argv, sz);
|
||||
fclose(fp);
|
||||
}
|
||||
if (fp != stdin && fshut(fp, *argv))
|
||||
ret = 1;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user