]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
Fix org#2644 Add support for binary files to bacula md5sum
authorEric Bollengier <eric@baculasystems.com>
Fri, 5 Aug 2022 08:15:07 +0000 (10:15 +0200)
committerEric Bollengier <eric@baculasystems.com>
Fri, 5 Aug 2022 08:16:39 +0000 (10:16 +0200)
bacula/src/lib/md5.c

index 98e26b3b38c8d345f855f4339e3624b4acce66b4..e4bfb7bbf990db02e7c74fc55a54b47ea39e8d04 100644 (file)
@@ -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 <stdio.h>
 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++) {