CF_CFDP_DecodeAllTlv reports success and drops TLVs after the fourth

Open Beginner friendly
#537 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
77/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
c

Research direction

Start with fsw/src/cf_codec.c, especially CF_CFDP_DecodeAllTlv and its callers CF_CFDP_DecodeEof and CF_CFDP_DecodeFin; the report identifies the loop condition that stops at the TLV limit. Check how decoder state and remaining bytes are handled when the limit is reached. Done means extra or malformed TLVs are not silently accepted, with a regression check for the reported cases.

Written by the indexing model from the issue text.

Description

Checklist (Please check before submitting)

  • I reviewed the Contributing Guide.
  • I performed a cursory search to see if the bug report is relevant, not redundant, nor in conflict with other tickets.

Describe the bug
CF_CFDP_DecodeAllTlv stops after limit (CF_PDU_MAX_TLV, 4) TLVs and returns with the decoder still OK, even when bytes remain. So an EOF or FIN with more than 4 TLVs decodes as successful with the extra TLVs silently dropped, and a malformed TLV after the fourth is never examined.

To Reproduce
Decoding FIN PDUs with cf_codec.c from dev (0dbc2b7; the file is the same on main) under ASan and UBSan:

FIN with Decoder OK TLVs kept Bytes left unread
4 entity-ID TLVs yes 4 0
5 entity-ID TLVs yes 4 3
6 entity-ID TLVs yes 4 6
2 TLVs, second malformed (length 9, 1 byte present) no 1 1
5 TLVs, fifth malformed yes 4 3

Expected behavior
Either reject the PDU when TLV bytes remain after the limit (as the in-limit malformed case already is), or record that TLVs were dropped (an event or counter). The num_tlv >= CF_PDU_MAX_TLV branch inside the loop is never reached: both callers (CF_CFDP_DecodeEof and CF_CFDP_DecodeFin) pass CF_PDU_MAX_TLV as limit, so the loop condition stops first.

Code snips
fsw/src/cf_codec.c, CF_CFDP_DecodeAllTlv: while (limit > 0 && CF_CODEC_GET_REMAIN(state) != 0).

System observed on:
Linux x86_64, gcc, harness around cf_codec.c.

Additional context
Low impact today, since CF only uses the entity-ID (fault location) TLV. Found while comparing CF with F´'s CfdpManager, which has the same behavior (nasa/fprime#6330). CLA: cFS Apps corporate CLA filed by Space Ocean Corp.

Dominant language
C
Stars
122
Forks
81
Avg merge
1d 15h
Merged PRs (30d)
4

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from nasa/CF

All issues in nasa/CF

Similar issues

More C issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.