diff options
author | Marek Vavrusa <marek.vavrusa@nic.cz> | 2013-06-01 15:02:38 +0200 |
---|---|---|
committer | Marek Vavrusa <marek.vavrusa@nic.cz> | 2013-06-03 11:16:14 +0200 |
commit | 994d209f64f6a0774e1c2af362358ca0ab84219f (patch) | |
tree | 4436ec49bf83d0205f6c0f7a180ce84c2bc13199 | |
parent | Return rightmost node when searching for node before leftmost. (diff) | |
download | knot-994d209f64f6a0774e1c2af362358ca0ab84219f.tar.xz knot-994d209f64f6a0774e1c2af362358ca0ab84219f.zip |
Use unsigned bytearray for dname lookup format.
Signed could result to overflow in label length.
Change-Id: Ic1cae2c0df295127940fe1af74561690c0cddc30
-rw-r--r-- | src/libknot/zone/zone-tree.c | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/src/libknot/zone/zone-tree.c b/src/libknot/zone/zone-tree.c index 1f8cb1624..f20f9189c 100644 --- a/src/libknot/zone/zone-tree.c +++ b/src/libknot/zone/zone-tree.c @@ -27,7 +27,7 @@ /* Non-API functions */ /*----------------------------------------------------------------------------*/ -#define DNAME_LFT_MAXLEN 256 /* maximum lookup format length */ +#define DNAME_LFT_MAXLEN 255 /* maximum lookup format length */ /*! * \brief Convert domain name from wire to lookup format. @@ -50,14 +50,16 @@ * \retval KNOT_ESPACE when not enough memory. * \retval KNOT_EINVAL on invalid parameters */ -static int dname_lf(char *dst, const knot_dname_t *src, size_t maxlen) { - if (!src || !dst) return KNOT_EINVAL; - if (src->size > maxlen) return KNOT_ESPACE; - *dst = src->size - 1; - if (*dst == 0) ++*dst; /* root special case */ +static int dname_lf(uint8_t *dst, const knot_dname_t *src, size_t maxlen) { + if (src->size > maxlen) + return KNOT_ESPACE; + *dst = (uint8_t)src->size; + /* need to save last \x00 for root dname */ + if (*dst > 1) + *dst -= 1; *++dst = '\0'; uint8_t* l = src->name; - uint8_t lstack[127]; + uint8_t lstack[DNAME_LFT_MAXLEN]; uint8_t *sp = lstack; while(*l != 0) { /* build label stack */ *sp++ = (l - src->name); @@ -106,10 +108,10 @@ size_t knot_zone_tree_weight(knot_zone_tree_t* tree) int knot_zone_tree_insert(knot_zone_tree_t *tree, knot_node_t *node) { assert(tree && node && node->owner); - char lf[DNAME_LFT_MAXLEN]; + uint8_t lf[DNAME_LFT_MAXLEN]; dname_lf(lf, node->owner, sizeof(lf)); - *hattrie_get(tree, lf+1, *lf) = node; + *hattrie_get(tree, (char*)lf+1, *lf) = node; return KNOT_EOK; } @@ -134,10 +136,10 @@ int knot_zone_tree_get(knot_zone_tree_t *tree, const knot_dname_t *owner, return KNOT_EINVAL; } - char lf[DNAME_LFT_MAXLEN]; + uint8_t lf[DNAME_LFT_MAXLEN]; dname_lf(lf, owner, sizeof(lf)); - value_t *val = hattrie_tryget(tree, lf+1, *lf); + value_t *val = hattrie_tryget(tree, (char*)lf+1, *lf); if (val == NULL) { *found = NULL; } else { @@ -179,11 +181,11 @@ int knot_zone_tree_get_less_or_equal(knot_zone_tree_t *tree, return KNOT_EINVAL; } - char lf[DNAME_LFT_MAXLEN]; + uint8_t lf[DNAME_LFT_MAXLEN]; dname_lf(lf, owner, sizeof(lf)); value_t *fval = NULL; - int ret = hattrie_find_leq(tree, lf+1, *lf, &fval); + int ret = hattrie_find_leq(tree, (char*)lf+1, *lf, &fval); if (fval) *found = (knot_node_t *)(*fval); int exact_match = 0; if (ret == 0) { @@ -235,10 +237,10 @@ int knot_zone_tree_remove(knot_zone_tree_t *tree, return KNOT_EINVAL; } - char lf[DNAME_LFT_MAXLEN]; + uint8_t lf[DNAME_LFT_MAXLEN]; dname_lf(lf, owner, sizeof(lf)); - value_t *rval = hattrie_tryget(tree, lf+1, *lf); + value_t *rval = hattrie_tryget(tree, (char*)lf+1, *lf); if (rval == NULL) { return KNOT_ENOENT; } else { @@ -246,7 +248,7 @@ int knot_zone_tree_remove(knot_zone_tree_t *tree, } - hattrie_del(tree, lf+1, *lf); + hattrie_del(tree, (char*)lf+1, *lf); return KNOT_EOK; } |