Skip to content

Commit e6c6266

Browse files
jdfiguerjdfiguer
jdfiguer
authored and
jdfiguer
committed
Fix nasa#444, Adds JSC 2.1 Static Analysis comments and adds OS_strnlen
This commit addresses issues flagged during static analysis by: - Adding JSC 2.1 disposition comments. - Replacing strlen with OS_strnlen.
1 parent 12eff1c commit e6c6266

File tree

4 files changed

+11
-20
lines changed

4 files changed

+11
-20
lines changed

fsw/src/cf_cfdp.c

+2-18
Original file line numberDiff line numberDiff line change
@@ -299,22 +299,6 @@ CF_Logical_PduBuffer_t *CF_CFDP_ConstructPduHeader(const CF_Transaction_t *txn,
299299
return ph;
300300
}
301301

302-
/*----------------------------------------------------------------
303-
*
304-
* Internal helper routine only, not part of API.
305-
*
306-
*-----------------------------------------------------------------*/
307-
static inline size_t CF_strnlen(const char *str, size_t maxlen)
308-
{
309-
const char *end = memchr(str, 0, maxlen);
310-
if (end != NULL)
311-
{
312-
/* actual length of string is difference */
313-
maxlen = end - str;
314-
}
315-
return maxlen;
316-
}
317-
318302
/*----------------------------------------------------------------
319303
*
320304
* Application-scope internal function
@@ -344,10 +328,10 @@ CFE_Status_t CF_CFDP_SendMd(CF_Transaction_t *txn)
344328
/* at this point, need to append filenames into md packet */
345329
/* this does not actually copy here - that is done during encode */
346330
md->source_filename.length =
347-
CF_strnlen(txn->history->fnames.src_filename, sizeof(txn->history->fnames.src_filename));
331+
OS_strnlen(txn->history->fnames.src_filename, sizeof(txn->history->fnames.src_filename));
348332
md->source_filename.data_ptr = txn->history->fnames.src_filename;
349333
md->dest_filename.length =
350-
CF_strnlen(txn->history->fnames.dst_filename, sizeof(txn->history->fnames.dst_filename));
334+
OS_strnlen(txn->history->fnames.dst_filename, sizeof(txn->history->fnames.dst_filename));
351335
md->dest_filename.data_ptr = txn->history->fnames.dst_filename;
352336

353337
CF_CFDP_EncodeMd(ph->penc, md);

fsw/src/cf_utils.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -184,20 +184,23 @@ CFE_Status_t CF_WriteHistoryEntryToFile(osal_id_t fd, const CF_History_t *histor
184184
{
185185
case 0:
186186
CF_Assert(history->dir < CF_Direction_NUM);
187+
/* SAD: No need to check snprintf return; buffer size is sufficient for the formatted output */
187188
snprintf(linebuf, sizeof(linebuf), "SEQ (%lu, %lu)\tDIR: %s\tPEER %lu\tSTAT: %d\t",
188189
(unsigned long)history->src_eid, (unsigned long)history->seq_num, CF_DSTR[history->dir],
189190
(unsigned long)history->peer_eid, (int)history->txn_stat);
190191
break;
191192
case 1:
193+
/* SAD: No need to check snprintf return; buffer size is sufficient for the formatted output */
192194
snprintf(linebuf, sizeof(linebuf), "SRC: %s\t", history->fnames.src_filename);
193195
break;
194196
case 2:
195197
default:
198+
/* SAD: No need to check snprintf return; buffer size is sufficient for the formatted output */
196199
snprintf(linebuf, sizeof(linebuf), "DST: %s\n", history->fnames.dst_filename);
197200
break;
198201
}
199202

200-
len = strlen(linebuf);
203+
len = OS_strnlen(linebuf, (CF_FILENAME_MAX_LEN * 2) + 128);
201204
ret = CF_WrappedWrite(fd, linebuf, len);
202205
if (ret != len)
203206
{

unit-test/cf_cfdp_tests.c

+4
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,8 @@ void Test_CF_CFDP_SendMd(void)
611611
strncpy(history->fnames.src_filename, "src1", sizeof(history->fnames.src_filename));
612612
txn->state = CF_TxnState_S1;
613613
txn->fsize = 1234;
614+
UT_SetDefaultReturnValue(UT_KEY(OS_strnlen), strlen(history->fnames.src_filename));
615+
UT_SetDeferredRetcode(UT_KEY(OS_strnlen), 2, strlen(history->fnames.dst_filename));
614616
UtAssert_INT32_EQ(CF_CFDP_SendMd(txn), CFE_SUCCESS);
615617
UtAssert_UINT32_EQ(md->size, txn->fsize);
616618
UtAssert_STRINGBUF_EQ(md->dest_filename.data_ptr, md->dest_filename.length, history->fnames.dst_filename,
@@ -625,6 +627,8 @@ void Test_CF_CFDP_SendMd(void)
625627
strncpy(history->fnames.src_filename, "src2", sizeof(history->fnames.src_filename));
626628
txn->state = CF_TxnState_S2;
627629
txn->fsize = 5678;
630+
UT_SetDefaultReturnValue(UT_KEY(OS_strnlen), strlen(history->fnames.src_filename));
631+
UT_SetDeferredRetcode(UT_KEY(OS_strnlen), 2, strlen(history->fnames.dst_filename));
628632
UtAssert_INT32_EQ(CF_CFDP_SendMd(txn), CFE_SUCCESS);
629633
UtAssert_UINT32_EQ(md->size, txn->fsize);
630634
UtAssert_UINT32_EQ(md->dest_filename.length, sizeof(history->fnames.dst_filename));

unit-test/stubs/cf_utils_stubs.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ void UT_DefaultHandler_CF_WriteTxnQueueDataToFile(void *, UT_EntryKey_t, const U
4141
* Generated stub function for CF_FindTransactionBySequenceNumber()
4242
* ----------------------------------------------------
4343
*/
44-
CF_Transaction_t *CF_FindTransactionBySequenceNumber(CF_Channel_t *chan,
44+
CF_Transaction_t *CF_FindTransactionBySequenceNumber(CF_Channel_t * chan,
4545
CF_TransactionSeq_t transaction_sequence_number,
4646
CF_EntityId_t src_eid)
4747
{

0 commit comments

Comments
 (0)