diff --git a/sbin/md5/md5.1 b/sbin/md5/md5.1 --- a/sbin/md5/md5.1 +++ b/sbin/md5/md5.1 @@ -1,4 +1,4 @@ -.Dd May 10, 2023 +.Dd February 13, 2024 .Dt MD5 1 .Os .Sh NAME @@ -79,6 +79,11 @@ format that match those of the similarly named utility that ships with Perl. .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 produce two messages having the same message digest, or to produce any message having a given prespecified target message digest. diff --git a/sbin/md5/md5.c b/sbin/md5/md5.c --- a/sbin/md5/md5.c +++ b/sbin/md5/md5.c @@ -611,11 +611,16 @@ const char *filename = *argv; const char *filemode = "rb"; + if (strcmp(filename, "-") == 0) { + f = stdin; + } else { #ifdef HAVE_CAPSICUM - if ((f = fileargs_fopen(fa, filename, filemode)) == NULL) { + f = fileargs_fopen(fa, filename, filemode); #else - if ((f = fopen(filename, filemode)) == NULL) { + f = fopen(filename, filemode); #endif + } + if (f == NULL) { if (errno != ENOENT || !(cflag && ignoreMissing)) { warn("%s", filename); failed = true; @@ -633,7 +638,8 @@ rec = rec->next; } p = MDInput(&Algorithm[digest], f, buf, false); - (void)fclose(f); + if (f != stdin) + (void)fclose(f); MDOutput(&Algorithm[digest], p, filename); } while (*++argv); } else if (!cflag && string == NULL && !skip) { diff --git a/sbin/md5/tests/md5_test.sh b/sbin/md5/tests/md5_test.sh --- a/sbin/md5/tests/md5_test.sh +++ b/sbin/md5/tests/md5_test.sh @@ -197,7 +197,9 @@ printf '%s' \"\$inp_${i}\" >in atf_check -o inline:\"\$out_${i}_${alg}\n\" ${alg}