On Tue, 28 Mar 2017 11:56:19 -0600 "Todd C. Miller" wrote:
> On Tue, 28 Mar 2017 09:33:53 -0600, "Todd C. Miller" wrote:
> 
> > It seems to me that in -C mode it should really process all the
> > checksums that match the specified file(s), but the documentation
> > does not actually specify what the behavior is in this case.
> 
> Here's a diff that accomplishes that.
> 
>  - todd


Who's OK with Todd's proved patch?


> 
> Index: bin/md5/md5.c
> ===================================================================
> RCS file: /cvs/src/bin/md5/md5.c,v
> retrieving revision 1.89
> diff -u -p -u -r1.89 md5.c
> --- bin/md5/md5.c     16 Dec 2016 17:55:26 -0000      1.89
> +++ bin/md5/md5.c     28 Mar 2017 17:54:05 -0000
> @@ -554,6 +554,7 @@ digest_filelist(const char *file, struct
>       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
>               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
>               /*
>                * 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
>       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);
>  }
>  
> 

Reply via email to