Skip to content

Fix/PLT 406 param list clear function clears local parameter - #85

Open
jeanbaptistelab wants to merge 9 commits into
developfrom
fix/PLT-406-param_list_clear-function-clears-local-parameter
Open

Fix/PLT 406 param list clear function clears local parameter#85
jeanbaptistelab wants to merge 9 commits into
developfrom
fix/PLT-406-param_list_clear-function-clears-local-parameter

Conversation

@jeanbaptistelab

Copy link
Copy Markdown
Contributor

Local parameters (whose node == 0) are usually placed in a specific “param” ELF section and are read-only.

In module code, remote parameters are added to a linked list, independent of the of the read-only “param” ELF section.

However, in CSH context, APMs that define their own parameters, add those parameters to the linked-list during initialization (by calling param_list_add()). Those parameters are in essence local not remote (they are part of the CSH instance local parameters).

When some code calls the param_list_clear() function (for instance from hk_store.c, part of OBC House Keeping), the linked list is essentially reset, causing the list of CSH parameters to revert back to the list as it was before loading any APM.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes PLT-406 by changing param_list_clear() semantics so it does not wipe “local” parameters that are dynamically added with node == 0 (e.g., CSH/APM-defined params), and adds a regression test to validate the behavior.

Changes:

  • Update param_list_clear() to only clear non-local (node != 0) entries from the dynamic list.
  • Add a new plt_406 test exercising the clear/remove behavior for node==0 vs node!=0 parameters.
  • Minor test/build updates (fix plt_405 exit code; register new test in Meson).

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
tests/plt_406.c Adds a regression test covering PLT-406 behavior around param_list_clear() and parameter persistence.
tests/plt_405.c Fixes test program to return success (0) on pass.
tests/meson.build Registers the new plt_406 test executable.
src/param/list/param_list.c Changes param_list_clear() to preserve node==0 list entries while clearing node!=0 entries.
meson.build Simplifies dependency list selection for the param library build.
Comments suppressed due to low confidence (1)

tests/plt_406.c:30

  • Same as above: check the return value of param_list_create_remote before using it.
    remote = param_list_create_remote(128, 400, PARAM_TYPE_UINT16, PM_DEBUG, 0, "remote", NULL, NULL, -1);
    param_list_add(remote);

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/param/list/param_list.c Outdated
Comment on lines +416 to +420
struct param_s *iter = 0;
SLIST_FOREACH(iter, &param_list_head, next) {
if(*iter->node != 0) {
SLIST_REMOVE(&param_list_head, iter, param_s, next);
param_list_destroy(iter);
Comment thread tests/plt_406.c
Comment thread tests/plt_406.c
Comment thread tests/plt_406.c Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Comments suppressed due to low confidence (2)

src/param/list/param_list.c:421

  • param_list_clear() currently removes elements while iterating with SLIST_FOREACH and then calls param_list_destroy() on a stack copy of the element. This can lead to use-after-free in the loop increment and can also attempt to free() stack memory (because param_list_destroy_impl() frees the param pointer itself in dynamic mode). Iterate safely by caching next, remove the real element, and destroy the real pointer.
	SLIST_FOREACH(iter, &param_list_head, next) {
		if(*iter->node != 0) {
			SLIST_REMOVE(&param_list_head, iter, param_s, next);
			struct param_s to_be_destroyed = *iter;
			param_list_destroy(&to_be_destroyed);

tests/plt_406.c:24

  • This assertion checks p (the previously found local param) instead of remote. If param_list_create_remote() fails, param_list_add(remote) will dereference NULL.
    assert(p);

Comment thread tests/plt_406.c
Comment on lines +15 to +18
if(NULL == p) {
/* libparam is probably built as a shared library -> need to explicitly add our own parameters*/
param_list_add((param_t *)&plt_406);
}
Comment thread tests/meson.build Outdated
plt_405_exe = executable('plt_405', 'plt_405.c', dependencies: [param_dep, csp_dep])
test('plt_405', plt_405_exe) No newline at end of file
test('plt_405', plt_405_exe)
plt_406_exe = executable('plt_406', 'plt_406.c', dependencies: [param_dep, csp_dep], link_args : ['-Wl,-Map=plt_406.map'])

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Comment on lines +419 to 426
while (iter_param) {
const param_t * param = iter_param;
if (i.phase != 0 && (i.element && *(i.element->node) != 0)) {
SLIST_REMOVE(&param_list_head, param, param_s, next);
param_list_destroy(param);
}
iter_param = param_list_iterate(&i);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants