Skip to content

Fix memory safety and type mismatch bugs (#63, #65, #66)#67

Open
dcpagotto wants to merge 1 commit intonasa-jpl:integrationfrom
dcpagotto:fix/memory-and-type-safety-bugs
Open

Fix memory safety and type mismatch bugs (#63, #65, #66)#67
dcpagotto wants to merge 1 commit intonasa-jpl:integrationfrom
dcpagotto:fix/memory-and-type-safety-bugs

Conversation

@dcpagotto
Copy link
Contributor

Fixes for three open bugs, all verified against the source. Minimal changes, one fix per file.


ams/library/libams.c — fix MRELEASE dereference (#66)

constructMessage receives content as char **. At line 1118, MRELEASE(content) frees the stack pointer itself instead of the buffer it points to. Every other MRELEASE call in the same function correctly uses *content.

// before (frees the char** pointer — crash or memory leak)
MRELEASE(content);

// after (frees the actual content buffer)
MRELEASE(*content);

tc/dtka/dtkaadmin.c — remove dead code with buffer overflow risk (#65)

manageLeadTime declares char test[5] and calls sprintf(test, "%u", ...) but the result is never read. The buffer is too small for the full range of unsigned int (up to 10 digits), and the only input validation is >= 20, so any value above 9999 would overflow. Removed both the buffer and the sprintf since they serve no purpose.


bpv7/ipn/ipnfw.c — fix SDR/SM list type mismatch (#63)

initializeHIRR creates viaPassageways with sm_list_create(ionwm) (shared memory list), but then tries to populate it using sdr_list_insert_last (SDR persistent store function). These are completely different list implementations. Changed to sm_list_insert_last(ionwm, ...) to match the list type. This is consistent with how the list is destroyed in libcgr.c using sm_list_destroy.


All three are single-line changes. No functional additions, just correcting existing behavior to match what the code clearly intended.

…asa-jpl#66)

- libams.c: dereference content pointer before calling MRELEASE (nasa-jpl#66)
  MRELEASE(content) was freeing the char** stack pointer instead of the
  actual buffer at *content, causing either a crash or memory leak.
  Other MRELEASE calls in the same function already use *content correctly.

- dtkaadmin.c: remove unused sprintf and undersized stack buffer (nasa-jpl#65)
  The char test[5] buffer and sprintf call in manageLeadTime were dead
  code (result never used). sprintf with %u on a 5-byte buffer can
  overflow for values > 9999, which is valid since the only lower bound
  check is >= 20.

- ipnfw.c: use sm_list_insert_last instead of sdr_list_insert_last (nasa-jpl#63)
  viaPassageways is created with sm_list_create (shared memory list) but
  was being populated with sdr_list_insert_last (SDR list function).
  Changed to sm_list_insert_last with ionwm partition, matching how the
  list is created and destroyed in the rest of the codebase.
@dcpagotto
Copy link
Contributor Author

Hey! Just noticed issue #65 got closed today — nice to see it's being addressed.

Quick question though: are you folks planning to review this PR, or did you end up fixing it differently on your side? Totally fine either way, just wanted to check so I know whether to keep this open or close it out.

Thanks!

@250MHz
Copy link
Collaborator

250MHz commented Feb 6, 2026

#63 is sorta fixed because IONe's IRF code is supposed to replace the HIRR code, so those HIRR functions would go away. But at the same time, they don't want to merge the IRF code into the default branch because it isn't tested. IMO we should remove the HIRR code and worry about IRF stuff at a later time, but I wanted feedback from the developers first.

As pointed out in #66 (comment), I think the memory ownership of the ams functions are sus. Someone with knowledge about AMS should clean that up (maybe @SkyDeBaun ?), but I think people are busy. If a cleanup is not forthcoming, then I think they should merge your AMS change.

@dcpagotto
Copy link
Contributor Author

Hey @SkyDeBaun, saw your comment on #66 — glad the MRELEASE issue is confirmed!

You mentioned there might be a conflict with your current branch. Happy to rebase this PR against your changes if that helps, or if you'd rather just fold these fixes into your work directly, that's cool too. Whatever makes integration easier on your end.

Just let me know how you'd like to handle it 👍

@SkyDeBaun
Copy link
Collaborator

SkyDeBaun commented Feb 12, 2026

Hey @SkyDeBaun, saw your comment on #66 — glad the MRELEASE issue is confirmed!

You mentioned there might be a conflict with your current branch. Happy to rebase this PR against your changes if that helps, or if you'd rather just fold these fixes into your work directly, that's cool too. Whatever makes integration easier on your end.

Just let me know how you'd like to handle it 👍

@dcpagotto I may have to retract that statement.. I think your fix looks promising (makes sense!) but am seeing a conflict with RAMS.. when the node in question is also an AMS subscriber.

Will need to dig into this a bit.

@iondev33
Copy link
Collaborator

@SkyDeBaun Please check if this PR can be closed or if we defer to 4.2 - update milestone please. Thx!

@SkyDeBaun
Copy link
Collaborator

Investigating ongoing.

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.

4 participants