Skip to content

fix: perf log DataStart offset, %u format specifiers, ResourceId narrowing conversion#2758

Open
stark256-spec wants to merge 2 commits into
nasa:mainfrom
stark256-spec:fix/perf-metadata-format-specifiers-resourceid-narrowing
Open

fix: perf log DataStart offset, %u format specifiers, ResourceId narrowing conversion#2758
stark256-spec wants to merge 2 commits into
nasa:mainfrom
stark256-spec:fix/perf-metadata-format-specifiers-resourceid-narrowing

Conversation

@stark256-spec

@stark256-spec stark256-spec commented Jun 3, 2026

Copy link
Copy Markdown

Summary

Three independent defects across two files.


Fix 1 — Perf log metadata DataStart mismatches file layout (closes #2637)

File: modules/es/fsw/src/cfe_es_perf.c

CFE_ES_RunPerfLogDump rewrites the dump buffer in order starting at DataStart, so the output file always begins at index 0. However, State->DataPos was still initialised to Perf->MetaData.DataStart when entering WRITE_PERF_ENTRIES, leaving MetaData.DataStart unchanged in the file. Parsers that honour this field skip every entry before the original start index — the number of skipped entries varies with wherever the circular buffer happened to stop.

Fix: set State->DataPos = 0 to match the actual file layout.


Fix 2 — %d format specifiers for unsigned values (closes #2638)

File: modules/es/fsw/src/cfe_es_perf.c

CFE_ES_PerfLogAdd formats Marker (uint32) and CFE_MISSION_ES_PERF_MAX_IDS with %d (signed). Changed both to %u and added an explicit (unsigned int) cast on the macro expression to satisfy -Wformat.


Fix 3 — Narrowing conversion in CFE_ResourceId_FromInteger (closes #2664)

File: modules/core_api/fsw/inc/cfe_resourceid.h

In strict mode CFE_RESOURCEID_WRAP(x) expands to a compound-literal struct initializer { x } where the field is uint32. Passing an unsigned long directly is a narrowing conversion that becomes a hard error when compiling C++ with -Werror=narrowing on 64-bit Linux (where unsigned long is 64 bits).

Fix: add an explicit (uint32) cast on Value before the wrap, consistent with the suggestion in the issue.


Test plan

  • Existing unit tests pass (no logic change for Fix 2 and Fix 3)
  • For Fix 1: verify perf log dump output parses cleanly from index 0
  • For Fix 3: confirm no -Werror=narrowing with OMIT_DEPRECATED=ON C++ build

@stark256-spec stark256-spec force-pushed the fix/perf-metadata-format-specifiers-resourceid-narrowing branch from d205909 to 6ee5fc2 Compare June 3, 2026 16:27
CFE_EVS_ProcessCommandPacket() and CFE_ES_TaskPipe() both cast the SB
buffer directly to *SendHkCmd_t without calling VerifyCmdLength first.
Every other command code in ProcessGroundCommand/ProcessGroundCmd is
guarded by a VerifyCmdLength check before the cast. A truncated or
malformed SEND_HK_MID packet silently bypasses validation and causes
an OOB read when the handler accesses struct fields beyond the actual
packet boundary.

Add the missing VerifyCmdLength guard in both dispatch functions,
matching the existing pattern used for all ground commands.

Fixes nasa/cFS#987 (EVS)
Fixes nasa/cFS#986 (ES)
…rrowing

Three independent defects:

1. CFE_ES_RunPerfLogDump (cfe_es_perf.c): State->DataPos was initialized
   to Perf->MetaData.DataStart when entering WRITE_PERF_ENTRIES. The
   dump loop now writes entries in order starting from DataStart, so the
   output file always begins at offset 0 — but MetaData.DataStart was
   left unchanged, causing parsers to skip entries before the original
   start index. Fix: initialize DataPos to 0 to match the actual file
   layout. Fixes nasa#2637.

2. CFE_ES_PerfLogAdd (cfe_es_perf.c): Marker (uint32) and
   CFE_MISSION_ES_PERF_MAX_IDS were printed with %d (signed) format
   specifiers. Changed to %u and added explicit (unsigned int) cast on
   the macro value to silence -Wformat warnings. Fixes nasa#2638.

3. CFE_ResourceId_FromInteger (cfe_resourceid.h): In strict mode
   CFE_RESOURCEID_WRAP expands to a compound literal initializer for a
   struct containing uint32. Passing an unsigned long directly triggers
   a narrowing-conversion warning/error when compiling C++ with -Werror.
   Added explicit (uint32) cast on Value before the wrap. Fixes nasa#2664.
@stark256-spec stark256-spec force-pushed the fix/perf-metadata-format-specifiers-resourceid-narrowing branch from 6ee5fc2 to 896b9c5 Compare June 30, 2026 20:07
@stark256-spec

Copy link
Copy Markdown
Author

This branch is rebased on current main. Three independent static-analysis findings bundled here (perf log offset calculation, format specifier mismatches, and a narrowing conversion on ResourceId) — happy to split into separate PRs if that's easier to review, or keep as-is if bundling small related fixes is fine. Let me know either way and I can request CCB:Ready.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants