]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
lib/utils: fixed recycle on already filled packet
authorMarek Vavruša <marek.vavrusa@nic.cz>
Fri, 3 Jul 2015 22:25:38 +0000 (00:25 +0200)
committerMarek Vavruša <marek.vavrusa@nic.cz>
Fri, 3 Jul 2015 22:25:52 +0000 (00:25 +0200)
daemon/bindings/kres.c
lib/utils.h

index 01aebf1ca7e9cadcb48ea9f5ac216324290cd627..1e765a4e63d91dbf1bc46feb7f218fc923d868f1 100644 (file)
@@ -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;
 }
index 405be2c2f9b60c6c78edc70b81d35aea31d0e067..5c9f8a20f9c44d74bd0dba9d5e5e1c312fcd180c 100644 (file)
@@ -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)