dedup

data deduplication program
git clone git://git.2f30.org/dedup.git
Log | Files | Refs | LICENSE

commit e11aca811109d7e85694e8fbe2773ef5b9068e19
parent a346481d84a075c0cc245535a251e131863445b8
Author: sin <sin@2f30.org>
Date:   Wed, 21 Mar 2018 09:48:50 +0000

Check for EOF on input

Diffstat:
dedup.c | 20++++++++++++++------
1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/dedup.c b/dedup.c @@ -164,7 +164,8 @@ void read_blk(struct blk *blk, off_t blkidx) { lseek(sfd, blkidx * sizeof(*blk), SEEK_SET); - xread(sfd, blk, sizeof(*blk)); + if (xread(sfd, blk, sizeof(*blk)) == 0) + errx(1, "unexpected EOF"); } void @@ -256,9 +257,12 @@ extract(unsigned char *id, int fd) lseek(ifd, sizeof(enthdr), SEEK_SET); for (i = 0; i < enthdr.nents; i++) { ent = alloc_ent(); - xread(ifd, ent, sizeof(*ent)); + if (xread(ifd, ent, sizeof(*ent)) == 0) + errx(1, "unexpected EOF"); ent = grow_ent(ent, ent->nblks); - xread(ifd, ent->blks, ent->nblks * sizeof(ent->blks[0])); + if (xread(ifd, ent->blks, + ent->nblks * sizeof(ent->blks[0])) == 0) + errx(1, "unexpected EOF"); if (memcmp(ent->md, md, sizeof(ent->md)) == 0) { uint64_t j; @@ -312,9 +316,12 @@ dump_index(void) lseek(ifd, sizeof(enthdr), SEEK_SET); for (i = 0; i < enthdr.nents; i++) { ent = alloc_ent(); - xread(ifd, ent, sizeof(*ent)); + if (xread(ifd, ent, sizeof(*ent)) == 0) + errx(1, "unexpected EOF"); ent = grow_ent(ent, ent->nblks); - xread(ifd, ent->blks, ent->nblks * sizeof(ent->blks[0])); + if (xread(ifd, ent->blks, + ent->nblks * sizeof(ent->blks[0])) == 0) + errx(1, "unexpected EOF"); dump_ent(ent); free(ent); } @@ -329,7 +336,8 @@ list(void) for (i = 0; i < enthdr.nents; i++) { struct ent ent; - xread(ifd, &ent, sizeof(ent)); + if (xread(ifd, &ent, sizeof(ent)) == 0) + errx(1, "unexpected EOF"); dump_md(ent.md, sizeof(ent.md)); putchar('\n'); lseek(ifd, ent.nblks * sizeof(ent.blks[0]), SEEK_CUR);