Use strlcpy() instead of strncpy() to copy the string returned by

setlocale() so that static analyzers know that the string is NUL
terminated.  This was causing a false positive in Coverity even
though the longest string returned by setlocale() is ENCODING_LEN
(31) and we are copying into a 64 byte buffer.  This change is also
a bit of an optimization since we don't need the strncpy() feature
of padding the rest of the destination buffer with NUL characters.

Reported by:	Coverity
CID:		974654
This commit is contained in:
Don Lewis 2016-05-12 06:39:13 +00:00
parent 5525a2edd8
commit 77b822dbc0

View File

@ -875,7 +875,7 @@ http_parse_mtime(const char *p, time_t *mtime)
char locale[64], *r;
struct tm tm;
strncpy(locale, setlocale(LC_TIME, NULL), sizeof(locale));
strlcpy(locale, setlocale(LC_TIME, NULL), sizeof(locale));
setlocale(LC_TIME, "C");
r = strptime(p, "%a, %d %b %Y %H:%M:%S GMT", &tm);
/*