From: Marek VavruĊĦa Date: Fri, 20 Apr 2018 03:15:19 +0000 (-0700) Subject: lib/generic/pack: fix operations on empty pack X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b7dbb94cadeba49430619ded9de9ea90dd92c906;p=thirdparty%2Fknot-resolver.git lib/generic/pack: fix operations on empty pack 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). --- diff --git a/lib/generic/pack.h b/lib/generic/pack.h index dc7a97591..270630dc5 100644 --- a/lib/generic/pack.h +++ b/lib/generic/pack.h @@ -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) {