Changeset: 56f893e3bd5c for MonetDB URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=56f893e3bd5c Modified Files: clients/mapiclient/mclient.c gdk/gdk_system.c gdk/gdk_utils.c monetdb5/modules/kernel/alarm.c sql/backends/monet5/UDF/capi/capi.c sql/backends/monet5/UDF/pyapi/pyapi.c tools/merovingian/daemon/merovingian.c tools/mserver/mserver5.c Branch: Mar2018 Log Message:
More system call checks. diffs (truncated from 366 to 300 lines): diff --git a/clients/mapiclient/mclient.c b/clients/mapiclient/mclient.c --- a/clients/mapiclient/mclient.c +++ b/clients/mapiclient/mclient.c @@ -1770,30 +1770,35 @@ start_pager(stream **saveFD) /* ignore SIGPIPE so that we get an error instead of signal */ act.sa_handler = SIG_IGN; - sigemptyset(&act.sa_mask); - act.sa_flags = 0; - sigaction(SIGPIPE, &act, NULL); - - p = popen(pager, "w"); - if (p == NULL) + if(sigemptyset(&act.sa_mask) == -1) { fprintf(stderr, "Starting '%s' failed\n", pager); - else { - *saveFD = toConsole; - /* put | in name to indicate that file should be closed with pclose */ - if ((toConsole = file_wastream(p, "|pager")) == NULL) { - toConsole = *saveFD; - *saveFD = NULL; + } else { + act.sa_flags = 0; + if(sigaction(SIGPIPE, &act, NULL) == -1) { fprintf(stderr, "Starting '%s' failed\n", pager); - } + } else { + p = popen(pager, "w"); + if (p == NULL) + fprintf(stderr, "Starting '%s' failed\n", pager); + else { + *saveFD = toConsole; + /* put | in name to indicate that file should be closed with pclose */ + if ((toConsole = file_wastream(p, "|pager")) == NULL) { + toConsole = *saveFD; + *saveFD = NULL; + fprintf(stderr, "Starting '%s' failed\n", pager); + } #ifdef HAVE_ICONV - if (encoding != NULL) { - if ((toConsole = iconv_wstream(toConsole, encoding, "pager")) == NULL) { - toConsole = *saveFD; - *saveFD = NULL; - fprintf(stderr, "Starting '%s' failed\n", pager); + if (encoding != NULL) { + if ((toConsole = iconv_wstream(toConsole, encoding, "pager")) == NULL) { + toConsole = *saveFD; + *saveFD = NULL; + fprintf(stderr, "Starting '%s' failed\n", pager); + } + } +#endif } } -#endif } } } diff --git a/gdk/gdk_system.c b/gdk/gdk_system.c --- a/gdk/gdk_system.c +++ b/gdk/gdk_system.c @@ -446,13 +446,18 @@ find_posthread(pthread_t tid) #endif #ifdef HAVE_PTHREAD_SIGMASK -static void +static int MT_thread_sigmask(sigset_t * new_mask, sigset_t * orig_mask) { - (void) sigdelset(new_mask, SIGQUIT); - (void) sigdelset(new_mask, SIGALRM); /* else sleep doesn't work */ - (void) sigdelset(new_mask, SIGPROF); - (void) pthread_sigmask(SIG_SETMASK, new_mask, orig_mask); + if(sigdelset(new_mask, SIGQUIT)) + return -1; + if(sigdelset(new_mask, SIGALRM)) /* else sleep doesn't work */ + return -1; + if(sigdelset(new_mask, SIGPROF)) + return -1; + if(pthread_sigmask(SIG_SETMASK, new_mask, orig_mask)) + return -1; + return 0; } #endif @@ -554,8 +559,10 @@ MT_create_thread(MT_Id *t, void (*f) (vo join_threads(); #ifdef HAVE_PTHREAD_SIGMASK - (void) sigfillset(&new_mask); - MT_thread_sigmask(&new_mask, &orig_mask); + if(sigfillset(&new_mask)) + return -1; + if(MT_thread_sigmask(&new_mask, &orig_mask)) + return -1; #endif if(pthread_attr_init(&attr)) return -1; @@ -570,7 +577,7 @@ MT_create_thread(MT_Id *t, void (*f) (vo p = malloc(sizeof(struct posthread)); if (p == NULL) { #ifdef HAVE_PTHREAD_SIGMASK - MT_thread_sigmask(&orig_mask, NULL); + (void) MT_thread_sigmask(&orig_mask, NULL); //going to fail anyway #endif pthread_attr_destroy(&attr); return -1; @@ -603,7 +610,8 @@ MT_create_thread(MT_Id *t, void (*f) (vo free(p); } #ifdef HAVE_PTHREAD_SIGMASK - MT_thread_sigmask(&orig_mask, NULL); + if(MT_thread_sigmask(&orig_mask, NULL)) + return -1; #endif return ret ? -1 : 0; } diff --git a/gdk/gdk_utils.c b/gdk/gdk_utils.c --- a/gdk/gdk_utils.c +++ b/gdk/gdk_utils.c @@ -913,7 +913,8 @@ GDKlockHome(int farmid) /* * Print the new process list in the global lock file. */ - fseek(GDKlockFile, 0, SEEK_SET); + if(fseek(GDKlockFile, 0, SEEK_SET) == -1) + GDKfatal("GDKlockHome: Error while setting the file pointer on %s\n", gdklockpath); if (ftruncate(fileno(GDKlockFile), 0) < 0) GDKfatal("GDKlockHome: Could not truncate %s\n", gdklockpath); fflush(GDKlockFile); diff --git a/monetdb5/modules/kernel/alarm.c b/monetdb5/modules/kernel/alarm.c --- a/monetdb5/modules/kernel/alarm.c +++ b/monetdb5/modules/kernel/alarm.c @@ -96,7 +96,8 @@ ALARMprelude(void *ret) { (void) ret; #ifdef SIGALRM - (void) signal(SIGALRM, (void (*)()) CLKsignal); + if(signal(SIGALRM, (void (*)()) CLKsignal) == SIG_ERR) + throw(MAL, "alarm.prelude", SQLSTATE(HY001) "Signal call failed"); #endif return MAL_SUCCEED; } @@ -113,7 +114,8 @@ ALARMepilogue(void *ret) #undef SIG_IGN /*((__sighandler_t)1 ) */ #define SIG_IGN ((__sighandler_t)1L) #endif - (void) signal(SIGALRM, SIG_IGN); + if(signal(SIGALRM, SIG_IGN) == SIG_ERR) + throw(MAL, "alarm.epilogue", SQLSTATE(HY001) "Signal call failed"); #endif for (k = 0; k < timerTop; k++) { if (timer[k].action) diff --git a/sql/backends/monet5/UDF/capi/capi.c b/sql/backends/monet5/UDF/capi/capi.c --- a/sql/backends/monet5/UDF/capi/capi.c +++ b/sql/backends/monet5/UDF/capi/capi.c @@ -1298,7 +1298,13 @@ static str CUDFeval(Client cntxt, MalBlk if (option_enable_mprotect) { memset(&sa, 0, sizeof(sa)); sa.sa_flags = SA_SIGINFO; - sigfillset(&sa.sa_mask); + if(sigfillset(&sa.sa_mask) == -1) { + msg = createException(MAL, "cudf.eval", + "Failed to set signal handler: %s", + strerror(errno)); + errno = 0; + goto wrapup; + } sa.sa_sigaction = handler; if (sigaction(SIGSEGV, &sa, &oldsa) == -1 || sigaction(SIGBUS, &sa, &oldsb) == -1) { @@ -1528,8 +1534,8 @@ wrapup: // remove the signal handler, if any was set if (option_enable_mprotect) { if (sa.sa_sigaction) { - sigaction(SIGSEGV, &oldsa, NULL); - sigaction(SIGBUS, &oldsb, NULL); + (void) sigaction(SIGSEGV, &oldsa, NULL); + (void) sigaction(SIGBUS, &oldsb, NULL); memset(&sa, 0, sizeof(sa)); } diff --git a/sql/backends/monet5/UDF/pyapi/pyapi.c b/sql/backends/monet5/UDF/pyapi/pyapi.c --- a/sql/backends/monet5/UDF/pyapi/pyapi.c +++ b/sql/backends/monet5/UDF/pyapi/pyapi.c @@ -536,7 +536,7 @@ static str PyAPIeval(Client cntxt, MalBl FILE *fp; char address[1000]; struct stat buffer; - size_t length; + ssize_t length; if (exprStr[0] == '/') { // absolute path snprintf(address, 1000, "%s", exprStr); @@ -557,16 +557,31 @@ static str PyAPIeval(Client cntxt, MalBl SQLSTATE(PY000) "Could not open Python source file \"%s\".", address); goto wrapup; } - fseek(fp, 0, SEEK_END); - length = ftell(fp); - fseek(fp, 0, SEEK_SET); + if(fseek(fp, 0, SEEK_END) == -1) { + msg = createException( + MAL, "pyapi.eval", + SQLSTATE(PY000) "Failed to set file pointer on Python source file \"%s\".", address); + goto wrapup; + } + if((length = ftell(fp)) == -1) { + msg = createException( + MAL, "pyapi.eval", + SQLSTATE(PY000) "Failed to set file pointer on Python source file \"%s\".", address); + goto wrapup; + } + if(fseek(fp, 0, SEEK_SET) == -1) { + msg = createException( + MAL, "pyapi.eval", + SQLSTATE(PY000) "Failed to set file pointer on Python source file \"%s\".", address); + goto wrapup; + } exprStr = GDKzalloc(length + 1); if (exprStr == NULL) { msg = createException(MAL, "pyapi.eval", SQLSTATE(HY001) MAL_MALLOC_FAIL " function body string."); goto wrapup; } - if (fread(exprStr, 1, length, fp) != length) { + if (fread(exprStr, 1, (size_t) length, fp) != (size_t) length) { msg = createException(MAL, "pyapi.eval", SQLSTATE(PY000) "Failed to read from file \"%s\".", address); diff --git a/tools/merovingian/daemon/merovingian.c b/tools/merovingian/daemon/merovingian.c --- a/tools/merovingian/daemon/merovingian.c +++ b/tools/merovingian/daemon/merovingian.c @@ -793,44 +793,64 @@ main(int argc, char *argv[]) MERO_EXIT(1); } - sigemptyset(&sa.sa_mask); - sa.sa_flags = 0; - sa.sa_handler = handler; - if ( - sigaction(SIGINT, &sa, NULL) == -1 || - sigaction(SIGQUIT, &sa, NULL) == -1 || - sigaction(SIGTERM, &sa, NULL) == -1) - { + if(sigemptyset(&sa.sa_mask) == -1) { Mfprintf(oerr, "%s: FATAL: unable to create signal handlers: %s\n", - argv[0], strerror(errno)); + argv[0], strerror(errno)); MERO_EXIT(1); + } else { + sa.sa_flags = 0; + sa.sa_handler = handler; + if ( + sigaction(SIGINT, &sa, NULL) == -1 || + sigaction(SIGQUIT, &sa, NULL) == -1 || + sigaction(SIGTERM, &sa, NULL) == -1) + { + Mfprintf(oerr, "%s: FATAL: unable to create signal handlers: %s\n", + argv[0], strerror(errno)); + MERO_EXIT(1); + } } - sigemptyset(&sa.sa_mask); - sa.sa_flags = 0; - sa.sa_handler = huphandler; - if (sigaction(SIGHUP, &sa, NULL) == -1) { + if(sigemptyset(&sa.sa_mask) == -1) { Mfprintf(oerr, "%s: FATAL: unable to create signal handlers: %s\n", - argv[0], strerror(errno)); + argv[0], strerror(errno)); MERO_EXIT(1); + } else { + sa.sa_flags = 0; + sa.sa_handler = huphandler; + if (sigaction(SIGHUP, &sa, NULL) == -1) { + Mfprintf(oerr, "%s: FATAL: unable to create signal handlers: %s\n", + argv[0], strerror(errno)); + MERO_EXIT(1); + } } - sigemptyset(&sa.sa_mask); - sa.sa_flags = 0; - sa.sa_handler = segvhandler; - if (sigaction(SIGSEGV, &sa, NULL) == -1) { + if(sigemptyset(&sa.sa_mask) == -1) { Mfprintf(oerr, "%s: FATAL: unable to create signal handlers: %s\n", - argv[0], strerror(errno)); + argv[0], strerror(errno)); MERO_EXIT(1); + } else { + sa.sa_flags = 0; + sa.sa_handler = segvhandler; + if (sigaction(SIGSEGV, &sa, NULL) == -1) { + Mfprintf(oerr, "%s: FATAL: unable to create signal handlers: %s\n", + argv[0], strerror(errno)); + MERO_EXIT(1); + } _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list