dedup

deduplicating backup program
git clone git://git.2f30.org/dedup
Log | Files | Refs | README | LICENSE

commit 758c94cb0be5e019637a9143e9f22601ab4a708b
parent ed26c07028c2c908351edbba0152e59d3fe1fb88
Author: sin <sin@2f30.org>
Date:   Thu, 25 Apr 2019 17:44:32 +0100

Check magic outside of unpack just like the other fields

Diffstat:
Mbstorage.c | 9+++++++--
1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/bstorage.c b/bstorage.c @@ -184,8 +184,6 @@ unpackbhdr(int fd, struct bhdr *bhdr) &bhdr->nent); assert(n == sizeof(buf)); - if (memcmp(bhdr->magic, BHDRMAGIC, NBHDRMAGIC) != 0) - return -1; return n; } @@ -399,6 +397,13 @@ bsopen(struct bctx *bctx, char *path, int flags, int mode, struct bparam *bpar) return -1; } + /* Check magic */ + if (memcmp(bhdr->magic, BHDRMAGIC, NBHDRMAGIC) != 0) { + free(sctx); + close(fd); + return -1; + } + /* If the major version is different, the format is incompatible */ if (((bhdr->flags >> VMAJSHIFT) & VMAJMASK) != VMAJ) { free(sctx);