A signal handler that calls for example waitpid has to save errno before and

restore it afterwards.

Cherry-picked from: 70b4927d847f52c865e0c6c91323eeb3295a99eb

Signed-off-by: Luke Dashjr <luke-jr+git@utopios.org>
pull/29/head
Ingo Klöcker 16 years ago committed by Michele Calgaro
parent 147bb5982f
commit c80147f221
Signed by: MicheleC
GPG Key ID: 2A75B7CA8ADED5CF

@ -71,6 +71,7 @@ imap://server/folder/
#include <signal.h> #include <signal.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/wait.h> #include <sys/wait.h>
#include <errno.h>
#ifdef HAVE_LIBSASL2 #ifdef HAVE_LIBSASL2
extern "C" { extern "C" {
@ -147,6 +148,10 @@ kdemain (int argc, char **argv)
void void
sigchld_handler (int signo) sigchld_handler (int signo)
{ {
// A signal handler that calls for example waitpid has to save errno
// before and restore it afterwards.
// (cf. https://www.securecoding.cert.org/confluence/display/cplusplus/ERR32-CPP.+Do+not+rely+on+indeterminate+values+of+errno)
const int save_errno = errno;
int pid, status; int pid, status;
while (signo == SIGCHLD) while (signo == SIGCHLD)
@ -158,9 +163,11 @@ sigchld_handler (int signo)
// the signal occurred ( BSD handles it different, but it should do // the signal occurred ( BSD handles it different, but it should do
// no harm ). // no harm ).
signal (SIGCHLD, sigchld_handler); signal (SIGCHLD, sigchld_handler);
return; break;
} }
} }
errno = save_errno;
} }
IMAP4Protocol::IMAP4Protocol (const TQCString & pool, const TQCString & app, bool isSSL):TCPSlaveBase ((isSSL ? 993 : 143), IMAP4Protocol::IMAP4Protocol (const TQCString & pool, const TQCString & app, bool isSSL):TCPSlaveBase ((isSSL ? 993 : 143),

Loading…
Cancel
Save