bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: gl_{,SN}PRINTF_DIRECTIVE_N wrongly fail on Ubuntu 18.04


From: Bruno Haible
Subject: Re: gl_{,SN}PRINTF_DIRECTIVE_N wrongly fail on Ubuntu 18.04
Date: Sun, 08 Mar 2020 23:04:40 +0100
User-agent: KMail/5.1.3 (Linux/4.4.0-174-generic; KDE/5.18.0; x86_64; ; )

Hi Adrian,

> In that case there are one documentation deficit and two gnulib bugs:
> 
>     * This function does not support the 'n' directive on some platforms:
> -     MSVC 14.
> +     MSVC 14, glibc with _FORTIFY_SOURCE > 0 (default in some
> +     Linux distributions).
> 
> 
> The cross compile cases are then bogus for glibc:
> 
> printf:
>  *)               gl_cv_func_printf_directive_n="guessing yes";;
> 
> snprintf:
>  *-gnu* | gnu*)        gl_cv_func_snprintf_directive_n="guessing yes";;

Fixed through the patch below.

> it is unfortunate when GNU software like bison or gzip uses the
> gnulib replacement for most glibc users.

You mean, because of code size of the executable? In this case it would
make sense for gnulib to have "nearly POSIX" compliant variants of these
functions; this would remove the need for the gnulib *printf* code in
many cases.

Or because of security considerations (%n being used to construct "gadgets"
in malware)? In this case, it would be good to take this up with the ISO C
and POSIX standardization groups. Gnulib will adapt, as new versions of the
standards are released.


