coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] cksum: use more exact selection of digest algorithms


From: Pádraig Brady
Subject: [PATCH] cksum: use more exact selection of digest algorithms
Date: Sun, 30 Jan 2022 20:36:21 +0000

Use more constrained argument matching
to improve forward compatibility and robustness.

For example it's better that `cksum -a sha3` is _not_
equivalent to `cksum -a sha386`, so that a user
specifying `-a sha3` on an older cksum would not be surprised.

Also argmatch() is used when parsing tags from lines like:
SHA3 (filename) = abcedf....
so it's more robust that older cksum instances to fail
earlier in the parsing process, when parsing output from
possible future cksum implementations that might support SHA3.

* src/digest.c (algorithm_from_tag): Use argmatch_exact()
to ensure we don't match abbreviated algorithms.
(main): Likewise.
---
 src/digest.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/digest.c b/src/digest.c
index 6de30ecb5..95782a450 100644
--- a/src/digest.c
+++ b/src/digest.c
@@ -692,7 +692,7 @@ algorithm_from_tag (char *s)
   /* Terminate tag, and lookup.  */
   char sep = s[i];
   s[i] = '\0';
-  ptrdiff_t algo = argmatch (s, algorithm_tags, NULL, 0);
+  ptrdiff_t algo = argmatch_exact (s, algorithm_tags);
   s[i] = sep;
 
   return algo;
@@ -1286,8 +1286,8 @@ main (int argc, char **argv)
       {
 #if HASH_ALGO_CKSUM
       case 'a':
-        cksum_algorithm = XARGMATCH ("--algorithm", optarg,
-                                     algorithm_args, algorithm_types);
+        cksum_algorithm = XARGMATCH_EXACT ("--algorithm", optarg,
+                                           algorithm_args, algorithm_types);
         algorithm_specified = true;
         break;
 
-- 
2.26.2




reply via email to

[Prev in Thread] Current Thread [Next in Thread]