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

Fix some UB in signal handling #18

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion can.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ static void can_exit(struct ios_ops *ios)
shutdown(ios->fd, SHUT_RDWR);
close(ios->fd);
pthread_join(can_thread, NULL);
free(ios);
}

static void *can_thread_fun(void *_data)
Expand Down
3 changes: 3 additions & 0 deletions commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,10 @@ static int cmd_break(int argc, char *argv[])

static int cmd_quit(int argc, char *argv[])
{
fflush(NULL);
microcom_exit(0);
free(ios);
exit(0);
return 0;
}

Expand Down
8 changes: 5 additions & 3 deletions microcom.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,13 @@ int flag_to_baudrate(speed_t speed)

void microcom_exit(int signal)
{
printf("exiting\n");
write(1, "exiting\n", 8);

ios->exit(ios);
tcsetattr(STDIN_FILENO, TCSANOW, &sots);

exit(0);
if (signal)
_Exit(0);
}

/********************************************************************
Expand Down Expand Up @@ -202,7 +203,7 @@ int listenonly = 0;

int main(int argc, char *argv[])
{
struct sigaction sact; /* used to initialize the signal handler */
struct sigaction sact = {0}; /* used to initialize the signal handler */
int opt, ret;
char *hostport = NULL;
int telnet = 0, can = 0;
Expand Down Expand Up @@ -319,6 +320,7 @@ int main(int argc, char *argv[])
/* set the signal handler to restore the old
* termios handler */
sact.sa_handler = &microcom_exit;
sigemptyset(&sact.sa_mask);
sigaction(SIGHUP, &sact, NULL);
sigaction(SIGINT, &sact, NULL);
sigaction(SIGPIPE, &sact, NULL);
Expand Down
1 change: 0 additions & 1 deletion serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ static void serial_exit(struct ios_ops *ios)
{
tcsetattr(ios->fd, TCSANOW, &pots);
close(ios->fd);
free(ios);
serial_unlock();
}

Expand Down
1 change: 0 additions & 1 deletion telnet.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ static int telnet_send_break(struct ios_ops *ios)
static void telnet_exit(struct ios_ops *ios)
{
close(ios->fd);
free(ios);
}

struct ios_ops *telnet_init(char *hostport)
Expand Down