]> granicus.if.org Git - curl/commitdiff
tool_metalink.c: Fixed validation of binary files containing EOF
authorMarc Hoersken <info@marc-hoersken.de>
Mon, 10 Sep 2012 23:42:58 +0000 (01:42 +0200)
committerMarc Hoersken <info@marc-hoersken.de>
Mon, 10 Sep 2012 23:42:58 +0000 (01:42 +0200)
Since Windows/MinGW threat 0x1A as the EOF character, reading binary
files which contain that byte does not work using text mode.
The read function will only read until the first 0x1A byte. This
means that the hash is not computed from the whole file and the
final validation check using hash comparision fails.

src/tool_metalink.c

index 6e4a31c43bbaf58d310727ad95cabd3149a8481f..77315871136bcbc766236e4d926457f706f0d8ea 100644 (file)
@@ -339,7 +339,8 @@ static int check_hash(const char *filename,
   digest_context *dctx;
   int check_ok;
   int fd;
-  fd = open(filename, O_RDONLY);
+  /* O_BINARY is required in order to avoid binary EOF in text mode */
+  fd = open(filename, O_RDONLY | O_BINARY);
   if(fd == -1) {
     fprintf(error, "Metalink: validating (%s) FAILED (%s)\n", filename,
             strerror(errno));