Avoid buffer overflow or truncation when constructing path_zoneinfo_file.

Reported by:	Coverity
CID:		1011160
MFC after:	1 week
This commit is contained in:
Don Lewis 2016-05-26 01:45:04 +00:00
parent 243e928310
commit ee67f7cc77

View File

@ -838,7 +838,9 @@ install_zoneinfo(const char *zoneinfo)
FILE *f;
char path_zoneinfo_file[MAXPATHLEN];
sprintf(path_zoneinfo_file, "%s/%s", path_zoneinfo, zoneinfo);
if ((size_t)snprintf(path_zoneinfo_file, sizeof(path_zoneinfo_file),
"%s/%s", path_zoneinfo, zoneinfo) >= sizeof(path_zoneinfo_file))
errx(1, "%s/%s name too long", path_zoneinfo, zoneinfo);
rv = install_zoneinfo_file(path_zoneinfo_file);
/* Save knowledge for later */