Skip to content

microcom.c: Call cleanup routines only once#56

Open
jonrebm wants to merge 1 commit into
pengutronix:mainfrom
jonrebm:cleaup-routines
Open

microcom.c: Call cleanup routines only once#56
jonrebm wants to merge 1 commit into
pengutronix:mainfrom
jonrebm:cleaup-routines

Conversation

@jonrebm

@jonrebm jonrebm commented Dec 14, 2025

Copy link
Copy Markdown
Contributor

Repeated call to ios->exit(ios); was observed as used after free using asan. Only call it once: In the exit handler.

Always call the exit handler and check there whether listenonly is set and there skip resetting the terminal if so.

Do not reset the terminal elsewhere.

Do not call the exit handler from the quit command, call exit instead.

@jonrebm jonrebm mentioned this pull request Dec 14, 2025
@jonrebm

jonrebm commented Jan 14, 2026

Copy link
Copy Markdown
Contributor Author

Has anyone taken a look at this one already? @ukleinek or @a3f maybe?

Comment thread microcom.c Outdated
Comment thread commands.c
@jonrebm

jonrebm commented Feb 6, 2026

Copy link
Copy Markdown
Contributor Author

Thank you @michaelolbrich. Seems I need to run another round of testing.

@jonrebm

jonrebm commented Jul 13, 2026

Copy link
Copy Markdown
Contributor Author

Applied feedback from @michaelolbrich, made microcom_exit static, rebased to main

@jonrebm
jonrebm requested a review from michaelolbrich July 13, 2026 11:17
Repeated call to ios->exit(ios); was observed as used after free using
asan. Only call it once: In the exit handler.

Always call the exit handler, either via sigaction or via atexit, and
check there whether listenonly is set and there skip resetting the
terminal if so.

Do not reset the terminal elsewhere.

Do not call the exit handler from the quit command, just call exit,
and rely on atexit.

Signed-off-by: Jonas Rebmann <jre@pengutronix.de>
Comment thread microcom.c
write(1, "exiting\n", 8);
static const char exit_msg[] = "exiting\n";

if (write(STDOUT_FILENO, exit_msg, sizeof(exit_msg) - 1) < 0) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this to avoid a warning about ignoring the return value? or why is this here?

(void)write(...); is the typical way to handle that, I think.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, for compiler and reader to see that error checking is omitted purposely. I thought that it looked better this way but I'll change it given you find that more idiomatic.

Comment thread microcom.c
ret = ios->set_speed(ios, current_speed);
if (ret)
goto cleanup_ios;
exit(1);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is before atexit() is configured. Don't you need to call at least ios->exit(ios); here?

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.

2 participants