summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Boros <puppyofkosh@gmail.com>2019-02-11 13:06:40 -0500
committerIan Boros <puppyofkosh@gmail.com>2019-02-12 18:02:53 -0500
commitdeb68db9838f307f0fd6ab3e74c741383b702075 (patch)
tree362a8a244c756f277acb1791c5997f2d4b412672
parent9d06566d7f8c9affbadd2bb9c54bb94457863dd0 (diff)
downloadmongo-deb68db9838f307f0fd6ab3e74c741383b702075.tar.gz
SERVER-39322 Backport fix for issue #37 in timelib (incorrect snprintf invocation)
Original commit message from timelib: Fixed #37: Incorrect snprintf invocation with static buffer
-rw-r--r--src/third_party/timelib-2017.05/parse_zoneinfo.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/third_party/timelib-2017.05/parse_zoneinfo.c b/src/third_party/timelib-2017.05/parse_zoneinfo.c
index 7ff88fbb766..fe99f94b738 100644
--- a/src/third_party/timelib-2017.05/parse_zoneinfo.c
+++ b/src/third_party/timelib-2017.05/parse_zoneinfo.c
@@ -101,7 +101,8 @@ static int is_valid_tzfile(const struct stat *st, int fd)
* length of the mapped data is placed in *length. */
static char *read_tzfile(const char *directory, const char *timezone, size_t *length)
{
- char fname[MAXPATHLEN];
+ char *fname;
+ size_t fname_len;
char *buffer;
struct stat st;
int fd;
@@ -115,9 +116,16 @@ static char *read_tzfile(const char *directory, const char *timezone, size_t *le
return NULL;
}
- snprintf(fname, sizeof(fname), "%s%s%s", directory, TIMELIB_DIR_SEPARATOR, timezone /* canonical_tzname(timezone) */);
+ fname_len = strlen(directory) + strlen(TIMELIB_DIR_SEPARATOR) + strlen(timezone) + 1;
+ fname = malloc(fname_len);
+ if (snprintf(fname, fname_len, "%s%s%s", directory, TIMELIB_DIR_SEPARATOR, timezone) < 0) {
+ free(fname);
+ return NULL;
+ }
fd = open(fname, O_RDONLY);
+ free(fname);
+
if (fd == -1) {
return NULL;
} else if (fstat(fd, &st) != 0 || !is_valid_tzfile(&st, fd)) {