Check {compr,hash}_init() for failures - dedup - deduplicating backup program
 (HTM) git clone git://bitreich.org/dedup/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/dedup/
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) Tags
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 738efabad162925277a2e7bb809ea127fd75d497
 (DIR) parent 4a21ac05f96b79113658a5adc1c04bde99bd8118
 (HTM) Author: sin <sin@2f30.org>
       Date:   Wed, 10 Apr 2019 13:48:52 +0100
       
       Check {compr,hash}_init() for failures
       
       This can happen if an old version of dedup is used on a new store that
       uses newer compression/hash algorithms.
       
       Diffstat:
         M dedup.c                             |      21 ++++++++++++++-------
       
       1 file changed, 14 insertions(+), 7 deletions(-)
       ---
 (DIR) diff --git a/dedup.c b/dedup.c
       @@ -109,7 +109,8 @@ hash_snap(struct snap *snap, uint8_t *md)
                struct hash_ctx ctx;
                uint64_t i;
        
       -        hash_init(&ctx, hash_algo, MD_SIZE);
       +        if (hash_init(&ctx, hash_algo, MD_SIZE) < 0)
       +                errx(1, "hash_init failed");
                for (i = 0; i < snap->nr_blk_descs; i++) {
                        struct blk_desc *blk_desc;
        
       @@ -184,7 +185,8 @@ hash_blk(uint8_t *buf, size_t size, uint8_t *md)
        {
                struct hash_ctx ctx;
        
       -        hash_init(&ctx, hash_algo, MD_SIZE);
       +        if (hash_init(&ctx, hash_algo, MD_SIZE) < 0)
       +                errx(1, "hash_init failed");
                hash_update(&ctx, buf, size);
                hash_final(&ctx, md, MD_SIZE);
        }
       @@ -222,7 +224,8 @@ dedup_chunk(struct snap *snap, uint8_t *chunkp, size_t chunk_size)
                uint8_t *compr_buf;
                size_t n, csize;
        
       -        compr_init(&ctx, compr_algo);
       +        if (compr_init(&ctx, compr_algo) < 0)
       +                errx(1, "compr_init failed");
                csize = compr_size(&ctx, BLKSIZE_MAX);
                compr_buf = alloc_buf(csize);
        
       @@ -306,7 +309,8 @@ extract(struct snap *snap, void *arg)
                if (memcmp(snap->md, args->md, sizeof(snap->md)) != 0)
                        return WALK_CONTINUE;
        
       -        compr_init(&ctx, compr_algo);
       +        if (compr_init(&ctx, compr_algo) < 0)
       +                errx(1, "compr_init failed");
                buf[0] = alloc_buf(BLKSIZE_MAX);
                buf[1] = alloc_buf(compr_size(&ctx, BLKSIZE_MAX));
                for (i = 0; i < snap->nr_blk_descs; i++) {
       @@ -344,7 +348,8 @@ check_snap(struct snap *snap, void *arg)
                        fputc('\n', stderr);
                }
        
       -        compr_init(&ctx, compr_algo);
       +        if (compr_init(&ctx, compr_algo) < 0)
       +                errx(1, "compr_init failed");
                buf = alloc_buf(compr_size(&ctx, BLKSIZE_MAX));
                for (i = 0; i < snap->nr_blk_descs; i++) {
                        uint8_t md[MD_SIZE];
       @@ -382,7 +387,8 @@ build_icache(struct snap *snap, void *arg)
                uint8_t *buf;
                uint64_t i;
        
       -        compr_init(&ctx, compr_algo);
       +        if (compr_init(&ctx, compr_algo) < 0)
       +                errx(1, "compr_init failed");
                buf = alloc_buf(compr_size(&ctx, BLKSIZE_MAX));
                for (i = 0; i < snap->nr_blk_descs; i++) {
                        struct blk_desc *blk_desc;
       @@ -481,7 +487,8 @@ init_snap_hdr(void)
        {
                struct compr_ctx ctx;
        
       -        compr_init(&ctx, compr_algo);
       +        if (compr_init(&ctx, compr_algo) < 0)
       +                errx(1, "compr_init failed");
                snap_hdr.flags = (VER_MAJ << VER_MAJ_SHIFT) | VER_MIN;
                snap_hdr.size = SNAP_HDR_SIZE;
                snap_hdr.st.min_blk_size = compr_size(&ctx, BLKSIZE_MAX);