From 6c0f109fb98501fc8d65ea2c83501b45a80b00ab Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Wed, 23 Jan 2019 01:17:07 +0100 Subject: [PATCH 2/2] vasnprintf: Don't use %n on Android. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reported and fix suggested by Hugo Beauzée-Luyssen in . * lib/vasnprintf.c (VASNPRINTF): Don’t use %n on Android. --- ChangeLog | 7 +++++++ lib/vasnprintf.c | 9 +++++++++ 2 files changed, 16 insertions(+) diff --git a/ChangeLog b/ChangeLog index e3ec57b..f3972fd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,12 @@ 2019-01-22 Bruno Haible + vasnprintf: Don't use %n on Android. + Reported and fix suggested by Hugo Beauzée-Luyssen in + . + * lib/vasnprintf.c (VASNPRINTF): Don’t use %n on Android. + +2019-01-22 Bruno Haible + *printf: Support cross-compilation to Android. * m4/printf.m4: Add cross-compilation guesses for Android. diff --git a/lib/vasnprintf.c b/lib/vasnprintf.c index 465ecc3..b14a959 100644 --- a/lib/vasnprintf.c +++ b/lib/vasnprintf.c @@ -4874,6 +4874,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp, # if ! (((__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 3)) \ && !defined __UCLIBC__) \ || (defined __APPLE__ && defined __MACH__) \ + || defined __ANDROID__ \ || (defined _WIN32 && ! defined __CYGWIN__)) fbp[1] = '%'; fbp[2] = 'n'; @@ -4895,6 +4896,14 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp, On Mac OS X 10.13 or newer, the use of %n in format strings in writable memory by default crashes the program, so we should avoid it in this situation. */ + /* On Android, we know that snprintf's return value conforms to + ISO C 99: the tests gl_SNPRINTF_RETVAL_C99 and + gl_SNPRINTF_TRUNCATION_C99 pass. + Therefore we can avoid using %n in this situation. + Starting on 2018-03-07, the use of %n in format strings + produces a fatal error (see + ), + so we should avoid it. */ /* On native Windows systems (such as mingw), we can avoid using %n because: - Although the gl_SNPRINTF_TRUNCATION_C99 test fails, -- 2.7.4