Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't free-up file-descriptor of stdin/stdout/stderr #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mostafa-salmaan
Copy link
Collaborator

stdout, stdin and stderr are statically allocated at tinystdio/posixiob_stdout.c, tinystdio/posixiob_stdin.c and tinystdio/posixiob_stderr.c respectively.

and the issue here is that the current implementation of fclose() frees the allocated memory for the stream file. When we call fclose(stdout) it tries to free an unallocated memory for stdout, so it frees a wrong pointer and saves it as a free heap space, then when trying to use this memory it causes memory corruption.

So, we shouldn't free the memory if the stream is stdin, stdout or stderr.

stdout, stdin and stderr are statically allocated at tinystdio/posixiob_stdout.c, tinystdio/posixiob_stdin.c
and tinystdio/posixiob_stderr.c respectively.

and the issue here is that the current implementation of `fclose()` frees the allocated memory for the stream file.
When we call `fclose(stdout)` it tries to free an unallocated memory for _stdout_,
so it frees a wrong pointer and saves it as a free heap space, then when trying to use this memory it causes memory corruption.

So, we shouldn't free the memory if the stream is stdin, stdout or stderr.
mostafa-salmaan pushed a commit that referenced this pull request Aug 28, 2024
- The PRU newlib port is supposed to implement case #2 as described in
  newlib/libc/include/reent.h .  Thus drop the defining of
  MISSING_SYSCALL_NAMES.
- libgloss/configure: Regenerate.
- libgloss/libnosys/acinclude.m4: Do not define
  MISSING_SYSCALL_NAMES for pru.

Signed-off-by: Dimitar Dimitrov <[email protected]>
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