summaryrefslogtreecommitdiff
path: root/usr/src/lib/libc
diff options
context:
space:
mode:
authorRobert Mustacchi <rm@joyent.com>2017-06-05 20:48:33 +0000
committerRobert Mustacchi <rm@joyent.com>2017-06-05 20:48:33 +0000
commit49add8ec88f479abb39ea7a1962c18ffd9b7a046 (patch)
tree95a179591b01f353dfc7f7ba514d1afa826d59bf /usr/src/lib/libc
parentb1ac738d4a193c034d5b994ac54f4f6f662cad73 (diff)
downloadillumos-joyent-49add8ec88f479abb39ea7a1962c18ffd9b7a046.tar.gz
5097 psignal and psiginfo don't handle NULL arguments correctly
Reviewed by: Joshua M. Clulow <josh@sysmgr.org> Reviewed by: Jason King <jason.brian.king@gmail.com> Reviewed by: Igor Kozhukhov <igor@dilos.org> Approved by: Gordon Ross <gordon.w.ross@gmail.com>
Diffstat (limited to 'usr/src/lib/libc')
-rw-r--r--usr/src/lib/libc/port/gen/psiginfo.c32
-rw-r--r--usr/src/lib/libc/port/gen/psignal.c9
2 files changed, 23 insertions, 18 deletions
diff --git a/usr/src/lib/libc/port/gen/psiginfo.c b/usr/src/lib/libc/port/gen/psiginfo.c
index a648c81094..e7cf46abef 100644
--- a/usr/src/lib/libc/port/gen/psiginfo.c
+++ b/usr/src/lib/libc/port/gen/psiginfo.c
@@ -51,16 +51,23 @@ psiginfo(const siginfo_t *sip, const char *s)
{
char buf[256];
char *c;
+ size_t l = 0;
const struct siginfolist *listp;
- if (sip == 0)
+ if (sip == NULL)
return;
+ if (s != NULL && *s != '\0') {
+ l = snprintf(buf, sizeof (buf), _libc_gettext("%s : "), s);
+ if (l > sizeof (buf))
+ l = sizeof (buf);
+ }
+
if (sip->si_code <= 0) {
- (void) snprintf(buf, sizeof (buf),
- _libc_gettext("%s : %s ( from process %d )\n"),
- s, strsignal(sip->si_signo), sip->si_pid);
+ (void) snprintf(buf + l, sizeof (buf) - l,
+ _libc_gettext("%s ( from process %d )\n"),
+ strsignal(sip->si_signo), sip->si_pid);
} else if (((listp = &_sys_siginfolist[sip->si_signo-1]) != NULL) &&
sip->si_code <= listp->nsiginfo) {
c = _libc_gettext(listp->vsiginfo[sip->si_code-1]);
@@ -69,21 +76,20 @@ psiginfo(const siginfo_t *sip, const char *s)
case SIGBUS:
case SIGILL:
case SIGFPE:
- (void) snprintf(buf, sizeof (buf),
- _libc_gettext("%s : %s ( [%p] %s)\n"),
- s, strsignal(sip->si_signo),
+ (void) snprintf(buf + l, sizeof (buf) - l,
+ _libc_gettext("%s ( [%p] %s)\n"),
+ strsignal(sip->si_signo),
sip->si_addr, c);
break;
default:
- (void) snprintf(buf, sizeof (buf),
- _libc_gettext("%s : %s (%s)\n"),
- s, strsignal(sip->si_signo), c);
+ (void) snprintf(buf + l, sizeof (buf) - l,
+ _libc_gettext("%s (%s)\n"),
+ strsignal(sip->si_signo), c);
break;
}
} else {
- (void) snprintf(buf, sizeof (buf),
- _libc_gettext("%s : %s\n"),
- s, strsignal(sip->si_signo));
+ (void) snprintf(buf + l, sizeof (buf) - l,
+ _libc_gettext("%s\n"), strsignal(sip->si_signo));
}
(void) write(2, buf, strlen(buf));
}
diff --git a/usr/src/lib/libc/port/gen/psignal.c b/usr/src/lib/libc/port/gen/psignal.c
index 201beaacd7..2a61cd9610 100644
--- a/usr/src/lib/libc/port/gen/psignal.c
+++ b/usr/src/lib/libc/port/gen/psignal.c
@@ -37,8 +37,6 @@
* contributors.
*/
-#pragma ident "%Z%%M% %I% %E% SMI"
-
/*
* Print the name of the signal indicated by "sig", along with the
* supplied message
@@ -61,14 +59,15 @@ void
psignal(int sig, const char *s)
{
char *c;
- size_t n;
+ size_t n = 0;
char buf[256];
if (sig < 0 || sig >= NSIG)
sig = 0;
c = strsignal(sig);
- n = strlen(s);
- if (n) {
+ if (s != NULL)
+ n = strlen(s);
+ if (n != 0) {
(void) snprintf(buf, sizeof (buf), "%s: %s\n", s, c);
} else {
(void) snprintf(buf, sizeof (buf), "%s\n", c);