Skip to content

Commit

Permalink
lib: modem_key_mgmt: update modem_key_mgmt.c
Browse files Browse the repository at this point in the history
Added support to return ENOMEM errno when buffer length doesnot
match certificate length

Signed-off-by: Nirmal Krishna <nirmal.rathakrishnan@nordicsemi.no>
  • Loading branch information
MechanicV1 authored and cvinayak committed Jun 21, 2023
1 parent e434ec2 commit 1619d7a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
4 changes: 4 additions & 0 deletions doc/nrf/releases/release-notes-changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,10 @@ Modem libraries

* Updated the library to allow a ``PDP_type``-only configuration in the :c:func:`pdn_ctx_configure` function.

* :ref:`nrf_modem_lib_readme`:

* Updated the :c:func:`modem_key_mgmt_cmp` function to return ``1`` if the buffer length does not match the certificate length.

Libraries for networking
------------------------

Expand Down
22 changes: 16 additions & 6 deletions lib/modem_key_mgmt/modem_key_mgmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ int modem_key_mgmt_cmp(nrf_sec_tag_t sec_tag,
const void *buf, size_t len)
{
int err;
char *p;
char *begin, *end;

if (buf == NULL) {
return -EINVAL;
Expand All @@ -199,16 +199,26 @@ int modem_key_mgmt_cmp(nrf_sec_tag_t sec_tag,
return err;
}

p = scratch_buf;
begin = scratch_buf;
for (size_t i = 0; i < 3; i++) {
p = strchr(p, '\"');
if (!p) {
begin = strchr(begin, '\"');
if (!begin) {
return -ENOENT;
}
p++;
begin++;
}

end = strchr(begin, '\"');
if (!end) {
return -ENOENT;
}

if (end - begin != len) {
LOG_DBG("Credential length mismatch");
return 1;
}

if (memcmp(p, buf, len)) {
if (memcmp(begin, buf, len)) {
LOG_DBG("Credential data mismatch");
return 1;
}
Expand Down

0 comments on commit 1619d7a

Please sign in to comment.