From 3f5fc2f959affe8f2c40944aeed6c2bf75cf462c Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Mon, 3 Sep 2007 14:44:53 +0200 Subject: [PATCH] sstrerror: Be even more cautios with the return value of `strerror_r'.. I don't trust this GNU implementation one bit.. ;) --- src/common.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/common.c b/src/common.c index 7555b7ef..951bae30 100644 --- a/src/common.c +++ b/src/common.c @@ -82,13 +82,23 @@ char *sstrerror (int errnum, char *buf, size_t buflen) temp = strerror_r (errnum, buf, buflen); if (buf[0] == '\0') { - strncpy (buf, temp, buflen); + if ((temp != NULL) && (temp != buf) && (temp[0] != '\0')) + strncpy (buf, temp, buflen); + else + strncpy (buf, "strerror_r did not return " + "an error message", buflen); buf[buflen - 1] = '\0'; } } #else - strerror_r (errnum, buf, buflen); + if (strerror_r (errnum, buf, buflen) != 0) + { + snprintf (buf, buflen, "Error #%i; " + "Additionally, strerror_r failed.", + errnum); + } #endif /* STRERROR_R_CHAR_P */ + buf[buflen - 1] = '\0'; return (buf); } /* char *sstrerror */ -- 2.30.2