From 8072140d3664b32988c00134844aef58c5c1c9b2 Mon Sep 17 00:00:00 2001 From: Thomas Osterried Date: Sat, 5 Jun 2010 00:14:04 +0000 Subject: The last patch introduced cosmetic errors like GIFADDR: Bad file descriptor after signling termination with ^C In detail: close(3) = 0 sigreturn() = ? (mask now []) ioctl(3, SIOCGIFHWADDR, {ifr_name="eth0", ???}) = -1 EBADF (Bad file descriptor) -> The interrupt handler introduced concurrency issues ;) The patch caused only unexpected behaviour; no security problems. This new patch fixes this problem. --- listen/listen.c | 44 ++++++++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 16 deletions(-) (limited to 'listen/listen.c') diff --git a/listen/listen.c b/listen/listen.c index 64a5d27..b7de1e3 100644 --- a/listen/listen.c +++ b/listen/listen.c @@ -55,6 +55,7 @@ static void handle_sigint(int signal) { sigint++; close(sock); /* disturb blocking recvfrom */ + sock = -1; } #define ASCII 0 @@ -74,6 +75,7 @@ int main(int argc, char **argv) socklen_t asize = sizeof(sa); struct ifreq ifr; int proto = ETH_P_AX25; + int exit_code = EXIT_SUCCESS; timestamp = 0; @@ -141,12 +143,11 @@ int main(int argc, char **argv) setservent(1); - signal(SIGINT, handle_sigint); - signal(SIGTERM, handle_sigint); - while (!sigint) { asize = sizeof(sa); + signal(SIGINT, handle_sigint); + signal(SIGTERM, handle_sigint); if ((size = recvfrom(sock, buffer, sizeof(buffer), 0, &sa, &asize)) == -1) { @@ -157,24 +158,35 @@ int main(int argc, char **argv) if (errno == EINTR) { refresh(); continue; - } else if (errno == EBADF && sigint) - break; - - if (color) - endwin(); - perror("recv"); - - return 1; + } else if (!(errno == EBADF && sigint)) { + perror("recv"); + exit_code = errno; + } + break; } + signal(SIGINT, SIG_DFL); + signal(SIGTERM, SIG_DFL); + if (sock == -1 || sigint) + break; if (dev != NULL && strcmp(dev, sa.sa_data) != 0) continue; if (proto == ETH_P_ALL) { strcpy(ifr.ifr_name, sa.sa_data); - if (ioctl(sock, SIOCGIFHWADDR, &ifr) < 0) - perror("GIFADDR"); - + signal(SIGINT, handle_sigint); + signal(SIGTERM, handle_sigint); + if (ioctl(sock, SIOCGIFHWADDR, &ifr) == -1) { + if (!(errno == EBADF && sigint)) { + perror("SIOCGIFHWADDR"); + exit_code = errno; + break; + } + } + signal(SIGINT, SIG_DFL); + signal(SIGTERM, SIG_DFL); + if (sock == -1 || sigint) + break; if (ifr.ifr_hwaddr.sa_family == AF_AX25) { display_port(sa.sa_data); #ifdef NEW_AX25_STACK @@ -182,7 +194,7 @@ int main(int argc, char **argv) #else ki_dump(buffer, size, dumpstyle); #endif -/* lprintf(T_DATA, "\n"); */ +/* lprintf(T_DATA, "\n"); */ } } else { display_port(sa.sa_data); @@ -199,7 +211,7 @@ int main(int argc, char **argv) if (color) endwin(); - return EXIT_SUCCESS; + return exit_code; } static void ascii_dump(unsigned char *data, int length) -- cgit v1.2.3