md5: Accept "-" as alias for stdin.
(based on a patch by jhb) MFC after: 1 week PR: 276915 Reported by: Hannes Hauswedell <h2+fbsdports@fsfe.org> Reviewed by: allanjude, markj, jhb, emaste Differential Revision: https://reviews.freebsd.org/D43870
This commit is contained in:
+6
-1
@@ -1,4 +1,4 @@
|
|||||||
.Dd May 10, 2023
|
.Dd February 13, 2024
|
||||||
.Dt MD5 1
|
.Dt MD5 1
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
@@ -79,6 +79,11 @@ utility does the same, but with command-line options and an output
|
|||||||
format that match those of the similarly named utility that ships with
|
format that match those of the similarly named utility that ships with
|
||||||
Perl.
|
Perl.
|
||||||
.Pp
|
.Pp
|
||||||
|
In all cases, each file listed on the command line is processed separately.
|
||||||
|
If no files are listed on the command line, or a file name is given as
|
||||||
|
.Pa - ,
|
||||||
|
input is taken from stdin instead.
|
||||||
|
.Pp
|
||||||
It is conjectured that it is computationally infeasible to
|
It is conjectured that it is computationally infeasible to
|
||||||
produce two messages having the same message digest, or to produce any
|
produce two messages having the same message digest, or to produce any
|
||||||
message having a given prespecified target message digest.
|
message having a given prespecified target message digest.
|
||||||
|
|||||||
+9
-3
@@ -611,11 +611,16 @@ main(int argc, char *argv[])
|
|||||||
const char *filename = *argv;
|
const char *filename = *argv;
|
||||||
const char *filemode = "rb";
|
const char *filemode = "rb";
|
||||||
|
|
||||||
|
if (strcmp(filename, "-") == 0) {
|
||||||
|
f = stdin;
|
||||||
|
} else {
|
||||||
#ifdef HAVE_CAPSICUM
|
#ifdef HAVE_CAPSICUM
|
||||||
if ((f = fileargs_fopen(fa, filename, filemode)) == NULL) {
|
f = fileargs_fopen(fa, filename, filemode);
|
||||||
#else
|
#else
|
||||||
if ((f = fopen(filename, filemode)) == NULL) {
|
f = fopen(filename, filemode);
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
if (f == NULL) {
|
||||||
if (errno != ENOENT || !(cflag && ignoreMissing)) {
|
if (errno != ENOENT || !(cflag && ignoreMissing)) {
|
||||||
warn("%s", filename);
|
warn("%s", filename);
|
||||||
failed = true;
|
failed = true;
|
||||||
@@ -633,7 +638,8 @@ main(int argc, char *argv[])
|
|||||||
rec = rec->next;
|
rec = rec->next;
|
||||||
}
|
}
|
||||||
p = MDInput(&Algorithm[digest], f, buf, false);
|
p = MDInput(&Algorithm[digest], f, buf, false);
|
||||||
(void)fclose(f);
|
if (f != stdin)
|
||||||
|
(void)fclose(f);
|
||||||
MDOutput(&Algorithm[digest], p, filename);
|
MDOutput(&Algorithm[digest], p, filename);
|
||||||
} while (*++argv);
|
} while (*++argv);
|
||||||
} else if (!cflag && string == NULL && !skip) {
|
} else if (!cflag && string == NULL && !skip) {
|
||||||
|
|||||||
@@ -197,7 +197,9 @@ bsd_${alg}_vec${i}_body() {
|
|||||||
printf '%s' \"\$inp_${i}\" >in
|
printf '%s' \"\$inp_${i}\" >in
|
||||||
atf_check -o inline:\"\$out_${i}_${alg}\n\" ${alg} <in
|
atf_check -o inline:\"\$out_${i}_${alg}\n\" ${alg} <in
|
||||||
atf_check -o inline:\"\$name_bsd_${alg} (in) = \$out_${i}_${alg}\n\" ${alg} in
|
atf_check -o inline:\"\$name_bsd_${alg} (in) = \$out_${i}_${alg}\n\" ${alg} in
|
||||||
|
atf_check -o inline:\"\$name_bsd_${alg} (-) = \$out_${i}_${alg}\n\" ${alg} - <in
|
||||||
atf_check -o inline:\"\$out_${i}_${alg} in\n\" ${alg} -r in
|
atf_check -o inline:\"\$out_${i}_${alg} in\n\" ${alg} -r in
|
||||||
|
atf_check -o inline:\"\$out_${i}_${alg} -\n\" ${alg} -r - <in
|
||||||
# -q overrides -r regardless of order
|
# -q overrides -r regardless of order
|
||||||
for opt in -q -qr -rq ; do
|
for opt in -q -qr -rq ; do
|
||||||
atf_check -o inline:\"\$out_${i}_${alg}\n\" ${alg} \${opt} in
|
atf_check -o inline:\"\$out_${i}_${alg}\n\" ${alg} \${opt} in
|
||||||
@@ -215,9 +217,13 @@ gnu_${alg}_vec${i}_body() {
|
|||||||
atf_check -o inline:\"\$out_${i}_${alg} -\n\" ${alg}sum <in
|
atf_check -o inline:\"\$out_${i}_${alg} -\n\" ${alg}sum <in
|
||||||
atf_check -o inline:\"\$out_${i}_${alg} *-\n\" ${alg}sum -b <in
|
atf_check -o inline:\"\$out_${i}_${alg} *-\n\" ${alg}sum -b <in
|
||||||
atf_check -o inline:\"\$out_${i}_${alg} in\n\" ${alg}sum in
|
atf_check -o inline:\"\$out_${i}_${alg} in\n\" ${alg}sum in
|
||||||
|
atf_check -o inline:\"\$out_${i}_${alg} -\n\" ${alg}sum - <in
|
||||||
atf_check -o inline:\"\$out_${i}_${alg} *in\n\" ${alg}sum -b in
|
atf_check -o inline:\"\$out_${i}_${alg} *in\n\" ${alg}sum -b in
|
||||||
|
atf_check -o inline:\"\$out_${i}_${alg} *-\n\" ${alg}sum -b - <in
|
||||||
atf_check -o inline:\"\$name_bsd_${alg} (in) = \$out_${i}_${alg}\n\" ${alg}sum --tag in
|
atf_check -o inline:\"\$name_bsd_${alg} (in) = \$out_${i}_${alg}\n\" ${alg}sum --tag in
|
||||||
|
atf_check -o inline:\"\$name_bsd_${alg} (-) = \$out_${i}_${alg}\n\" ${alg}sum --tag - <in
|
||||||
atf_check -o inline:\"\$out_${i}_${alg} in\0\" ${alg}sum -z in
|
atf_check -o inline:\"\$out_${i}_${alg} in\0\" ${alg}sum -z in
|
||||||
|
atf_check -o inline:\"\$out_${i}_${alg} -\0\" ${alg}sum -z - <in
|
||||||
}
|
}
|
||||||
"
|
"
|
||||||
eval "
|
eval "
|
||||||
@@ -233,9 +239,13 @@ perl_${alg}_vec${i}_body() {
|
|||||||
atf_check -o inline:\"\$out_${i}_${alg} *-\n\" shasum \$alg_perl_${alg} -b <in
|
atf_check -o inline:\"\$out_${i}_${alg} *-\n\" shasum \$alg_perl_${alg} -b <in
|
||||||
atf_check -o inline:\"\$out_${i}_${alg} U-\n\" shasum \$alg_perl_${alg} -U <in
|
atf_check -o inline:\"\$out_${i}_${alg} U-\n\" shasum \$alg_perl_${alg} -U <in
|
||||||
atf_check -o inline:\"\$out_${i}_${alg} in\n\" shasum \$alg_perl_${alg} in
|
atf_check -o inline:\"\$out_${i}_${alg} in\n\" shasum \$alg_perl_${alg} in
|
||||||
|
atf_check -o inline:\"\$out_${i}_${alg} -\n\" shasum \$alg_perl_${alg} - <in
|
||||||
atf_check -o inline:\"\$out_${i}_${alg} *in\n\" shasum \$alg_perl_${alg} -b in
|
atf_check -o inline:\"\$out_${i}_${alg} *in\n\" shasum \$alg_perl_${alg} -b in
|
||||||
|
atf_check -o inline:\"\$out_${i}_${alg} *-\n\" shasum \$alg_perl_${alg} -b - <in
|
||||||
atf_check -o inline:\"\$out_${i}_${alg} Uin\n\" shasum \$alg_perl_${alg} -U in
|
atf_check -o inline:\"\$out_${i}_${alg} Uin\n\" shasum \$alg_perl_${alg} -U in
|
||||||
|
atf_check -o inline:\"\$out_${i}_${alg} U-\n\" shasum \$alg_perl_${alg} -U - <in
|
||||||
atf_check -o inline:\"\$name_perl_${alg} (in) = \$out_${i}_${alg}\n\" shasum \$alg_perl_${alg} --tag in
|
atf_check -o inline:\"\$name_perl_${alg} (in) = \$out_${i}_${alg}\n\" shasum \$alg_perl_${alg} --tag in
|
||||||
|
atf_check -o inline:\"\$name_perl_${alg} (-) = \$out_${i}_${alg}\n\" shasum \$alg_perl_${alg} --tag - <in
|
||||||
}
|
}
|
||||||
"
|
"
|
||||||
done
|
done
|
||||||
|
|||||||
Reference in New Issue
Block a user