# HG changeset patch # User Bruno Haible # Date 1202434368 -3600 # Node ID cbba7bfe013b9d0fd54015e1edc89cc39f17a879 # Parent 2caa4d287a004a972d985b7638e9eb41071f0c65 Don't use %n on native Woe32 systems, to avoid a crash on Windows Vista systems. diff --git a/ChangeLog b/ChangeLog --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2008-02-07 Bruno Haible + + * lib/vasnprintf.c (VASNPRINTF): Don't use %n on native Woe32 systems. + Avoids a crash on Windows Vista. + Reported by Simon Josefsson . + 2008-02-06 Bruno Haible Fix *printf behaviour regarding the left-adjust flag on HP-UX 10.20. diff --git a/lib/vasnprintf.c b/lib/vasnprintf.c --- a/lib/vasnprintf.c +++ b/lib/vasnprintf.c @@ -4010,7 +4010,7 @@ #endif *fbp = dp->conversion; #if USE_SNPRINTF -# if !(__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 3)) +# if !(__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 3) || ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__)) fbp[1] = '%'; fbp[2] = 'n'; fbp[3] = '\0'; @@ -4023,6 +4023,21 @@ in format strings in writable memory may crash the program (if compiled with _FORTIFY_SOURCE=2), so we should avoid it in this situation. */ + /* On native Win32 systems (such as mingw), we can avoid using + %n because: + - Although the gl_SNPRINTF_TRUNCATION_C99 test fails, + snprintf does not write more than the specified number + of bytes. (snprintf (buf, 3, "%d %d", 4567, 89) writes + '4', '5', '6' into buf, not '4', '5', '\0'.) + - Although the gl_SNPRINTF_RETVAL_C99 test fails, snprintf + allows us to recognize the case of an insufficient + buffer size: it returns -1 in this case. + On native Win32 systems (such as mingw) where the OS is + Windows Vista, the use of %n in format strings by default + crashes the program. See + and + + So we should avoid %n in this situation. */ fbp[1] = '\0'; # endif #else