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
8 changes: 6 additions & 2 deletions fsw/src/cf_cfdp.c
Original file line number Diff line number Diff line change
Expand Up @@ -2237,7 +2237,11 @@ void CF_CFDP_SendEotPkt(CF_Transaction_t *txn)
*-----------------------------------------------------------------*/
int CF_CFDP_CopyStringFromLV(char *buf, size_t buf_maxsz, const CF_Logical_Lv_t *src_lv)
{
if (src_lv->length < buf_maxsz)
/* Guard against a NULL data_ptr, which CF_CFDP_DoDecodeChunk sets when the
* claimed LV length exceeds the remaining PDU bytes. Without this check a
* crafted PDU can trigger memcpy(buf, NULL, n) — undefined behaviour that
* causes a NULL-pointer dereference on most platforms. */
if (src_lv->data_ptr != NULL && src_lv->length < buf_maxsz)
{
memcpy(buf, src_lv->data_ptr, src_lv->length);
buf[src_lv->length] = 0;
Expand All @@ -2246,7 +2250,7 @@ int CF_CFDP_CopyStringFromLV(char *buf, size_t buf_maxsz, const CF_Logical_Lv_t

/* ensure output is empty */
buf[0] = 0;
return CF_ERROR; /* invalid len in lv? */
return CF_ERROR;
}

/*----------------------------------------------------------------
Expand Down
Loading