From: Marek VavruĊĦa Date: Fri, 3 Jul 2015 22:25:38 +0000 (+0200) Subject: lib/utils: fixed recycle on already filled packet X-Git-Tag: v1.0.0-beta1~88^2~9 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6edb8d291a42a1d354ed693a5afd2d3c91cab6a9;p=thirdparty%2Fknot-resolver.git lib/utils: fixed recycle on already filled packet --- diff --git a/daemon/bindings/kres.c b/daemon/bindings/kres.c index 01aebf1ca..1e765a4e6 100644 --- a/daemon/bindings/kres.c +++ b/daemon/bindings/kres.c @@ -90,7 +90,7 @@ static lookup_table_t wire_flag_names[] = { #define PKT_UDATA_CHECK(L) \ if (!lua_touserdata(L, 1)) { \ - lua_pushstring(L, "bad parameters, expected (pkt[, newvalue])"); \ + lua_pushliteral(L, "bad parameters, expected (pkt[, newvalue])"); \ lua_error(L); \ } @@ -164,7 +164,7 @@ static int pkt_question(lua_State *L) } uint8_t dname[KNOT_DNAME_MAXLEN]; knot_dname_from_str(dname, lua_tostring(L, 2), sizeof(dname)); - if (!knot_dname_is_equal(knot_pkt_qname(pkt), dname)) { + if (!knot_dname_is_equal(knot_pkt_qname(pkt), dname) || pkt->rrset_count > 0) { KR_PKT_RECYCLE(pkt); knot_pkt_put_question(pkt, dname, lua_tointeger(L, 3), lua_tointeger(L, 4)); pkt->parsed = pkt->size; @@ -176,6 +176,10 @@ static int pkt_begin(lua_State *L) { PKT_UDATA_CHECK(L); knot_pkt_t *pkt = lua_touserdata(L, 1); + if (lua_isnil(L, 2) || lua_tonumber(L, 2) < pkt->current) { + lua_pushliteral(L, "bad parameters, expected packet section >= current"); + lua_error(L); + } knot_pkt_begin(pkt, lua_tointeger(L, 2)); return 0; } diff --git a/lib/utils.h b/lib/utils.h index 405be2c2f..5c9f8a20f 100644 --- a/lib/utils.h +++ b/lib/utils.h @@ -36,9 +36,11 @@ extern void _cleanup_fclose(FILE **p); /** @internal Fast packet reset. */ #define KR_PKT_RECYCLE(pkt) do { \ - (pkt)->current = KNOT_ANSWER; \ (pkt)->rrset_count = 0; \ (pkt)->size = KNOT_WIRE_HEADER_SIZE; \ + (pkt)->current = KNOT_ANSWER; \ + memset((pkt)->sections, 0, sizeof((pkt)->sections)); \ + knot_pkt_begin((pkt), KNOT_ANSWER); \ knot_pkt_parse_question((pkt)); \ } while (0)