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

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.
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.

1 participant