Skip to content

Commit

Permalink
Fix nasa#444, Adds JSC 2.1 Static Analysis comments and adds OS_strnlen
Browse files Browse the repository at this point in the history
This commit addresses issues flagged during static analysis by:
- Adding JSC 2.1 disposition comments.
- Replacing strlen with OS_strnlen.
  • Loading branch information
jdfiguer authored and jdfiguer committed Jun 27, 2024
1 parent 12eff1c commit a788a3f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 20 deletions.
20 changes: 2 additions & 18 deletions fsw/src/cf_cfdp.c
Original file line number Diff line number Diff line change
Expand Up @@ -299,22 +299,6 @@ CF_Logical_PduBuffer_t *CF_CFDP_ConstructPduHeader(const CF_Transaction_t *txn,
return ph;
}

/*----------------------------------------------------------------
*
* Internal helper routine only, not part of API.
*
*-----------------------------------------------------------------*/
static inline size_t CF_strnlen(const char *str, size_t maxlen)
{
const char *end = memchr(str, 0, maxlen);
if (end != NULL)
{
/* actual length of string is difference */
maxlen = end - str;
}
return maxlen;
}

/*----------------------------------------------------------------
*
* Application-scope internal function
Expand Down Expand Up @@ -344,10 +328,10 @@ CFE_Status_t CF_CFDP_SendMd(CF_Transaction_t *txn)
/* at this point, need to append filenames into md packet */
/* this does not actually copy here - that is done during encode */
md->source_filename.length =
CF_strnlen(txn->history->fnames.src_filename, sizeof(txn->history->fnames.src_filename));
OS_strnlen(txn->history->fnames.src_filename, sizeof(txn->history->fnames.src_filename));
md->source_filename.data_ptr = txn->history->fnames.src_filename;
md->dest_filename.length =
CF_strnlen(txn->history->fnames.dst_filename, sizeof(txn->history->fnames.dst_filename));
OS_strnlen(txn->history->fnames.dst_filename, sizeof(txn->history->fnames.dst_filename));
md->dest_filename.data_ptr = txn->history->fnames.dst_filename;

CF_CFDP_EncodeMd(ph->penc, md);
Expand Down
5 changes: 4 additions & 1 deletion fsw/src/cf_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,20 +184,23 @@ CFE_Status_t CF_WriteHistoryEntryToFile(osal_id_t fd, const CF_History_t *histor
{
case 0:
CF_Assert(history->dir < CF_Direction_NUM);
/* SAD: No need to check snprintf return; buffer size is sufficient for the formatted output */
snprintf(linebuf, sizeof(linebuf), "SEQ (%lu, %lu)\tDIR: %s\tPEER %lu\tSTAT: %d\t",
(unsigned long)history->src_eid, (unsigned long)history->seq_num, CF_DSTR[history->dir],
(unsigned long)history->peer_eid, (int)history->txn_stat);
break;
case 1:
/* SAD: No need to check snprintf return; buffer size is sufficient for the formatted output */
snprintf(linebuf, sizeof(linebuf), "SRC: %s\t", history->fnames.src_filename);
break;
case 2:
default:
/* SAD: No need to check snprintf return; buffer size is sufficient for the formatted output */
snprintf(linebuf, sizeof(linebuf), "DST: %s\n", history->fnames.dst_filename);
break;
}

len = strlen(linebuf);
len = OS_strnlen(linebuf, (CF_FILENAME_MAX_LEN * 2) + 128);
ret = CF_WrappedWrite(fd, linebuf, len);
if (ret != len)
{
Expand Down
2 changes: 1 addition & 1 deletion unit-test/stubs/cf_utils_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void UT_DefaultHandler_CF_WriteTxnQueueDataToFile(void *, UT_EntryKey_t, const U
* Generated stub function for CF_FindTransactionBySequenceNumber()
* ----------------------------------------------------
*/
CF_Transaction_t *CF_FindTransactionBySequenceNumber(CF_Channel_t *chan,
CF_Transaction_t *CF_FindTransactionBySequenceNumber(CF_Channel_t * chan,
CF_TransactionSeq_t transaction_sequence_number,
CF_EntityId_t src_eid)
{
Expand Down

0 comments on commit a788a3f

Please sign in to comment.