2020-03-08  Bruno Haible  <address@hidden>

        *printf-posix: Document why it's overridden on some glibc systems.
        Reported by Adrian Bunk <address@hidden> in
        <https://lists.gnu.org/archive/html/bug-gnulib/2020-03/msg00011.html>.
        * doc/posix-functions/*printf.texi: Document the problem with the %n
        directive on some glibc systems.
        * m4/printf.m4 (gl_PRINTF_DIRECTIVE_N, gl_SNPRINTF_DIRECTIVE_N): Adjust
        the cross-compilation guesses accordingly.

diff --git a/doc/posix-functions/fprintf.texi b/doc/posix-functions/fprintf.texi
index a596bcb..f555806 100644
--- a/doc/posix-functions/fprintf.texi
+++ b/doc/posix-functions/fprintf.texi
@@ -30,6 +30,7 @@ NetBSD 3.0, AIX 5.1, HP-UX 11.23, IRIX 6.5, Solaris 9,
 Cygwin 1.5.x, mingw, MSVC 14.
 @item
 This function does not support the @samp{n} directive on some platforms:
+glibc when used with @code{_FORTIFY_SOURCE >= 2} (set by default on Ubuntu),
 MSVC 14.
 @item
 This function does not support the @samp{ls} directive on some platforms:
diff --git a/doc/posix-functions/printf.texi b/doc/posix-functions/printf.texi
index 3f00531..1216656 100644
--- a/doc/posix-functions/printf.texi
+++ b/doc/posix-functions/printf.texi
@@ -30,6 +30,7 @@ NetBSD 3.0, AIX 5.1, HP-UX 11.23, IRIX 6.5, Solaris 9,
 Cygwin 1.5.x, mingw, MSVC 14.
 @item
 This function does not support the @samp{n} directive on some platforms:
+glibc when used with @code{_FORTIFY_SOURCE >= 2} (set by default on Ubuntu),
 MSVC 14.
 @item
 This function does not support the @samp{ls} directive on some platforms:
diff --git a/doc/posix-functions/snprintf.texi 
b/doc/posix-functions/snprintf.texi
index 477931f..6724043 100644
--- a/doc/posix-functions/snprintf.texi
+++ b/doc/posix-functions/snprintf.texi
@@ -45,6 +45,7 @@ NetBSD 3.0, AIX 5.1, HP-UX 11.23, IRIX 6.5, Solaris 9,
 Cygwin 1.5.x, mingw, MSVC 14.
 @item
 This function does not support the @samp{n} directive on some platforms:
+glibc when used with @code{_FORTIFY_SOURCE >= 2} (set by default on Ubuntu),
 MSVC 14.
 @item
 This function does not support the @samp{ls} directive on some platforms:
diff --git a/doc/posix-functions/sprintf.texi b/doc/posix-functions/sprintf.texi
index c43dd15..a880899 100644
--- a/doc/posix-functions/sprintf.texi
+++ b/doc/posix-functions/sprintf.texi
@@ -30,6 +30,7 @@ NetBSD 3.0, AIX 5.1, HP-UX 11.23, IRIX 6.5, Solaris 9,
 Cygwin 1.5.x, mingw, MSVC 14.
 @item
 This function does not support the @samp{n} directive on some platforms:
+glibc when used with @code{_FORTIFY_SOURCE >= 2} (set by default on Ubuntu),
 MSVC 14.
 @item
 This function does not support the @samp{ls} directive on some platforms:
diff --git a/doc/posix-functions/swprintf.texi 
b/doc/posix-functions/swprintf.texi
index b5aca13..4d849ae 100644
--- a/doc/posix-functions/swprintf.texi
+++ b/doc/posix-functions/swprintf.texi
@@ -27,6 +27,7 @@ This function is only defined as a macro on some platforms:
 MSVC 14.
 @item
 This function does not support the @samp{n} directive on some platforms:
+glibc when used with @code{_FORTIFY_SOURCE >= 2} (set by default on Ubuntu),
 MSVC 14.
 @item
 On Windows and 32-bit AIX platforms, @code{wchar_t} is a 16-bit type and 
therefore cannot
diff --git a/doc/posix-functions/vfprintf.texi 
b/doc/posix-functions/vfprintf.texi
index 0e7ecba..a87219e 100644
--- a/doc/posix-functions/vfprintf.texi
+++ b/doc/posix-functions/vfprintf.texi
@@ -30,6 +30,7 @@ NetBSD 3.0, AIX 5.1, HP-UX 11.23, IRIX 6.5, Solaris 9,
 Cygwin 1.5.x, mingw, MSVC 14.
 @item
 This function does not support the @samp{n} directive on some platforms:
+glibc when used with @code{_FORTIFY_SOURCE >= 2} (set by default on Ubuntu),
 MSVC 14.
 @item
 This function does not support the @samp{ls} directive on some platforms:
diff --git a/doc/posix-functions/vprintf.texi b/doc/posix-functions/vprintf.texi
index 09d9e2b..0cb573c 100644
--- a/doc/posix-functions/vprintf.texi
+++ b/doc/posix-functions/vprintf.texi
@@ -30,6 +30,7 @@ NetBSD 3.0, AIX 5.1, HP-UX 11.23, IRIX 6.5, Solaris 9,
 Cygwin 1.5.x, mingw, MSVC 14.
 @item
 This function does not support the @samp{n} directive on some platforms:
+glibc when used with @code{_FORTIFY_SOURCE >= 2} (set by default on Ubuntu),
 MSVC 14.
 @item
 This function does not support the @samp{ls} directive on some platforms:
diff --git a/doc/posix-functions/vsnprintf.texi 
b/doc/posix-functions/vsnprintf.texi
index de5258d..8f2f410 100644
--- a/doc/posix-functions/vsnprintf.texi
+++ b/doc/posix-functions/vsnprintf.texi
@@ -75,6 +75,7 @@ This function does not truncate the result as specified in 
C99 on some platforms
 mingw, MSVC 14.
 @item
 This function does not fully support the @samp{n} directive on some platforms:
+glibc when used with @code{_FORTIFY_SOURCE >= 2} (set by default on Ubuntu),
 HP-UX 11, mingw, MSVC 14.
 @item
 This function overwrites memory even when a zero size argument is passed on 
some
diff --git a/doc/posix-functions/vsprintf.texi 
b/doc/posix-functions/vsprintf.texi
index 71da5cc..4e264c7 100644
--- a/doc/posix-functions/vsprintf.texi
+++ b/doc/posix-functions/vsprintf.texi
@@ -30,6 +30,7 @@ NetBSD 3.0, AIX 5.1, HP-UX 11.23, IRIX 6.5, Solaris 9,
 Cygwin 1.5.x, mingw, MSVC 14.
 @item
 This function does not support the @samp{n} directive on some platforms:
+glibc when used with @code{_FORTIFY_SOURCE >= 2} (set by default on Ubuntu),
 MSVC 14.
 @item
 This function does not support the @samp{ls} directive on some platforms:
diff --git a/m4/printf.m4 b/m4/printf.m4
index 9df2153..54a2d71 100644
--- a/m4/printf.m4
+++ b/m4/printf.m4
@@ -1,4 +1,4 @@
-# printf.m4 serial 62
+# printf.m4 serial 63
 dnl Copyright (C) 2003, 2007-2020 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -711,6 +711,16 @@ int main ()
         [gl_cv_func_printf_directive_n=yes],
         [gl_cv_func_printf_directive_n=no],
         [case "$host_os" in
+                            # Guess no on glibc when _FORTIFY_SOURCE >= 2.
+           *-gnu* | gnu*)   AC_COMPILE_IFELSE(
+                              [AC_LANG_SOURCE(
+                                 [[#if _FORTIFY_SOURCE >= 2
+                                    error fail
+                                   #endif
+                                 ]])],
+                              [gl_cv_func_printf_directive_n="guessing yes"],
+                              [gl_cv_func_printf_directive_n="guessing no"])
+                            ;;
                             # Guess no on Android.
            linux*-android*) gl_cv_func_printf_directive_n="guessing no";;
                             # Guess no on native Windows.
@@ -1414,8 +1424,16 @@ int main ()
         [
 changequote(,)dnl
          case "$host_os" in
-                                 # Guess yes on glibc systems.
-           *-gnu* | gnu*)        gl_cv_func_snprintf_directive_n="guessing 
yes";;
+                                 # Guess no on glibc when _FORTIFY_SOURCE >= 2.
+           *-gnu* | gnu*)        AC_COMPILE_IFELSE(
+                                   [AC_LANG_SOURCE(
+                                      [[#if _FORTIFY_SOURCE >= 2
+                                         error fail
+                                        #endif
+                                      ]])],
+                                   [gl_cv_func_snprintf_directive_n="guessing 
yes"],
+                                   [gl_cv_func_snprintf_directive_n="guessing 
no"])
+                                 ;;
                                  # Guess yes on musl systems.
            *-musl*)              gl_cv_func_snprintf_directive_n="guessing 
yes";;
                                  # Guess yes on FreeBSD >= 5.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]