Browse Source

* Use ftruncate() when writing binary

Bryan Drewery 16 years ago
parent
commit
6c0bdc5aaa
1 changed files with 2 additions and 3 deletions
  1. 2 3
      src/binary.c

+ 2 - 3
src/binary.c

@@ -199,13 +199,12 @@ bin_checksum(const char *fname, int todo)
     if (!(todo & GET_CHECKSUM))
       OPENSSL_cleanse(hash, sizeof(hash));
 
+    if (ftruncate(newbin->fd, size)) goto fatal;
+
     /* Copy everything up to this point into the new binary (including the settings header/prefix) */
     outmap = (unsigned char*) mmap(0, size, PROT_READ|PROT_WRITE, MAP_SHARED, newbin->fd, 0);
     if ((void*)outmap == MAP_FAILED) goto fatal;
 
-    if (lseek(newbin->fd, size - 1, SEEK_SET) == -1) goto fatal;
-    if (write(newbin->fd, "", 1) != 1) goto fatal;
-
     offset += PREFIXLEN;
     memcpy(outmap, map, offset);