From: Jim Warner Date: Tue, 14 Nov 2017 05:00:00 +0000 (-0500) Subject: top: exploit msg handler override to avoid corrupt tty X-Git-Tag: v3.3.13rc1~46 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=18e5aecd2b61387ebd82c83f6f716e4c8e093272;p=procps-ng top: exploit msg handler override to avoid corrupt tty Way back in November of 2011, the library was equipped with an overridable error message handler function. It was done expressly for a program like top which alters the tty. But that support was withdrawn shortly after. This was all done in the lead up to v3.3.2. That's the release where NLS support was added and it represented a hectic time. In hindsight, the changes went too far. So this commit, in a minimal fashion, restores ability to address a potential fatal library error. After all, any properly behaving library would never unilaterally subject a caller to a stderr message and then an exit. [ when exposing 1 variable in libprocps.sym, 2 other ] [ existing symbols were repositioned alphabetically. ] Reference(s): . generalized library memory provisions commit 7126cc4491847ce5d50e603fe48666f94bfc60bf . top exploit library memory provisions commit 88087ec5a5968304d6461be2c2fbe05885ffdad8 . library xalloc type functions made private commit 2865ded64e72e0bec721dad9b442dab0899ee2b0 . restored prior top memory logic commit 05f5deb97c454b3558892ff4266efc81547f88d5 Signed-off-by: Jim Warner --- diff --git a/proc/libprocps.sym b/proc/libprocps.sym index 1996dc5a..75f334a9 100644 --- a/proc/libprocps.sym +++ b/proc/libprocps.sym @@ -47,7 +47,9 @@ global: page_bytes; pretty_print_signals; print_uptime; + procps_linux_version; put_slabinfo; + pwcache_get_user; readeither; readproc; readproctab2; @@ -62,8 +64,7 @@ global: tty_to_dev; unix_print_signals; uptime; - pwcache_get_user; - procps_linux_version; + xalloc_err_handler; local: *; }; diff --git a/top/top.c b/top/top.c index e90935c4..840c5269 100644 --- a/top/top.c +++ b/top/top.c @@ -47,6 +47,7 @@ #include "../include/fileutils.h" #include "../include/nls.h" +#include "../proc/alloc.h" #include "../proc/devname.h" #include "../proc/numa.h" #include "../proc/procps.h" @@ -640,6 +641,20 @@ static void sig_resize (int dont_care_sig) { Frames_signal = BREAK_sig; (void)dont_care_sig; } // end: sig_resize + + + /* + * Handles libproc memory errors, so our tty can be reset */ +static void xalloc_our_handler (const char *fmts, ...) { + static char buf[MEDBUFSIZ]; + va_list va; + + va_start(va, fmts); + vsnprintf(buf, sizeof(buf), fmts, va); + va_end(va); + scat(buf, "\n"); + bye_bye(buf); +} // end: xalloc_our_handler /*###### Special UTF-8 Multi-Byte support ##############################*/ @@ -3465,6 +3480,9 @@ static void before (char *me) { // accommodate nls/gettext potential translations initialize_nls(); + // override default library memory alloc error handler + xalloc_err_handler = xalloc_our_handler; + // establish cpu particulars #ifdef PRETEND8CPUS smp_num_cpus = 8; diff --git a/top/top.h b/top/top.h index 813a957b..31683cd2 100644 --- a/top/top.h +++ b/top/top.h @@ -681,6 +681,7 @@ typedef struct WIN_t { //atic void sig_endpgm (int dont_care_sig); //atic void sig_paused (int dont_care_sig); //atic void sig_resize (int dont_care_sig); +//atic void xalloc_our_handler (const char *fmts, ...); /*------ Special UTF-8 Multi-Byte support ------------------------------*/ /*atic char UTF8_tab[] = { ... } */ //atic int utf8_delta (const char *str);