From nobody Sat Feb 24 12:15:01 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Thm6G2CFTz5Cf4B; Sat, 24 Feb 2024 12:15:02 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Thm6G1cYGz4pRy; Sat, 24 Feb 2024 12:15:02 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1708776902; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=J4RCXJ80iY/CLOQkEXiw0PIBXXggm35MWwOspoAFmxc=; b=kp3hkExk+30zmmc/z3uHzD/9OpZdyyqHds+7uekBSfW8R4dKvu8h1F+Q4O/jfHnkxzBeOV mbYA2nAddw5QAAx8hyqfAO9xOigbFh2w2L9U0RbOglrvB1zDxrmG0YpIP9gTswUYCbJghO 7NHdjHCjCkMgc/dPAyVRLyiU5pLOPptDMO6flRWkWYop0/GRxEsVUht9v8P9RhmQj6wMru 0Idv1YeK7evzAxhAFDDb+klf7xsXNHSwR8526GENkelZuliatmZc89vxPa2kvSnUWLrggY JHaA0IotlA76zV1gMpCIgDO0T8E033t+h/YX1KpTe0f5E/qvkZzfYmYv/08T9w== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1708776902; a=rsa-sha256; cv=none; b=s51ye2nn1yYqS3uV6/XfiExwINXZrI/f2pdQ0jmbolm6Zseh18TssvY+9nyYym2IpGHs/p Q/IGATB3zf8poZ9GogK4sIjkLvZHq4xC21yXDJtbT2ZrK+7rsi2dQZf91d3lLUQ10GJszm tA+BybxZaJh3LZEYPu+lM3KysqP1y37ms4TGjwBWnOKOsRemZxfHOZxE+8T0M3llhi1fMl cK935UANoQ+UdYDCiDe+hybCf2GDi+xOPd73a2LHbsRd1xnV2q+5Fx+LwpqPKkJZt6HrRe QR4ZoI5s7iwWOgf7KOi/feP/Fbr0keu2IYld3j3S+gurYwUup+NagPrXhDFnaw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1708776902; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=J4RCXJ80iY/CLOQkEXiw0PIBXXggm35MWwOspoAFmxc=; b=d0A8YjNCiWoJwyTyaSKyAdsFkOZOaywxEaB08eq6nD1L4t+ZxLGHL1gBXKxhtiQ1Rpz+XL FsQhyI4RKC56kKvzQkoEHqTKAcqkSczYi6/mH7B4Fhzrv43euENqQe9gtFshovgYW1m7+1 H5I0TH0igor4G4hHiaOMyLGYKd0Mfh1YunG0GGEpPDkW2FX1ZliDqAQ6AzDvJw1LM05yoy Ww3PpNpHo4Uoy3iTyg6lUFk0ICfJXHHX0mi3bMx2N2eICYZrVlkm0mQfQ3vzQTZo1X9FEQ 7cYVlJHImQBfbiztj4iQ1JCxV36tBCDXVBBKEVvbtWEa71Gs0PG8Rg4ePs+YnQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Thm6G0Z0Sz10MZ; Sat, 24 Feb 2024 12:15:02 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 41OCF1Pr085159; Sat, 24 Feb 2024 12:15:01 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 41OCF1IR085156; Sat, 24 Feb 2024 12:15:01 GMT (envelope-from git) Date: Sat, 24 Feb 2024 12:15:01 GMT Message-Id: <202402241215.41OCF1IR085156@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Dag-Erling =?utf-8?Q?Sm=C3=B8rgrav?= Subject: git: 1288891878d9 - stable/14 - md5: Accept "-" as alias for stdin. List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: des X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 1288891878d9a194af8c170bb6a33c06e306e0e0 Auto-Submitted: auto-generated The branch stable/14 has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=1288891878d9a194af8c170bb6a33c06e306e0e0 commit 1288891878d9a194af8c170bb6a33c06e306e0e0 Author: Dag-Erling Smørgrav AuthorDate: 2024-02-16 12:36:58 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2024-02-24 12:12:49 +0000 md5: Accept "-" as alias for stdin. (based on a patch by jhb) MFC after: 1 week PR: 276915 Reported by: Hannes Hauswedell Reviewed by: allanjude, markj, jhb, emaste Differential Revision: https://reviews.freebsd.org/D43870 (cherry picked from commit 72ee91fed4cfdcfbfb767cc166370b40e50d446a) md5: Ignore files in string and passthrough mode. MFC after: 1 week Reviewed by: allanjude, markj Differential Revision: https://reviews.freebsd.org/D43871 (cherry picked from commit 5b44edb4058365ba8e4ccfdb5176c1cddd4394fe) md5: Clean up input stream rights. Keep it simple, caph_limit_stdio() and fileargs_fopen() already take care of everything for us. MFC after: 1 week Reviewed by: markj, jhb, emaste Differential Revision: https://reviews.freebsd.org/D43897 (cherry picked from commit 17d5b027c1921d0c6ba2de7993dd808dbf4df078) md5: Add test case for GNU input modes. MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: allanjude, markj Differential Revision: https://reviews.freebsd.org/D43988 (cherry picked from commit e7308a60a5b77a1e4aff6e27eddef40fedabb98c) md5: Fix Perl mode long options. MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: imp, allanjude, markj Differential Revision: https://reviews.freebsd.org/D43989 (cherry picked from commit 4db7ca24470576948e33f48033cfa5be2749950e) md5: Fix GNU check mode. Fixes: 9b20849bc5f1b500f2de7aeca77f0e6556069bbb MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: imp, allanjude, markj Differential Revision: https://reviews.freebsd.org/D43990 (cherry picked from commit c05533d97ac178f8e811407860d47d3c0ae61eed) md5: Untabify declarations. MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: imp, allanjude, markj Differential Revision: https://reviews.freebsd.org/D43991 (cherry picked from commit 702f133fa18185a7e10e66316e8f158be935b696) --- sbin/md5/md5.1 | 9 +++- sbin/md5/md5.c | 101 +++++++++++++++++++++++---------------------- sbin/md5/tests/md5_test.sh | 35 ++++++++++++++++ 3 files changed, 95 insertions(+), 50 deletions(-) diff --git a/sbin/md5/md5.1 b/sbin/md5/md5.1 index 0cdfff928211..0a8dc46f3b1f 100644 --- 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 @@ utility does the same, but with command-line options and an output 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. @@ -124,6 +129,7 @@ option, the calculated digest is printed in addition to the exit status being se .Pq Note that this option is not yet useful if multiple files are specified. .It Fl p , -passthrough Echo stdin to stdout and append the checksum to stdout. +In this mode, any files specified on the command line are silently ignored. .It Fl q , -quiet Quiet mode \(em only the checksum is printed out. Overrides the @@ -141,6 +147,7 @@ options. .It Fl s Ar string , Fl -string= Ns Ar string Print a checksum of the given .Ar string . +In this mode, any files specified on the command line are silently ignored. .It Fl t , Fl -time-trial Run a built-in time trial. For the diff --git a/sbin/md5/md5.c b/sbin/md5/md5.c index eb9a2ffae1cc..1bf897d119c0 100644 --- a/sbin/md5/md5.c +++ b/sbin/md5/md5.c @@ -264,7 +264,8 @@ static const char *gnu_shortopts = "bctwz"; static const struct option perl_longopts[] = { { "algorithm", required_argument, 0, opt_algorithm }, - { "check", required_argument, 0, opt_check }, + { "binary", no_argument, 0, opt_binary }, + { "check", no_argument, 0, opt_check }, { "help", no_argument, 0, opt_help }, { "ignore-missing", no_argument, 0, opt_ignore_missing }, { "quiet", no_argument, 0, opt_quiet }, @@ -287,9 +288,10 @@ MD5_Update(MD5_CTX *c, const unsigned char *data, size_t len) } struct chksumrec { - char *filename; - char *chksum; - struct chksumrec *next; + char *filename; + enum input_mode input_mode; + char *chksum; + struct chksumrec *next; }; static struct chksumrec *head = NULL; @@ -302,17 +304,17 @@ static unsigned int numrecs; static void gnu_check(const char *checksumsfile) { - FILE *inp; - char *linebuf = NULL; - size_t linecap; - ssize_t linelen; - int lineno; - char *filename; - char *hashstr; - struct chksumrec *rec; - const char *digestname; - size_t digestnamelen; - size_t hashstrlen; + FILE *inp; + char *linebuf = NULL; + size_t linecap; + ssize_t linelen; + int lineno; + char *filename; + char *hashstr; + struct chksumrec *rec; + const char *digestname; + size_t digestnamelen; + size_t hashstrlen; struct stat st; if (strcmp(checksumsfile, "-") == 0) @@ -362,16 +364,18 @@ gnu_check(const char *checksumsfile) if (rec == NULL) errx(1, "malloc failed"); - if (*filename == '*' || - *filename == ' ' || - *filename == 'U' || - *filename == '^') { - if (lstat(filename, &st) != 0) - filename++; + if ((*filename == '*' || *filename == ' ' || + *filename == 'U' || *filename == '^') && + lstat(filename, &st) != 0 && + lstat(filename + 1, &st) == 0) { + rec->filename = strdup(filename + 1); + rec->input_mode = (enum input_mode)*filename; + } else { + rec->filename = strdup(filename); + rec->input_mode = input_mode; } rec->chksum = strdup(hashstr); - rec->filename = strdup(filename); if (rec->chksum == NULL || rec->filename == NULL) errx(1, "malloc failed"); rec->next = NULL; @@ -396,17 +400,17 @@ int main(int argc, char *argv[]) { #ifdef HAVE_CAPSICUM - cap_rights_t rights; - fileargs_t *fa = NULL; + cap_rights_t rights; + fileargs_t *fa = NULL; #endif const struct option *longopts; const char *shortopts; - FILE *f; - int i, opt; - char *p, *string = NULL; - char buf[HEX_DIGEST_LENGTH]; - size_t len; - struct chksumrec *rec; + FILE *f; + int i, opt; + char *p, *string = NULL; + char buf[HEX_DIGEST_LENGTH]; + size_t len; + struct chksumrec *rec; if ((progname = strrchr(argv[0], '/')) == NULL) progname = argv[0]; @@ -575,7 +579,7 @@ main(int argc, char *argv[]) argv += optind; #ifdef HAVE_CAPSICUM - if (caph_limit_stdout() < 0 || caph_limit_stderr() < 0) + if (caph_limit_stdio() < 0) err(1, "unable to limit rights for stdio"); #endif @@ -607,41 +611,40 @@ main(int argc, char *argv[]) err(1, "Unable to enter capability mode"); #endif - if (*argv) { + if (*argv && !pflag && string == NULL) { do { const char *filename = *argv; const char *filemode = "rb"; + if (cflag && mode != mode_bsd) { + input_mode = rec->input_mode; + checkAgainst = rec->chksum; + rec = rec->next; + } + if (input_mode == input_text) + filemode = "r"; + 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; } - if (cflag && mode != mode_bsd) - rec = rec->next; continue; } -#ifdef HAVE_CAPSICUM - if (caph_rights_limit(fileno(f), &rights) < 0) - err(1, "capsicum"); -#endif - if (cflag && mode != mode_bsd) { - checkAgainst = rec->chksum; - 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) { -#ifdef HAVE_CAPSICUM - if (caph_limit_stdin() < 0) - err(1, "capsicum"); -#endif if (mode == mode_bsd) output_mode = output_bare; p = MDInput(&Algorithm[digest], stdin, buf, pflag); diff --git a/sbin/md5/tests/md5_test.sh b/sbin/md5/tests/md5_test.sh index c6bc1dfd7be0..34bdf43f13ea 100644 --- a/sbin/md5/tests/md5_test.sh +++ b/sbin/md5/tests/md5_test.sh @@ -197,11 +197,15 @@ bsd_${alg}_vec${i}_body() { printf '%s' \"\$inp_${i}\" >in atf_check -o inline:\"\$out_${i}_${alg}\n\" ${alg} input + # The first line is malformed per GNU coreutils but matches + # what we produce when mode == mode_bsd && output_mode == + # output_reverse (i.e. `sha1 -r`) so we want to support it. + cat >digests <