Skip to content

Commit

Permalink
system.c: Flush node input after running external programs.
Browse files Browse the repository at this point in the history
If a child program that was supposed to receive user input didn't
receive it before exiting, then input the user intended for the
program might go back to the BBS afterwards, potentially doing unwanted
things in the menu system. Since any "leftover" input should be
discarded, flush any pending input on the node after the child has exited.
  • Loading branch information
InterLinked1 committed Oct 7, 2024
1 parent 457fdcf commit c94e012
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions bbs/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -1182,6 +1182,7 @@ static int __bbs_execvpe_fd(struct bbs_node *node, int usenode, int fdin, int fd
*/
node->childpid = 0;
if (usenode) {
int buffered = node->buffered;
/* Restore original terminal settings.
* This way, if whatever program was executed exited
* without leaving the terminal in a good/usable state,
Expand All @@ -1190,6 +1191,16 @@ static int __bbs_execvpe_fd(struct bbs_node *node, int usenode, int fdin, int fd
if (tcsetattr(node->slavefd, TCSANOW, &term)) {
bbs_error("tcsetattr failed: %s\n", strerror(errno));
}

/* Flush any input that may still be pending when the program exited.
* If there was still input waiting for the program, discard it all,
* or it could erroneously be sent to the BBS when we return,
* wreaking havoc. */
bbs_node_unbuffer(node);
bbs_node_flush_input(node);
if (buffered) {
bbs_node_buffer(node); /* Not sure if it's really necessary to restore... but doesn't hurt */
}
}
}

Expand Down

0 comments on commit c94e012

Please sign in to comment.