coreutils
[Top][All Lists]
Advanced

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

Re: [PATCH 10/12] cksum: support digest detection for tagged format


From: Pádraig Brady
Subject: Re: [PATCH 10/12] cksum: support digest detection for tagged format
Date: Sun, 12 Sep 2021 22:57:28 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:84.0) Gecko/20100101 Thunderbird/84.0

On 12/09/2021 19:14, Pádraig Brady wrote:
> +/* Return the corresponding Algorithm for the string S,
> +   or -1 for no match.  */
> +
> +static ptrdiff_t
> +algorithm_from_tag (char *s)
> +{
> +  /* Limit check size to this length for perf reasons.  */
> +  static size_t max_tag_len;
> +  if (! max_tag_len)
> +    {
> +      char const * const * tag = algorithm_tags;
> +      while (*tag)
> +        {
> +          size_t tag_len = strlen (*tag++);
> +          max_tag_len = MAX (tag_len, max_tag_len);
> +        }
> +    }
> +
> +  size_t i = 0;
> +
> +  /* Find end of tag */
> +  while (i < max_tag_len && s[i] && ! ISWHITE (s[i])
> +         && s[i] != '-' && s[i] != '(')
> +    ++i;
> +
> +  if (i > max_tag_len)
> +    return -1;

Oops. Off by one:

diff --git a/src/digest.c b/src/digest.c
index 3931c8ae8..9e1182005 100644
--- a/src/digest.c
+++ b/src/digest.c
@@ -653,7 +653,7 @@ algorithm_from_tag (char *s)
   size_t i = 0;

   /* Find end of tag */
-  while (i < max_tag_len && s[i] && ! ISWHITE (s[i])
+  while (i <= max_tag_len && s[i] && ! ISWHITE (s[i])
          && s[i] != '-' && s[i] != '(')
     ++i;



reply via email to

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