summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPádraig Brady <P@draigBrady.com>2016-10-26 15:45:01 +0100
committerPádraig Brady <P@draigBrady.com>2016-10-26 20:42:30 +0100
commitd0ddfadfb27def2861f35b1a45190a4c1780b257 (patch)
tree4ec472c7d9dccc1ba082c550b683d03081dcf2cd /src
parent34d1aeaf315b97ac27d54b2af039126b1d5a34f4 (diff)
downloadcoreutils-d0ddfadfb27def2861f35b1a45190a4c1780b257.tar.xz
md5sum,sha*sum: fix --ignore-missing with checksums starting with 00
* NEWS: Mention the fix. * src/md5sum.c (digest_file): Add a new MISSING parameter to return whether the file was missing, separately from the digest. * tests/misc/md5sum.pl: Add a test case. Fixes http://bugs.gnu.org/24795
Diffstat (limited to 'src')
-rw-r--r--src/md5sum.c20
1 files changed, 12 insertions, 8 deletions
diff --git a/src/md5sum.c b/src/md5sum.c
index 5a39a4f05..6e85cb150 100644
--- a/src/md5sum.c
+++ b/src/md5sum.c
@@ -463,15 +463,19 @@ print_filename (char const *file, bool escape)
text because it was a terminal.
Put the checksum in *BIN_RESULT, which must be properly aligned.
+ Put true in *MISSING if the file can't be opened due to ENOENT.
Return true if successful. */
static bool
-digest_file (const char *filename, int *binary, unsigned char *bin_result)
+digest_file (const char *filename, int *binary, unsigned char *bin_result,
+ bool *missing)
{
FILE *fp;
int err;
bool is_stdin = STREQ (filename, "-");
+ *missing = false;
+
if (is_stdin)
{
have_read_stdin = true;
@@ -491,7 +495,7 @@ digest_file (const char *filename, int *binary, unsigned char *bin_result)
{
if (ignore_missing && errno == ENOENT)
{
- *bin_result = '\0';
+ *missing = true;
return true;
}
error (0, errno, "%s", quotef (filename));
@@ -604,14 +608,14 @@ digest_check (const char *checkfile_name)
'8', '9', 'a', 'b',
'c', 'd', 'e', 'f' };
bool ok;
+ bool missing;
/* Only escape in the edge case producing multiple lines,
to ease automatic processing of status output. */
bool needs_escape = ! status_only && strchr (filename, '\n');
properly_formatted_lines = true;
- *bin_buffer = '\1'; /* flag set to 0 for ignored missing files. */
- ok = digest_file (filename, &binary, bin_buffer);
+ ok = digest_file (filename, &binary, bin_buffer, &missing);
if (!ok)
{
@@ -624,10 +628,9 @@ digest_check (const char *checkfile_name)
printf (": %s\n", _("FAILED open or read"));
}
}
- else if (ignore_missing && ! *bin_buffer)
+ else if (ignore_missing && missing)
{
- /* Treat an empty buffer as meaning a missing file,
- which is ignored with --ignore-missing. */
+ /* Ignore missing files with --ignore-missing. */
;
}
else
@@ -878,8 +881,9 @@ main (int argc, char **argv)
else
{
int file_is_binary = binary;
+ bool missing;
- if (! digest_file (file, &file_is_binary, bin_buffer))
+ if (! digest_file (file, &file_is_binary, bin_buffer, &missing))
ok = false;
else
{