Skip to content

Commit

Permalink
nfc: platform: Fix NULL pointer check and potential dereference
Browse files Browse the repository at this point in the history
Fix potential NULL pointer dereferencing in ring_buf_get_data function.

Jira: NCSDK-27132

Signed-off-by: Dominik Chat <dominik.chat@nordicsemi.no>
  • Loading branch information
dchat-nordic authored and nordicjm committed Aug 29, 2024
1 parent 4583376 commit dc0efd4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,7 @@ Libraries for NFC
-----------------

* Added an experimental serialization of NFC tag 2 and tag 4 APIs.
* Fixed a potential issue with handling data pointers in the function ``ring_buf_get_data`` in the :file:`platform_internal_thread` file.

nRF RPC libraries
-----------------
Expand Down
6 changes: 5 additions & 1 deletion subsys/nfc/lib/platform_internal_thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ static int ring_buf_get_data(struct ring_buf *buf, uint8_t **data, uint32_t size
uint32_t tmp;
int err;

if (!buf || !data || !is_alloc) {
return -EINVAL;
}

*is_alloc = false;

/* Try to access data without copying.
Expand All @@ -79,7 +83,7 @@ static int ring_buf_get_data(struct ring_buf *buf, uint8_t **data, uint32_t size
}

*data = k_malloc(size);
if (data == NULL) {
if (*data == NULL) {
LOG_DBG("Could not allocate %d bytes.", size);
return -ENOMEM;
}
Expand Down

0 comments on commit dc0efd4

Please sign in to comment.