[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;
- [PATCH 05/12] cksum: add --debug to --help output and man page, (continued)
- [PATCH 05/12] cksum: add --debug to --help output and man page, Pádraig Brady, 2021/09/12
- [PATCH 03/12] digest: refactor sum(1) into digest.c, Pádraig Brady, 2021/09/12
- [PATCH 04/12] sum: handle EOVERFLOW for too large inputs, Pádraig Brady, 2021/09/12
- [PATCH 09/12] maint: simplify b2sum to only handle BLAKE2b, Pádraig Brady, 2021/09/12
- [PATCH 08/12] digest: add support for sm3, Pádraig Brady, 2021/09/12
- [PATCH 06/12] digest: refactor cksum(1) into digest.c, Pádraig Brady, 2021/09/12
- [PATCH 07/12] cksum: add --algorithm option to select digest mode, Pádraig Brady, 2021/09/12
- [PATCH 12/12] cksum: support --zero in default mode, Pádraig Brady, 2021/09/12
- [PATCH 10/12] cksum: support digest detection for tagged format, Pádraig Brady, 2021/09/12
- [PATCH 11/12] digest: support -length specifiers on all digest tags, Pádraig Brady, 2021/09/12
- Re: [PATCH V2] Add support for cksum --algorithm [sm3], Pádraig Brady, 2021/09/12
- Re: [PATCH V2] Add support for cksum --algorithm [sm3], Pádraig Brady, 2021/09/14
- Re: [PATCH V2] Add support for cksum --algorithm [sm3], Jim Meyering, 2021/09/14
- [PATCH 3/4] doc: improve --help indenting in checksum utils, Pádraig Brady, 2021/09/15
- [PATCH 1/4] cksum: use --tag format by default, Pádraig Brady, 2021/09/15
- Re: [PATCH 1/4] cksum: use --tag format by default, Eric Blake, 2021/09/17
- Re: [PATCH 1/4] cksum: use --tag format by default, Pádraig Brady, 2021/09/17
- Re: [PATCH 1/4] cksum: use --tag format by default, Pádraig Brady, 2021/09/20