Skip to content

fix(tbl): close file descriptor after table load command - #2830

Closed
philphauler wants to merge 1 commit into
nasa:devfrom
philphauler:fix-2811-tbl-fd-leak
Closed

philphauler wants to merge 1 commit into
nasa:devfrom
philphauler:fix-2811-tbl-fd-leak

Conversation

@philphauler

@philphauler philphauler commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

Checklist (Please check before submitting)

Describe the contribution

Fixes #2811. In CFE_TBL_LoadCmd() the file descriptor from CFE_FS_OpenFileForReading() was never closed on any path. The descriptor is now closed inside the open-success block once CFE_TBL_SetMetaDataFromFileHeader() has consumed the header, the same shape CFE_TBL_LoadFromFile uses.

Testing performed

tbl_ut_load.c adds UtAssert_STUB_COUNT(OS_close, n) on each path that opens the file (per the note on #2811). The close sits inside the open-success block, like CFE_TBL_LoadFromFile, because the OSAL stub hands back a fake object id on a forced open failure (this is what the first CI run tripped on). Run locally in the cFS dev bundle with the tests kept and cfe_tbl_task_cmds.c reverted to dev: the two success-path asserts fail with CallCount: OS_close() (0) == 1 (tbl_ut_load.c:323 and :370) and the failed-open path stays at 0 as it should. With the fix, coverage-tbl-ALL passes 1361/1361.

Expected behavior changes

Table load commands no longer leak the opened file descriptor. Repeated table loads no longer accumulate leaked descriptors.

System(s) tested on

Hardware: x86_64 (WSL2), OS: Ubuntu 22.04, Versions: cFE dev 2612eb0 with OSAL and PSP from the cFS dev bundle, native build with ENABLE_UNIT_TESTS

Contributor Info

Filip Koscak - phil.phaulre@gmail.com

CFE_TBL_LoadCmd opens a file via TxnOpenTableLoadFile but never closes it; TxnFinish only releases the registry lock. Every load command leaks one OS file descriptor, eventually exhausting the OSAL file table.

Close the file inside the open-success block, the way CFE_TBL_LoadFromFile already does with the same helper. The descriptor exported on a failed open is not to be trusted (the OSAL stub hands back a fake id), so no close is attempted there.

Tests assert OS_close is called once after a successful load and after a failure that follows the open, and not at all when the open fails.
@philphauler

Copy link
Copy Markdown
Contributor Author

Hi @jphickey 👋 thanks for confirming the bug on #2811 and for the test guidance. Moved the close inside the open-success block (the OSAL stub hands back a fake id on a failed open, which is what CI tripped on) and added OS_close stub-count asserts on the three paths that open the file (6fc75a1). coverage-tbl-ALL passes. If #2774 is the one you would rather take, happy to close this one. Have a great day!

@philphauler

Copy link
Copy Markdown
Contributor Author

Hey @jphickey, just saw #2831 covers this one. Closing in favour of your fix. Have a nice day!

@philphauler philphauler closed this Sep 8, 2026
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.

[SECURITY] CFE_TBL_LoadCmd() file descriptor leak causes denial of service via resource exhaustion

1 participant