[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 18:59:54 +0100 |
User-agent: |
KMail/5.1.3 (Linux/4.4.0-174-generic; KDE/5.18.0; x86_64; ; ) |
Hi Adrian,
> rpl_fprintf is wrongly being used on Ubuntu 18.04 due to:
>
> $ cat test.c
> /* gl_PRINTF_DIRECTIVE_N */
> #include <stdio.h>
> #include <stdlib.h>
> #include <string.h>
> static char fmtstring[10];
> static char buf[100];
> int main ()
> {
> int count = -1;
> /* Copy the format string. Some systems (glibc with _FORTIFY_SOURCE=2)
> support %n in format strings in read-only memory but not in writable
> memory. */
> strcpy (fmtstring, "%d %n");
> if (sprintf (buf, fmtstring, 123, &count, 33, 44, 55) < 0
> || strcmp (buf, "123 ") != 0
> || count != 4)
> return 1;
> return 0;
> }
> $ gcc -O2 test.c -o test && ./test
> *** %n in writable segment detected ***
> Aborted
> $
gnulib works as designed. gnulib is designed to override system function so as
to make them POSIX compliant. POSIX [1] specifies that support for %n in the
*printf functions is mandatory. As you have shown with the test program, glibc
does not provide %n support when the CFLAGS contain _FORTIFY_SOURCE=2; gnulib
rectifies that.
Bruno
[1] https://pubs.opengroup.org/onlinepubs/9699919799/functions/printf.html
- gl_{,SN}PRINTF_DIRECTIVE_N wrongly fail on Ubuntu 18.04, Adrian Bunk, 2020/03/08
- Re: gl_{,SN}PRINTF_DIRECTIVE_N wrongly fail on Ubuntu 18.04,
Bruno Haible <=
- Re: gl_{,SN}PRINTF_DIRECTIVE_N wrongly fail on Ubuntu 18.04, Adrian Bunk, 2020/03/08
- Re: gl_{,SN}PRINTF_DIRECTIVE_N wrongly fail on Ubuntu 18.04, Bruno Haible, 2020/03/08
- Re: gl_{,SN}PRINTF_DIRECTIVE_N wrongly fail on Ubuntu 18.04, Adrian Bunk, 2020/03/08
- Re: gl_{,SN}PRINTF_DIRECTIVE_N wrongly fail on Ubuntu 18.04, Bruno Haible, 2020/03/08
- Re: gl_{,SN}PRINTF_DIRECTIVE_N wrongly fail on Ubuntu 18.04, Paul Eggert, 2020/03/08
- Re: gl_{,SN}PRINTF_DIRECTIVE_N wrongly fail on Ubuntu 18.04, Bruno Haible, 2020/03/16