cksum: fix off-by-1 bug with \r stripping

Problem reported by Jim Meyering (Bug#50611).
* src/digest.c (digest_check): When stripping trailing \r,
avoid subscript error before start of line.
This commit is contained in:
Paul Eggert committed 2021-09-16 00:25:26 -07:00
1 parent 2715aba08a
commit 121f74dfc2
1 file changed
+3 -4
+3 -4
View File
@@ -1070,11 +1070,10 @@ digest_check (char const *checkfile_name)
continue;
/* Remove any trailing newline. */
if (line[line_length - 1] == '\n')
line[--line_length] = '\0';
line_length -= line[line_length - 1] == '\n';
/* Remove any trailing carriage return. */
if (line[line_length - 1] == '\r')
line[--line_length] = '\0';
line_length -= line[line_length - (0 < line_length)] == '\r';
line[line_length] = '\0';
if (! (split_3 (line, line_length, &hex_digest, &binary, &filename)
&& ! (is_stdin && STREQ (filename, "-"))))