dedup

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

commit 083901e286dddcf542979c1037dea36a5f7ab1b1
parent 41722ed34fe2e6aa8442410a91cbdd231e56b00a
Author: sin <sin@2f30.org>
Date:   Thu, 28 Feb 2019 13:19:15 +0000

Do not modify type in the serialization function

Diffstat:
Mdedup.c | 15+++++++++++++--
Mtypes.c | 8--------
2 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/dedup.c b/dedup.c @@ -106,9 +106,20 @@ print_stats(struct stats *st) static void append_snap(struct snapshot *snap) { + if (mul_overflow(snap->nr_blk_descs, BLK_DESC_LEN)) + errx(1, "%s: overflow", __func__); + snap->size = snap->nr_blk_descs * BLK_DESC_LEN; + + if (add_overflow(SNAPSHOT_LEN, snap->size)) + errx(1, "%s: overflow", __func__); + snap->size += SNAPSHOT_LEN; + xlseek(ifd, snap_hdr.size, SEEK_SET); write_snapshot(ifd, snap); write_snapshot_blk_descs(ifd, snap); + + if (add_overflow(snap_hdr.size, snap->size)) + errx(1, "%s: overflow", __func__); snap_hdr.size += snap->size; snap_hdr.nr_snapshots++; } @@ -136,11 +147,11 @@ grow_snap(struct snapshot *snap, uint64_t nr_blk_descs) size_t size; if (mul_overflow(nr_blk_descs, sizeof(snap->blk_desc[0]))) - errx(1, "grow_snap: overflow"); + errx(1, "%s: overflow", __func__); size = nr_blk_descs * sizeof(snap->blk_desc[0]); if (add_overflow(size, sizeof(*snap))) - errx(1, "grow_snap: overflow"); + errx(1, "%s: overflow", __func__); size += sizeof(*snap); snap = realloc(snap, size); diff --git a/types.c b/types.c @@ -184,14 +184,6 @@ write_snapshot(int fd, struct snapshot *snap) char fmt[BUFSIZ]; int n; - if (mul_overflow(snap->nr_blk_descs, BLK_DESC_LEN)) - errx(1, "write_snapshot: overflow"); - snap->size = snap->nr_blk_descs * BLK_DESC_LEN; - - if (add_overflow(SNAPSHOT_LEN, snap->size)) - errx(1, "write_snapshot: overflow"); - snap->size += SNAPSHOT_LEN; - snprintf(fmt, sizeof(fmt), "q'%d'%dq", MSGSIZE, MDSIZE); n = pack(buf, fmt, snap->size,