summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2017-04-26 21:10:43 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2017-04-26 21:10:43 +0000
commitedb3b0b1375519aabc914d8ea8b9a1cf43ffa5ff (patch)
treed3fb78f1910796549ea96b6fdf04fa972b6abd05 /bin
parentab33d46067de22f4cbf13808adadac88cc9e9f46 (diff)
In -C mode, process all checksums that match the specified file(s),
not just the first one that matches. OK deraadt@
Diffstat (limited to 'bin')
-rw-r--r--bin/md5/md5.c28
1 files changed, 22 insertions, 6 deletions
diff --git a/bin/md5/md5.c b/bin/md5/md5.c
index 3f83f721570..c59f48b5e06 100644
--- a/bin/md5/md5.c
+++ b/bin/md5/md5.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: md5.c,v 1.89 2016/12/16 17:55:26 krw Exp $ */
+/* $OpenBSD: md5.c,v 1.90 2017/04/26 21:10:42 millert Exp $ */
/*
* Copyright (c) 2001,2003,2005-2007,2010,2013,2014
@@ -554,6 +554,7 @@ digest_filelist(const char *file, struct hash_function *defhash, int selcount,
char *lbuf = NULL;
FILE *listfp, *fp;
size_t len, nread;
+ int *sel_found = NULL;
u_char data[32 * 1024];
union ANY_CTX context;
struct hash_function *hf;
@@ -565,6 +566,12 @@ digest_filelist(const char *file, struct hash_function *defhash, int selcount,
return(1);
}
+ if (sel != NULL) {
+ sel_found = calloc((size_t)selcount, sizeof(*sel_found));
+ if (sel_found == NULL)
+ err(1, NULL);
+ }
+
algorithm_max = algorithm_min = strlen(functions[0].name);
for (hf = &functions[1]; hf->name != NULL; hf++) {
len = strlen(hf->name);
@@ -673,13 +680,11 @@ digest_filelist(const char *file, struct hash_function *defhash, int selcount,
/*
* If only a selection of files is wanted, proceed only
* if the filename matches one of those in the selection.
- * Mark found files by setting them to NULL so that we can
- * detect files that are missing from the checklist later.
*/
- if (sel) {
+ if (sel != NULL) {
for (i = 0; i < selcount; i++) {
- if (sel[i] && strcmp(sel[i], filename) == 0) {
- sel[i] = NULL;
+ if (strcmp(sel[i], filename) == 0) {
+ sel_found[i] = 1;
break;
}
}
@@ -725,6 +730,17 @@ digest_filelist(const char *file, struct hash_function *defhash, int selcount,
if (!found)
warnx("%s: no properly formatted checksum lines found", file);
free(lbuf);
+ if (sel_found != NULL) {
+ /*
+ * Mark found files by setting them to NULL so that we can
+ * detect files that are missing from the checklist later.
+ */
+ for (i = 0; i < selcount; i++) {
+ if (sel_found[i])
+ sel[i] = NULL;
+ }
+ free(sel_found);
+ }
return(error || !found);
}