From 48b6d2c8b7c6aa6df4bf6cc5c1f107869764b5f3 Mon Sep 17 00:00:00 2001 From: truckman Date: Thu, 26 May 2016 01:45:04 +0000 Subject: [PATCH] Avoid buffer overflow or truncation when constructing path_zoneinfo_file. Reported by: Coverity CID: 1011160 MFC after: 1 week --- usr.sbin/tzsetup/tzsetup.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/usr.sbin/tzsetup/tzsetup.c b/usr.sbin/tzsetup/tzsetup.c index e571d1f4751f..ce9e1480cc2a 100644 --- a/usr.sbin/tzsetup/tzsetup.c +++ b/usr.sbin/tzsetup/tzsetup.c @@ -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 */