From: Eric Bollengier Date: Fri, 5 Aug 2022 08:15:07 +0000 (+0200) Subject: Fix org#2644 Add support for binary files to bacula md5sum X-Git-Tag: Release-13.0.1~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=56453774684030ad1ab62751dc695e7e5cbdffef;p=thirdparty%2Fbacula.git Fix org#2644 Add support for binary files to bacula md5sum --- diff --git a/bacula/src/lib/md5.c b/bacula/src/lib/md5.c index 98e26b3b3..e4bfb7bbf 100644 --- a/bacula/src/lib/md5.c +++ b/bacula/src/lib/md5.c @@ -286,7 +286,7 @@ static void usage() static bool decode = false; /* - * Reads a single ASCII file and prints the HEX md5 sum. + * Reads a single file and prints the HEX md5 sum. */ #include int main(int argc, char *argv[]) @@ -325,8 +325,11 @@ int main(int argc, char *argv[]) goto decode_it; } MD5Init(&ctx); - while (fgets(buf, sizeof(buf), fd)) { - MD5Update(&ctx, (unsigned char *)buf, strlen(buf)); + while (!feof(fd) && !ferror(fd)) { + size_t nb = fread(buf, 1, sizeof(buf), fd); + if (nb > 0) { + MD5Update(&ctx, (unsigned char *)buf, nb); + } } MD5Final((unsigned char *)signature, &ctx); for (int i=0; i < 16; i++) {