From 57cf2138522f3dacf26ea30c6f32a800def70209 Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Wed, 30 Jan 2008 13:33:17 +0000 Subject: fixed a bug that could cause invalid string handling via strerror_r varmojfekoj provided the patch - many thanks! --- syslogd.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'syslogd.c') diff --git a/syslogd.c b/syslogd.c index d47197d4..5d2531bf 100644 --- a/syslogd.c +++ b/syslogd.c @@ -2341,7 +2341,7 @@ void logerror(char *type) if (errno == 0) snprintf(buf, sizeof(buf), "%s", type); else { - strerror_r(errno, errStr, sizeof(errStr)); + rs_strerror_r(errno, errStr, sizeof(errStr)); snprintf(buf, sizeof(buf), "%s: %s", type, errStr); } buf[sizeof(buf)/sizeof(char) - 1] = '\0'; /* just to be on the safe side... */ @@ -3045,7 +3045,7 @@ finalize_it: if(fCurr != NULL) selectorDestruct(fCurr); - strerror_r(errno, errStr, sizeof(errStr)); + rs_strerror_r(errno, errStr, sizeof(errStr)); dbgprintf("error %d processing config file '%s'; os error (if any): %s\n", iRet, pConfFile, errStr); } @@ -4133,6 +4133,20 @@ int decode(uchar *name, struct code *codetab) +char *rs_strerror_r(int errnum, char *buf, size_t buflen) { +#ifdef STRERROR_R_CHAR_P + char *p = strerror_r(errnum, buf, buflen); + if (p != buf) { + strncpy(buf, p, buflen); + buf[buflen - 1] = '\0'; + } +#else + strerror_r(errnum, buf, buflen); +#endif + return buf; +} + + /* * The following function is resposible for handling a SIGHUP signal. Since * we are now doing mallocs/free as part of init we had better not being -- cgit