glibc _FORTIFY_SOURCE=2 and %n in writable segment detected

Gilles Espinasse g.esp at free.fr
Sun Apr 25 07:19:36 PDT 2010


----- Original Message ----- 
From: "Kevin Day" <thekevinday at gmail.com>
To: "Hardened LFS Development List" <hlfs-dev at linuxfromscratch.org>
Sent: Saturday, April 24, 2010 3:47 PM
Subject: Re: glibc _FORTIFY_SOURCE=2 and %n in writable segment detected


> On 4/24/10, Gilles Espinasse <g.esp at free.fr> wrote:
> > Some packages actually coreutils-8.{4,5}, gzip-1.4, m4-1.4.14 print a
> >  spurious
> >  "%n in writable segment detected" message during configure when glibc
is
> >  compiled with _FORTIFY_SOURCE=2
> >
> >  This result in gl_cv_func_printf_directive_n=no.
> >  If we want to be able to control where the message is printed, we need
to
> >  add to the configure command
> >  LIBC_FATAL_STDERR_=1 ./configure
> >
> >  That way, the message is redirected to stderr as usual.
> >  http://sourceware.org/bugzilla/show_bug.cgi?id=9854
> >
> >  Gilles
> >
> >
>
> Does this cause any configure tests to fail that should otherwise succeed?
>
> -- 
> Kevin Day
> -- 
That's a good question
Author of the test know that test will fail if compiled with
_FORTIFY_SOURCE=2

Just look in configure and comment inside test is clear
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

#include <stdio.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;
}
_ACEOF

Now the question is :
is it required to support %n in writable memory to support %n format?

If gnulib emulate that system call because test has failed, will the
emulation be better, worst or the same than original from glibc?

Gilles




More information about the hlfs-dev mailing list