From ee67f7cc774eede896ccaaceff0b9948d383ec63 Mon Sep 17 00:00:00 2001 From: Don Lewis 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 e571d1f4751..ce9e1480cc2 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 */