changeset 40121:6240a6971ae1

vasnprintf: Don't use %n on Android. Reported and fix suggested by Hugo Beauzée-Luyssen <hugo@beauzee.fr> in <https://lists.gnu.org/archive/html/bug-gnulib/2018-12/msg00123.html>. * lib/vasnprintf.c (VASNPRINTF): Don’t use %n on Android.
author Bruno Haible <bruno@clisp.org>
date Wed, 23 Jan 2019 01:17:07 +0100
parents eab9edb07d2e
children 33ac33ab575c
files ChangeLog lib/vasnprintf.c
diffstat 2 files changed, 16 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Tue Jan 22 22:44:49 2019 +0100
+++ b/ChangeLog	Wed Jan 23 01:17:07 2019 +0100
@@ -1,3 +1,10 @@
+2019-01-22  Bruno Haible  <bruno@clisp.org>
+
+	vasnprintf: Don't use %n on Android.
+	Reported and fix suggested by Hugo Beauzée-Luyssen <hugo@beauzee.fr> in
+	<https://lists.gnu.org/archive/html/bug-gnulib/2018-12/msg00123.html>.
+	* lib/vasnprintf.c (VASNPRINTF): Don’t use %n on Android.
+
 2019-01-22  Bruno Haible  <bruno@clisp.org>
 
 	*printf: Support cross-compilation to Android.
--- a/lib/vasnprintf.c	Tue Jan 22 22:44:49 2019 +0100
+++ b/lib/vasnprintf.c	Wed Jan 23 01:17:07 2019 +0100
@@ -4874,6 +4874,7 @@
 # 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 @@
                    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
+                   <https://android.googlesource.com/platform/bionic/+/41398d03b7e8e0dfb951660ae713e682e9fc0336>),
+                   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,