aboutsummaryrefslogtreecommitdiffstats
path: root/src/sysdep.c
diff options
context:
space:
mode:
authorPaul Eggert2012-10-01 15:12:44 -0700
committerPaul Eggert2012-10-01 15:12:44 -0700
commitaa1ba90e4a95542c83cf636de3bc67e8fb23bad3 (patch)
tree1407a999bbc11bf54aaeba40764d6a75565db182 /src/sysdep.c
parentace917bddb2ed2448a97ddf279445bb581c5cd32 (diff)
downloademacs-aa1ba90e4a95542c83cf636de3bc67e8fb23bad3.tar.gz
emacs-aa1ba90e4a95542c83cf636de3bc67e8fb23bad3.zip
Fix a malloc race condition involving strsignal.
A signal can arrive in the middle of a malloc, and Emacs's signal handler can invoke strsignal, which can invoke malloc, which is not portable. This race condition bug makes Emacs hang on GNU/Linux. Fix it by altering the signal handler so that it does not invoke strsignal. * emacs.c (shut_down_emacs): Use safe_strsignal, not strsignal. * process.c (status_message): Use const pointer, in case strsignal is #defined to safe_strsignal. * sysdep.c (sys_siglist, init_signals): Always define and initialize a substitute sys_siglist if the system does not define one, even if HAVE_STRSIGNAL. (safe_strsignal): Rename from strsignal. Always define, using sys_siglist. Return a const pointer. * syssignal.h (safe_strsignal): New decl. (strsignal) [!HAVE_STRSIGNAL]: Define in terms of safe_strsignal.
Diffstat (limited to 'src/sysdep.c')
-rw-r--r--src/sysdep.c29
1 files changed, 13 insertions, 16 deletions
diff --git a/src/sysdep.c b/src/sysdep.c
index a825145c6dd..74617fcaf0f 100644
--- a/src/sysdep.c
+++ b/src/sysdep.c
@@ -1543,12 +1543,10 @@ deliver_thread_signal (int sig, signal_handler_t handler)
1543 errno = old_errno; 1543 errno = old_errno;
1544} 1544}
1545 1545
1546#if !defined HAVE_STRSIGNAL && !HAVE_DECL_SYS_SIGLIST 1546#if !HAVE_DECL_SYS_SIGLIST
1547static char *my_sys_siglist[NSIG]; 1547# undef sys_siglist
1548# ifdef sys_siglist
1549# undef sys_siglist
1550# endif
1551# define sys_siglist my_sys_siglist 1548# define sys_siglist my_sys_siglist
1549static char const *sys_siglist[NSIG];
1552#endif 1550#endif
1553 1551
1554/* Handle bus errors, invalid instruction, etc. */ 1552/* Handle bus errors, invalid instruction, etc. */
@@ -1611,7 +1609,7 @@ init_signals (bool dumping)
1611 main_thread = pthread_self (); 1609 main_thread = pthread_self ();
1612#endif 1610#endif
1613 1611
1614#if !defined HAVE_STRSIGNAL && !HAVE_DECL_SYS_SIGLIST 1612#if !HAVE_DECL_SYS_SIGLIST
1615 if (! initialized) 1613 if (! initialized)
1616 { 1614 {
1617 sys_siglist[SIGABRT] = "Aborted"; 1615 sys_siglist[SIGABRT] = "Aborted";
@@ -1759,7 +1757,7 @@ init_signals (bool dumping)
1759 sys_siglist[SIGXFSZ] = "File size limit exceeded"; 1757 sys_siglist[SIGXFSZ] = "File size limit exceeded";
1760# endif 1758# endif
1761 } 1759 }
1762#endif /* !defined HAVE_STRSIGNAL && !defined HAVE_DECL_SYS_SIGLIST */ 1760#endif /* !HAVE_DECL_SYS_SIGLIST */
1763 1761
1764 /* Don't alter signal handlers if dumping. On some machines, 1762 /* Don't alter signal handlers if dumping. On some machines,
1765 changing signal handlers sets static data that would make signals 1763 changing signal handlers sets static data that would make signals
@@ -2280,21 +2278,20 @@ set_file_times (int fd, const char *filename,
2280 return fdutimens (fd, filename, timespec); 2278 return fdutimens (fd, filename, timespec);
2281} 2279}
2282 2280
2283#ifndef HAVE_STRSIGNAL 2281/* Like strsignal, except async-signal-safe, and this function typically
2284char * 2282 returns a string in the C locale rather than the current locale. */
2285strsignal (int code) 2283char const *
2284safe_strsignal (int code)
2286{ 2285{
2287 char *signame = 0; 2286 char const *signame = 0;
2288 2287
2289 if (0 <= code && code < NSIG) 2288 if (0 <= code && code < NSIG)
2290 { 2289 signame = sys_siglist[code];
2291 /* Cast to suppress warning if the table has const char *. */ 2290 if (! signame)
2292 signame = (char *) sys_siglist[code]; 2291 signame = "Unknown signal";
2293 }
2294 2292
2295 return signame; 2293 return signame;
2296} 2294}
2297#endif /* HAVE_STRSIGNAL */
2298 2295
2299#ifndef DOS_NT 2296#ifndef DOS_NT
2300/* For make-serial-process */ 2297/* For make-serial-process */