commit 47ec558f694b05fc961322ec2733ff0cf7826413
parent a6f3624b616e46d60875a82ddc5cd5ce6f62dfbd
Author: sin <sin@2f30.org>
Date: Thu, 25 Apr 2019 14:00:41 +0100
Some more sanity checks
Diffstat:
1 file changed, 13 insertions(+), 0 deletions(-)
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;