commit a479eeb424496b781d7ea9cf7b2d9a6404d7c32f
Author: Georg Koppen <gk(a)torproject.org>
Date: Sun Sep 1 06:14:09 2019 +0000
Bug 31567: NS_tsnprintf() does not handle %s correctly on Windows
---
projects/mingw-w64-clang/31567_1.patch | 33 ++++++++++++++
projects/mingw-w64-clang/31567_2.patch | 82 ++++++++++++++++++++++++++++++++++
projects/mingw-w64-clang/build | 2 +
projects/mingw-w64-clang/config | 2 +
4 files changed, 119 insertions(+)
diff --git a/projects/mingw-w64-clang/31567_1.patch b/projects/mingw-w64-clang/31567_1.patch
new file mode 100644
index 0000000..be316ee
--- /dev/null
+++ b/projects/mingw-w64-clang/31567_1.patch
@@ -0,0 +1,33 @@
+From d9c7a5aa3ac8d29b98f28af71d862c2d3931e7d8 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Martin=20Storsj=C3=B6?= <martin(a)martin.st>
+Date: Sun, 1 Sep 2019 06:05:40 +0000
+Subject: [PATCH 1/2] This function was moved from inline in header to a
+ statically linked one in 52a34d52d6f5f1789d329abd4e, where the use of this
+ define was dropped.
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+As this function is statically linked, the caller can't control
+and change the behaviour of the function by defining
+UCRTBASE_PRINTF_DEFAULT_WIDE in the calling translation unit,
+but we should at least use the headers' default value (which currently
+is zero).
+
+Signed-off-by: Martin Storsjö <martin(a)martin.st>
+
+diff --git a/mingw-w64-crt/stdio/ucrt__vsnwprintf.c b/mingw-w64-crt/stdio/ucrt__vsnwprintf.c
+index bf9f4de2..c505c31e 100644
+--- a/mingw-w64-crt/stdio/ucrt__vsnwprintf.c
++++ b/mingw-w64-crt/stdio/ucrt__vsnwprintf.c
+@@ -10,6 +10,6 @@
+
+ int __cdecl _vsnwprintf(wchar_t * __restrict__ _Dest,size_t _Count,const wchar_t * __restrict__ _Format,va_list _Args) __MINGW_ATTRIB_DEPRECATED_SEC_WARN
+ {
+- return __stdio_common_vswprintf(UCRTBASE_PRINTF_LEGACY_VSPRINTF_NULL_TERMINATION, _Dest, _Count, _Format, NULL, _Args);
++ return __stdio_common_vswprintf(UCRTBASE_PRINTF_DEFAULT_WIDE | UCRTBASE_PRINTF_LEGACY_VSPRINTF_NULL_TERMINATION, _Dest, _Count, _Format, NULL, _Args);
+ }
+ int __cdecl (*__MINGW_IMP_SYMBOL(_vsnwprintf))(wchar_t *__restrict__, size_t, const wchar_t *__restrict__, va_list) = _vsnwprintf;
+--
+2.23.0.rc1
+
diff --git a/projects/mingw-w64-clang/31567_2.patch b/projects/mingw-w64-clang/31567_2.patch
new file mode 100644
index 0000000..12070aa
--- /dev/null
+++ b/projects/mingw-w64-clang/31567_2.patch
@@ -0,0 +1,82 @@
+From 44d0691f6fa51d2b3a0df911652c801635424e4e Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Martin=20Storsj=C3=B6?= <martin(a)martin.st>
+Date: Sun, 1 Sep 2019 06:08:24 +0000
+Subject: [PATCH 2/2] When __USE_MINGW_ANSI_STDIO is defined, we still call the
+ custom implementation bundled in libmingwex, which has the C99 standard
+ semantics for %s in wide format strings.
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+This matches how the wide stdio functions behave both when using
+msvcrt.dll, and in all versions of MSVC, even the modern ones that
+use ucrt.
+
+Signed-off-by: Martin Storsjö <martin(a)martin.st>
+
+diff --git a/mingw-w64-headers/crt/conio.h b/mingw-w64-headers/crt/conio.h
+index 363203c3..a92ee059 100644
+--- a/mingw-w64-headers/crt/conio.h
++++ b/mingw-w64-headers/crt/conio.h
+@@ -21,12 +21,13 @@
+ #define UCRTBASE_SCANF_LEGACY_WIDE_SPECIFIERS (0x0002)
+ #define UCRTBASE_SCANF_LEGACY_MSVCRT_COMPATIBILITY (0x0004)
+
+-// Default wide printfs and scanfs to the standard mode
++// Default wide printfs and scanfs to the legacy wide mode. Only code built
++// with -D__USE_MINGW_ANSI_STDIO=1 will expect the standard behaviour.
+ #ifndef UCRTBASE_PRINTF_DEFAULT_WIDE
+-#define UCRTBASE_PRINTF_DEFAULT_WIDE 0
++#define UCRTBASE_PRINTF_DEFAULT_WIDE UCRTBASE_PRINTF_LEGACY_WIDE_SPECIFIERS
+ #endif
+ #ifndef UCRTBASE_SCANF_DEFAULT_WIDE
+-#define UCRTBASE_SCANF_DEFAULT_WIDE 0
++#define UCRTBASE_SCANF_DEFAULT_WIDE UCRTBASE_SCANF_LEGACY_WIDE_SPECIFIERS
+ #endif
+ #endif
+
+diff --git a/mingw-w64-headers/crt/stdio.h b/mingw-w64-headers/crt/stdio.h
+index e183236d..e8d3c857 100644
+--- a/mingw-w64-headers/crt/stdio.h
++++ b/mingw-w64-headers/crt/stdio.h
+@@ -147,12 +147,13 @@ extern FILE (* __MINGW_IMP_SYMBOL(_iob))[]; /* A pointer to an array of FILE */
+ #define UCRTBASE_SCANF_LEGACY_WIDE_SPECIFIERS (0x0002)
+ #define UCRTBASE_SCANF_LEGACY_MSVCRT_COMPATIBILITY (0x0004)
+
+-// Default wide printfs and scanfs to the standard mode
++// Default wide printfs and scanfs to the legacy wide mode. Only code built
++// with -D__USE_MINGW_ANSI_STDIO=1 will expect the standard behaviour.
+ #ifndef UCRTBASE_PRINTF_DEFAULT_WIDE
+-#define UCRTBASE_PRINTF_DEFAULT_WIDE 0
++#define UCRTBASE_PRINTF_DEFAULT_WIDE UCRTBASE_PRINTF_LEGACY_WIDE_SPECIFIERS
+ #endif
+ #ifndef UCRTBASE_SCANF_DEFAULT_WIDE
+-#define UCRTBASE_SCANF_DEFAULT_WIDE 0
++#define UCRTBASE_SCANF_DEFAULT_WIDE UCRTBASE_SCANF_LEGACY_WIDE_SPECIFIERS
+ #endif
+ #endif
+
+diff --git a/mingw-w64-headers/crt/wchar.h b/mingw-w64-headers/crt/wchar.h
+index cd26e098..d1348bc2 100644
+--- a/mingw-w64-headers/crt/wchar.h
++++ b/mingw-w64-headers/crt/wchar.h
+@@ -247,12 +247,13 @@ extern FILE (* __MINGW_IMP_SYMBOL(_iob))[]; /* A pointer to an array of FILE */
+ #define UCRTBASE_SCANF_LEGACY_WIDE_SPECIFIERS (0x0002)
+ #define UCRTBASE_SCANF_LEGACY_MSVCRT_COMPATIBILITY (0x0004)
+
+-// Default wide printfs and scanfs to the standard mode
++// Default wide printfs and scanfs to the legacy wide mode. Only code built
++// with -D__USE_MINGW_ANSI_STDIO=1 will expect the standard behaviour.
+ #ifndef UCRTBASE_PRINTF_DEFAULT_WIDE
+-#define UCRTBASE_PRINTF_DEFAULT_WIDE 0
++#define UCRTBASE_PRINTF_DEFAULT_WIDE UCRTBASE_PRINTF_LEGACY_WIDE_SPECIFIERS
+ #endif
+ #ifndef UCRTBASE_SCANF_DEFAULT_WIDE
+-#define UCRTBASE_SCANF_DEFAULT_WIDE 0
++#define UCRTBASE_SCANF_DEFAULT_WIDE UCRTBASE_SCANF_LEGACY_WIDE_SPECIFIERS
+ #endif
+ #endif
+
+--
+2.23.0.rc1
+
diff --git a/projects/mingw-w64-clang/build b/projects/mingw-w64-clang/build
index 4226212..820346d 100644
--- a/projects/mingw-w64-clang/build
+++ b/projects/mingw-w64-clang/build
@@ -69,6 +69,8 @@ default_win32_winnt=0x601
cd $builddir/mingw-w64-clang
patch -p1 < $rootdir/mingw-winrt.patch
+patch -p1 < $rootdir/31567_1.patch
+patch -p1 < $rootdir/31567_2.patch
cd mingw-w64-headers
mkdir build && cd build
../configure --host=[% c("arch") %]-w64-mingw32 \
diff --git a/projects/mingw-w64-clang/config b/projects/mingw-w64-clang/config
index 203e12e..16adee8 100644
--- a/projects/mingw-w64-clang/config
+++ b/projects/mingw-w64-clang/config
@@ -36,3 +36,5 @@ input_files:
- project: llvm-mingw
name: llvm-mingw
- filename: mingw-winrt.patch
+ - filename: 31567_1.patch
+ - filename: 31567_2.patch