diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2021-09-16 00:17:18 -0700 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2021-09-16 00:25:26 -0700 |
commit | 121f74dfc2e060a2ae174a636cd773f4d461a852 (patch) | |
tree | 06fe244e78ffe926ceef442851f5a7db301c58e4 /src/digest.c | |
parent | 2715aba08a381a6099c1c6b054995e6b3df785c8 (diff) | |
download | coreutils-121f74dfc2e060a2ae174a636cd773f4d461a852.tar.gz |
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.
Diffstat (limited to 'src/digest.c')
-rw-r--r-- | src/digest.c | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/src/digest.c b/src/digest.c index 0d7ce3265..fdf01b21b 100644 --- a/src/digest.c +++ b/src/digest.c @@ -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, "-")))) |