bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
From: Bruno Haible <bruno@clisp.org>
To: bug-gnulib@gnu.org
Cc: Adrian Bunk <bunk@stusta.de>
Subject: Re: gl_{,SN}PRINTF_DIRECTIVE_N wrongly fail on Ubuntu 18.04
Date: Sun, 08 Mar 2020 18:59:54 +0100	[thread overview]
Message-ID: <1672454.J3UH0QvxPd@omega> (raw)
In-Reply-To: <20200308111935.GA20113@localhost>

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



  reply	other threads:[~2020-03-08 18:01 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-08 11:19 gl_{,SN}PRINTF_DIRECTIVE_N wrongly fail on Ubuntu 18.04 Adrian Bunk
2020-03-08 17:59 ` Bruno Haible [this message]
2020-03-08 18:46   ` Adrian Bunk
2020-03-08 22:04     ` Bruno Haible
2020-03-08 23:38       ` Adrian Bunk
2020-03-09  0:11         ` Bruno Haible
2020-03-09  3:36           ` Paul Eggert
2020-03-16 13:17       ` Bruno Haible

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://lists.gnu.org/mailman/listinfo/bug-gnulib

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1672454.J3UH0QvxPd@omega \
    --to=bruno@clisp.org \
    --cc=bug-gnulib@gnu.org \
    --cc=bunk@stusta.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).