From 11f38fca55972832ee09a3b1ac8693050500545b Mon Sep 17 00:00:00 2001 From: Philipp Takacs Date: Sat, 21 Feb 2015 11:05:43 +0100 Subject: [PATCH] remove longjmp in signalhandler of prompter to avoid undefined behavior use close(2) in the signal handler --- uip/prompter.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/uip/prompter.c b/uip/prompter.c index 4d0ce86..e42e8df 100644 --- a/uip/prompter.c +++ b/uip/prompter.c @@ -12,6 +12,7 @@ #include #include #include +#include static struct swit switches[] = { #define PREPSW 0 @@ -34,8 +35,8 @@ static struct swit switches[] = { }; -static int wtuser = 0; -static int sigint = 0; +volatile sig_atomic_t wtuser = 0; +volatile sig_atomic_t sigint = 0; static jmp_buf sigenv; /* @@ -263,6 +264,7 @@ int getln(char *buffer, int n) { int c; + sig_atomic_t psigint; char *cp; cp = buffer; @@ -271,15 +273,17 @@ getln(char *buffer, int n) switch (setjmp(sigenv)) { case 0: wtuser = 1; + psigint = sigint; break; - case DONE: - wtuser = 0; - return 0; - default: wtuser = 0; - return NOTOK; + if (sigint == psigint) { + return 0; + } else { + sigint = psigint; + return NOTOK; + } } for (;;) { @@ -311,7 +315,8 @@ getln(char *buffer, int n) static void intrser(int i) { - if (wtuser) - longjmp(sigenv, NOTOK); + if (wtuser) { + close(STDIN_FILENO); + } sigint++; } -- 1.7.10.4