Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions subsys/net/lib/dns/dns_pack.c
Original file line number Diff line number Diff line change
Expand Up @@ -479,10 +479,9 @@
}

/* Returns the length of the unpacked name */
static int dns_unpack_name(const uint8_t *msg, int maxlen, const uint8_t *src,

Check failure on line 482 in subsys/net/lib/dns/dns_pack.c

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this function to reduce its Cognitive Complexity from 28 to the 25 allowed.

See more on https://sonarcloud.io/project/issues?id=zephyrproject-rtos_zephyr&issues=AZq1jWGAu09CkqfykYKL&open=AZq1jWGAu09CkqfykYKL&pullRequest=99900
struct net_buf *buf, const uint8_t **eol)
{
int dest_size = net_buf_tailroom(buf);
const uint8_t *end_of_label = NULL;
const uint8_t *curr_src = src;
int loop_check = 0, len = -1;
Expand Down Expand Up @@ -521,6 +520,8 @@
return -EMSGSIZE;
}
} else {
size_t dest_size = net_buf_tailroom(buf);

/* Max label length is 64 bytes (because 2 bits are
* used for pointer)
*/
Expand All @@ -529,8 +530,7 @@
return -EMSGSIZE;
}

if (((buf->data + label_len + 1) >=
(buf->data + dest_size)) ||
if ((label_len + 1 >= dest_size) ||
((curr_src + label_len) >= (msg + maxlen))) {
return -EMSGSIZE;
}
Expand Down
Loading