Skip to content
Snippets Groups Projects
Commit 6edb8d29 authored by Marek Vavruša's avatar Marek Vavruša
Browse files

lib/utils: fixed recycle on already filled packet

parent cca93b11
No related branches found
No related tags found
No related merge requests found
......@@ -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;
}
......
......@@ -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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment