Some more sanity checks - dedup - deduplicating backup program HTML git clone git://bitreich.org/dedup/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/dedup/ DIR Log DIR Files DIR Refs DIR Tags DIR README DIR LICENSE --- DIR commit 47ec558f694b05fc961322ec2733ff0cf7826413 DIR parent a6f3624b616e46d60875a82ddc5cd5ce6f62dfbd HTML Author: sin <sin@2f30.org> Date: Thu, 25 Apr 2019 14:00:41 +0100 Some more sanity checks Diffstat: M bstorage.c | 13 +++++++++++++ 1 file changed, 13 insertions(+), 0 deletions(-) --- DIR diff --git a/bstorage.c b/bstorage.c @@ -84,12 +84,14 @@ struct sctx { int rdonly; }; +#define NCALGOS 2 static char *ctbl[] = { "none", "snappy", NULL, }; +#define NHALGOS 1 static char *htbl[] = { "blake2b", NULL, @@ -396,8 +398,19 @@ bsopen(struct bctx *bctx, char *path, int flags, int mode, struct bparam *bpar) } calgo = (bhdr->flags >> CALGOSHIFT) & CALGOMASK; + if (calgo < 0 || calgo >= NCALGOS) { + free(sctx); + close(fd); + return -1; + } bpar->calgo = ctbl[calgo]; + halgo = (bhdr->flags >> CALGOSHIFT) & CALGOMASK; + if (halgo < 0 || halgo >= NHALGOS) { + free(sctx); + close(fd); + return -1; + } bpar->halgo = htbl[halgo]; sctx->fd = fd;