Skip to content

Commit

Permalink
fix memory leak if "<root>" is dns query (arkime#3088)
Browse files Browse the repository at this point in the history
  • Loading branch information
awick authored Jan 14, 2025
1 parent d5f943f commit 516b65f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ NOTICE: Create a parliament config file before upgrading (see https://arkime.com
- #3083 new _flipSrcDst rule action
- #3083 new tcp.synSet rule field
- #3083 rules can now use values of "${configvar}"
- #3088 fix memory leak if "<root>" is dns query
## Viewer
- #3055 fix missing session.network section error
- #3059 fix losing custom theme setting
Expand Down
20 changes: 11 additions & 9 deletions capture/parsers/dns.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ void dns_free_object(ArkimeFieldObject_t *object);
uint32_t dns_hash(const void *key);
int dns_cmp(const void *keyv, const void *elementv);

LOCAL char *root = "<root>";

/******************************************************************************/
LOCAL void dns_free(ArkimeSession_t *UNUSED(session), void *uw)
{
Expand Down Expand Up @@ -526,7 +528,7 @@ LOCAL void dns_parser(ArkimeSession_t *session, int kind, const uint8_t *data, i
}

if (!namelen) {
key.query.hostname = (char *)"<root>";
key.query.hostname = root;
namelen = 6;
} else {
key.query.hostname = g_hostname_to_unicode(name);
Expand Down Expand Up @@ -590,7 +592,7 @@ LOCAL void dns_parser(ArkimeSession_t *session, int kind, const uint8_t *data, i

fobject->object = dns;

if (strcmp(key.query.hostname, "<root>") != 0) {
if (key.query.hostname != root) {
int hostlen = strlen(dns->query.hostname);
if (g_utf8_validate(dns->query.hostname, hostlen, NULL)) {
ArkimeString_t *element;
Expand Down Expand Up @@ -621,7 +623,7 @@ LOCAL void dns_parser(ArkimeSession_t *session, int kind, const uint8_t *data, i
}
arkime_field_object_add(dnsField, session, fobject, jsonLen);
} else {
if (strcmp(key.query.hostname, "<root>") != 0)
if (key.query.hostname != root)
g_free(key.query.hostname);
dns = fobject->object;
}
Expand Down Expand Up @@ -659,7 +661,7 @@ LOCAL void dns_parser(ArkimeSession_t *session, int kind, const uint8_t *data, i
DNSAnswer_t *answer = ARKIME_TYPE_ALLOC0(DNSAnswer_t);

if (!namelen) {
answer->name = (char *)"<root>";
answer->name = root;
namelen = 6;
} else {
answer->name = g_hostname_to_unicode(name);
Expand Down Expand Up @@ -692,7 +694,7 @@ LOCAL void dns_parser(ArkimeSession_t *session, int kind, const uint8_t *data, i
BSB_IMPORT_u16 (bsb, rdlength);

if (BSB_REMAINING(bsb) < rdlength) {
if (answer->name && !(strcmp(answer->name, "<root>") == 0)) {
if (answer->name && answer->name != root) {
g_free(answer->name);
}
ARKIME_TYPE_FREE(DNSAnswer_t, answer);
Expand Down Expand Up @@ -948,7 +950,7 @@ LOCAL void dns_parser(ArkimeSession_t *session, int kind, const uint8_t *data, i
continue;

continueerr:
if (answer->name && !(strcmp(answer->name, "<root>") == 0)) {
if (answer->name && answer->name != root) {
g_free(answer->name);
}
ARKIME_TYPE_FREE(DNSAnswer_t, answer);
Expand Down Expand Up @@ -1339,7 +1341,7 @@ void dns_save(BSB *jbsb, ArkimeFieldObject_t *object, struct arkime_session *ses

BSB_EXPORT_sprintf(*jbsb, "\"name\":\"%s\",", answer->name);

if (answer->name && !(strcmp(answer->name, "<root>") == 0)) {
if (answer->name && answer->name != root) {
g_free(answer->name);
}

Expand Down Expand Up @@ -1463,13 +1465,13 @@ void dns_free_object(ArkimeFieldObject_t *object)
break;
}

if (answer->name && !(strcmp(answer->name, "<root>") == 0)) {
if (answer->name && answer->name != root) {
g_free(answer->name);
}
ARKIME_TYPE_FREE(DNSAnswer_t, answer);
}

if (dns->query.hostname && !(strcmp(dns->query.hostname, "<root>") == 0)) {
if (dns->query.hostname && dns->query.hostname != root) {
g_free(dns->query.hostname);
}

Expand Down

0 comments on commit 516b65f

Please sign in to comment.