]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
lib/generic/pack: fix operations on empty pack
authorMarek Vavruša <mvavrusa@cloudflare.com>
Fri, 20 Apr 2018 03:15:19 +0000 (20:15 -0700)
committerMarek Vavruša <mvavrusa@cloudflare.com>
Fri, 7 Sep 2018 17:45:21 +0000 (10:45 -0700)
Several operations were not safe to call on empty pack and would
return invalid memory. If the pack would have reserved space, but
would be empty (length = 0), it's head would be NULL but tail would
be array address (pack->at + 0). This is mostly checked by caller,
but it wasn't in several places (object deletion).

lib/generic/pack.h

index dc7a97591ce20a5d67f1d8a9728957af3045edd1..270630dc5d73d4c0526df6cd56a8ddea9237c8bd 100644 (file)
@@ -184,6 +184,7 @@ static inline uint8_t *pack_obj_find(pack_t *pack, const uint8_t *obj, pack_objl
                        assert(obj != NULL);
                        return NULL;
                }
+
                uint8_t *endp = pack_tail(*pack);
                uint8_t *it = pack_head(*pack);
                while (it != endp) {
@@ -205,6 +206,7 @@ static inline int pack_obj_del(pack_t *pack, const uint8_t *obj, pack_objlen_t l
                assert(obj != NULL);
                return kr_error(EINVAL);
        }
+
        uint8_t *endp = pack_tail(*pack);
        uint8_t *it = pack_obj_find(pack, obj, len);
        if (it) {