From 482d9590b54308e7b2f83cdf4180426c38444894 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Mon, 1 Feb 2016 14:52:34 +0100 Subject: Don't use unsafe _snprintf on MSVC older than 2015. Wrap the unsafe _snprintf to ensure that the string is null-terminated even on overflow. --- include/mupdf/fitz/system.h | 25 +++++++++++++++++++++++-- thirdparty/mujs | 2 +- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/include/mupdf/fitz/system.h b/include/mupdf/fitz/system.h index aeb5686c..abc3b9b7 100644 --- a/include/mupdf/fitz/system.h +++ b/include/mupdf/fitz/system.h @@ -112,11 +112,32 @@ struct timeval; struct timezone; int gettimeofday(struct timeval *tv, struct timezone *tz); -#define snprintf _snprintf -#if _MSC_VER < 1800 +#if _MSC_VER < 1900 /* MSVC 2015 */ +#define snprintf msvc_snprintf +#define vsnprintf msvc_vsnprintf +static int msvc_vsnprintf(char *str, size_t size, const char *fmt, va_list ap) +{ + int n; + n = _vsnprintf(str, size, fmt, ap); + str[size-1] = 0; + return n; +} +static int msvc_snprintf(char *str, size_t size, const char *fmt, ...) +{ + int n; + va_list ap; + va_start(ap, fmt); + n = msvc_vsnprintf(str, size, fmt, ap); + va_end(ap); + return n; +} +#endif + +#if _MSC_VER < 1700 /* MSVC 2012 */ #define isnan(x) _isnan(x) #define isinf(x) (!_finite(x)) #endif + #define hypotf _hypotf FILE *fz_fopen_utf8(const char *name, const char *mode); diff --git a/thirdparty/mujs b/thirdparty/mujs index d800b59f..a462ed44 160000 --- a/thirdparty/mujs +++ b/thirdparty/mujs @@ -1 +1 @@ -Subproject commit d800b59f0f0fabc15f3eb572ab85baefc0a7edef +Subproject commit a462ed445fba17987b9138c0c9b14d4e640910ee -- cgit v1.2.3