From 02e061ec186e797ca1a1d1a0ba4f255166008500 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Tue, 14 Mar 2017 11:02:10 -0400 Subject: [PATCH] Hardcode signal messages in C99 style. Fixed null pointer access in several places. Need to make the messages array private and use an API to synthesize unknown signal messages as well protect against null pointer access --- .gitignore | 5 ++++ fn.c | 5 ++-- sigmsgs.c | 68 ++++++++++++++++++++++++++++-------------------------- 3 files changed, 43 insertions(+), 35 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b9c4208 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +*.o +rc +mkstatval +statval.h +tags diff --git a/fn.c b/fn.c index 97e0b43..ac89895 100644 --- a/fn.c +++ b/fn.c @@ -139,6 +139,7 @@ static void dud_handler(int ignore) { */ extern void fnassign(char *name, Node *def) { + if (!name) return; Node *newdef = treecpy(def == NULL ? &null : def, ealloc); /* important to do the treecopy first */ rc_Function *new = get_fn_place(name); int i; @@ -212,7 +213,7 @@ extern char *fnlookup_string(char *name) { extern void fnrm(char *name) { int i; for (i = 1; i < NSIG; i++) - if (streq(signals[i].name, name)) { + if (signals[i].name && streq(signals[i].name, name)) { handlers[i] = NULL; switch (i) { case SIGINT: @@ -236,7 +237,7 @@ extern void fnrm(char *name) { extern void whatare_all_signals() { int i; for (i = 1; i < NSIG; i++) - if (*signals[i].name != '\0') { + if (signals[i].name && *signals[i].name) { if (sighandlers[i] == SIG_IGN) fprint(1, "fn %s {}\n", signals[i].name); else if (sighandlers[i] == fn_handler) diff --git a/sigmsgs.c b/sigmsgs.c index 54c9400..d7d3219 100644 --- a/sigmsgs.c +++ b/sigmsgs.c @@ -1,36 +1,38 @@ #include "rc.h" -Sigmsgs signals[] = { - {"", ""}, - {"sighup", "hangup"}, - {"sigint", ""}, - {"sigquit", "quit"}, - {"sigill", "illegal instruction"}, - {"sigtrap", "trace trap"}, - {"sigabrt", "abort"}, - {"sigemt", "emt instruction"}, - {"sigfpe", "floating point error"}, - {"sigkill", "killed"}, - {"sigbus", "bus error"}, - {"sigsegv", "segmentation violation"}, - {"sigsys", "invalid argument to system call"}, - {"sigpipe", ""}, - {"sigalrm", "alarm clock"}, - {"sigterm", "terminated"}, - {"sigurg", "urgent condition on i/o channel"}, - {"sigstop", "stopped by program"}, - {"sigtstp", "stopped"}, - {"sigcont", "continue"}, - {"sigchld", "child stop or exit"}, - {"sigttin", "background tty read"}, - {"sigttou", "background tty write"}, - {"sigio", "socket i/o possible"}, - {"sigxcpu", "exceeded cpu time limit"}, - {"sigxfsz", "exceeded file size limit"}, - {"sigvtalrm", "virtual timer alarm"}, - {"sigprof", "profiling timer alarm"}, - {"sigwinch", "window size change"}, - {"siginfo", "information request"}, - {"sigusr1", "user defined signal 1"}, - {"sigusr2", "user defined signal 2"}, +Sigmsgs signals[NSIG] = { + [SIGHUP] = { "sighup", "hangup" }, + [SIGINT] = { "sigint", "" }, + [SIGQUIT] = { "sigquit", "quit" }, + [SIGILL] = { "sigill", "illegal instruction" }, + [SIGTRAP] = { "sigtrap", "trace trap" }, + [SIGABRT] = { "sigabrt", "abort" }, + [SIGIOT] = { "sigiot", "iot trap " }, + [SIGBUS] = { "sigbus", "bus error" }, + [SIGFPE] = { "sigfpe", "floating-point exception" }, + [SIGKILL] = { "sigkill", "kill, unblockable" }, + [SIGUSR1] = { "sigusr1", "user-defined signal 1" }, + [SIGSEGV] = { "sigsegv", "segmentation violation" }, + [SIGUSR2] = { "sigusr2", "user-defined signal 2" }, + [SIGPIPE] = { "sigpipe", "broken pipe" }, + [SIGALRM] = { "sigalrm", "alarm clock" }, + [SIGTERM] = { "sigterm", "termination" }, + [SIGSTKFLT] = { "sigstkflt", "stack fault" }, + [SIGCLD] = { "sigcld", "child stop or exit" }, + [SIGCHLD] = { "sigchld", "child status has changed" }, + [SIGCONT] = { "sigcont", "continue" }, + [SIGSTOP] = { "sigstop", "stop, unblockable" }, + [SIGTSTP] = { "sigstp", "keyboard stop" }, + [SIGTTIN] = { "sigttin", "background read from tty" }, + [SIGTTOU] = { "sigttou", "background write to tty" }, + [SIGURG] = { "sigurg", "urgent condition on socket" }, + [SIGXCPU] = { "sigxcpu", "cpu limit exceeded" }, + [SIGXFSZ] = { "sigxfsz", "file size limit exceeded" }, + [SIGVTALRM] = { "sigvtalrm", "virtual alarm clock" }, + [SIGPROF] = { "sigprof", "profiling alarm clock" }, + [SIGWINCH] = { "sigwinch", "window size change" }, + [SIGPOLL] = { "sigpoll", "pollable event occurred" }, + [SIGIO] = { "sigio", "i/o now possible" }, + [SIGPWR] = { "sigpwr", "power failure restart" }, + [SIGSYS] = { "sigsys", "bad system call" }, }; -- 2.49.0