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! --- configure.ac | 3 ++- net.c | 2 +- omfwd.c | 2 +- rfc3195d.c | 6 +++--- syslogd.c | 18 ++++++++++++++++-- syslogd.h | 1 + tcpsyslog.c | 4 ++-- 7 files changed, 26 insertions(+), 10 deletions(-) diff --git a/configure.ac b/configure.ac index 9acad937..fd96fa88 100644 --- a/configure.ac +++ b/configure.ac @@ -77,9 +77,10 @@ AC_FUNC_REALLOC AC_FUNC_SELECT_ARGTYPES AC_TYPE_SIGNAL AC_FUNC_STAT +AC_FUNC_STRERROR_R AC_FUNC_VPRINTF AC_FUNC_WAIT3 -AC_CHECK_FUNCS([alarm clock_gettime gethostbyname gethostname gettimeofday localtime_r memset mkdir regcomp select setid socket strcasecmp strchr strdup strerror strerror_r strndup strnlen strrchr strstr strtol strtoul uname ttyname_r]) +AC_CHECK_FUNCS([alarm clock_gettime gethostbyname gethostname gettimeofday localtime_r memset mkdir regcomp select setid socket strcasecmp strchr strdup strerror strndup strnlen strrchr strstr strtol strtoul uname ttyname_r]) # Large file support diff --git a/net.c b/net.c index e5807ec3..4654282f 100644 --- a/net.c +++ b/net.c @@ -578,7 +578,7 @@ int should_use_so_bsdcompat(void) init_done = 1; if (uname(&utsname) < 0) { char errStr[1024]; - dbgprintf("uname: %s\r\n", strerror_r(errno, errStr, sizeof(errStr))); + dbgprintf("uname: %s\r\n", rs_strerror_r(errno, errStr, sizeof(errStr))); return 1; } /* Format is .. diff --git a/omfwd.c b/omfwd.c index 66b8a055..d63ae1bf 100644 --- a/omfwd.c +++ b/omfwd.c @@ -188,7 +188,7 @@ static rsRetVal UDPSend(instanceData *pData, char *msg, size_t len) int eno = errno; char errStr[1024]; dbgprintf("sendto() error: %d = %s.\n", - eno, strerror_r(eno, errStr, sizeof(errStr))); + eno, rs_strerror_r(eno, errStr, sizeof(errStr))); } } if (lsent == len && !send_to_all) diff --git a/rfc3195d.c b/rfc3195d.c index e088c551..f79ec949 100644 --- a/rfc3195d.c +++ b/rfc3195d.c @@ -97,7 +97,7 @@ static void openlog() if(LogFile < 0) { char errStr[1024]; printf("error opening '%s': %s\n", - pPathLogname, strerror_r(errno, errStr, sizeof(errStr))); + pPathLogname, rs_strerror_r(errno, errStr, sizeof(errStr))); } } if (LogFile != -1 && !connected && @@ -107,7 +107,7 @@ static void openlog() else { char errStr[1024]; printf("error connecting '%s': %s\n", - pPathLogname, strerror_r(errno, errStr, sizeof(errStr))); + pPathLogname, rs_strerror_r(errno, errStr, sizeof(errStr))); } } @@ -163,7 +163,7 @@ void OnReceive(srAPIObj* pAPI, srSLMGObj* pSLMG) if(nWritten < 0) { /* error, recover! */ char errStr[1024]; - printf("error writing to domain socket: %s\r\n", strerror_r(errno, errStr, sizeof(errStr))); + printf("error writing to domain socket: %s\r\n", rs_strerror_r(errno, errStr, sizeof(errStr))); closelog(); } else { /* prepare for (potential) next write */ 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 diff --git a/syslogd.h b/syslogd.h index 17b45161..6163c292 100644 --- a/syslogd.h +++ b/syslogd.h @@ -49,6 +49,7 @@ #define ADDDATE 0x004 /* add a date to the message */ #define MARK 0x008 /* this message is a mark */ +char *rs_strerror_r(int errnum, char *buf, size_t buflen); void logerror(char *type); void logerrorSz(char *type, char *errMsg); void logerrorInt(char *type, int iErr); diff --git a/tcpsyslog.c b/tcpsyslog.c index 80f0d82a..0674f669 100644 --- a/tcpsyslog.c +++ b/tcpsyslog.c @@ -1051,7 +1051,7 @@ int TCPSendCreateSocket(struct addrinfo *addrDest) } else { char errStr[1024]; dbgprintf("create tcp connection failed, reason %s", - strerror_r(errno, errStr, sizeof(errStr))); + rs_strerror_r(errno, errStr, sizeof(errStr))); } } @@ -1062,7 +1062,7 @@ int TCPSendCreateSocket(struct addrinfo *addrDest) } else { char errStr[1024]; - dbgprintf("couldn't create send socket, reason %s", strerror_r(errno, errStr, sizeof(errStr))); + dbgprintf("couldn't create send socket, reason %s", rs_strerror_r(errno, errStr, sizeof(errStr))); } r = r->ai_next; } -- cgit v1.2.3