From: Arran Cudbard-Bell Date: Thu, 29 Jun 2017 03:12:12 +0000 (-0400) Subject: Fix GNU strerro_r usage X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2cd8d95425fb4f7c6238394d0afa0985ea0da4d3;p=thirdparty%2Ffreeradius-server.git Fix GNU strerro_r usage --- diff --git a/src/lib/util/syserror.c b/src/lib/util/syserror.c index 4d4b9f1754d..a81bcb7fed7 100644 --- a/src/lib/util/syserror.c +++ b/src/lib/util/syserror.c @@ -207,8 +207,10 @@ char const *fr_syserror(int num) */ #else { - p = strerror_r(num, p, end - p); - if (!p) { + char *q; + + q = strerror_r(num, p, end - p); + if (!q) { # ifndef NDEBUG fprintf(stderr, "strerror_r() failed to write error for errno %i to buffer %p " "(%zu bytes): %s\n", num, buffer, (size_t)FR_SYSERROR_BUFSIZE, strerror(errno)); @@ -217,6 +219,18 @@ char const *fr_syserror(int num) return buffer; } + /* + * If strerror_r used a static string, copy it to the buffer + */ + if (q != p) { + size_t len; + + len = strlen(q) + 1; + if (len >= (end - p)) len = end - p; + + strlcpy(p, q, len); + } + return buffer; } #endif