[PATCH v2] stdlib: Remove attr_write from mbstows if dst is NULL [BZ: 29265]
Noah Goldstein
goldstein.w.n@gmail.com
Wed Jun 22 22:38:02 GMT 2022
On Wed, Jun 22, 2022 at 3:06 PM Mark Wielaard <mark@klomp.org> wrote:
>
> Hi Noah,
>
> On Wed, Jun 22, 2022 at 02:38:07PM -0700, Noah Goldstein wrote:
> > I think it should be just mbstowcs, we don't pass dstlen
> >
> > Does:
> >
> > ```
> > diff --git a/stdlib/bits/stdlib.h b/stdlib/bits/stdlib.h
> > index d9c2d822a5..ece553df74 100644
> > --- a/stdlib/bits/stdlib.h
> > +++ b/stdlib/bits/stdlib.h
> > @@ -96,10 +96,10 @@ extern size_t __mbstowcs_chk (wchar_t *__restrict __dst,
> > const char *__restrict __src,
> > size_t __len, size_t __dstlen) __THROW
> > __attr_access ((__write_only__, 1, 3)) __attr_access ((__read_only__, 2));
> > -extern size_t __REDIRECT_NTH (__mbstowcs_chk_nulldst,
> > +extern size_t __REDIRECT_NTH (__mbstowcs_nulldst,
> > (wchar_t *__restrict __dst,
> > const char *__restrict __src,
> > - size_t __len), mbstowcs_chk)
> > + size_t __len), mbstowcs)
> > __attr_access ((__read_only__, 2));
> > extern size_t __REDIRECT_NTH (__mbstowcs_alias,
> > (wchar_t *__restrict __dst,
> > @@ -118,7 +118,7 @@ __NTH (mbstowcs (wchar_t *__restrict __dst, const
> > char *__restrict __src,
> > size_t __len))
> > {
> > if (__builtin_constant_p (__dst == NULL) && __dst == NULL)
> > - return __mbstowcs_chk_nulldst (__dst, __src, __len);
> > + return __mbstowcs_nulldst (__dst, __src, __len);
> > else
> > return __glibc_fortify_n (mbstowcs, __len, sizeof (wchar_t),
> > __glibc_objsize (__dst), __dst, __src, __len);
> > ```
> >
> > Work?
>
> I hope I applied to correctly, there were some whitespace issues.
> But no, that causes:
>
> make[2]: Entering directory '/srv/glibc/glibc/debug'
> g++ /srv/glibc/glibc-obj/debug/tst-fortify-cc-default-1.cc -c -I/srv/glibc/glibc-obj/ -g -O2 -Wall -Wwrite-strings -Wundef -Werror -fmerge-all-constants -frounding-math -fno-stack-protector -fno-common -fpie -D_FORTIFY_SOURCE=1 -Wno-format -Wno-deprecated-declarations -Wno-error -I../include -I/srv/glibc/glibc-obj/debug -I/srv/glibc/glibc-obj -I../sysdeps/unix/sysv/linux/x86_64/64 -I../sysdeps/unix/sysv/linux/x86_64 -I../sysdeps/unix/sysv/linux/x86/include -I../sysdeps/unix/sysv/linux/x86 -I../sysdeps/x86/nptl -I../sysdeps/unix/sysv/linux/wordsize-64 -I../sysdeps/x86_64/nptl -I../sysdeps/unix/sysv/linux/include -I../sysdeps/unix/sysv/linux -I../sysdeps/nptl -I../sysdeps/pthread -I../sysdeps/gnu -I../sysdeps/unix/inet -I../sysdeps/unix/sysv -I../sysdeps/unix/x86_64 -I../sysdeps/unix -I../sysdeps/posix -I../sysdeps/x86_64/64 -I../sysdeps/x86_64/fpu/multiarch -I../sysdeps/x86_64/fpu -I../sysdeps/x86/fpu -I../sysdeps/x86_64/multiarch -I../sysdeps/x86_64 -I../sysdeps/x86/include -I../sysdeps/x86 -I../sysdeps/ieee754/float128 -I../sysdeps/ieee754/ldbl-96/include -I../sysdeps/ieee754/ldbl-96 -I../sysdeps/ieee754/dbl-64 -I../sysdeps/ieee754/flt-32 -I../sysdeps/wordsize-64 -I../sysdeps/ieee754 -I../sysdeps/generic -I.. -I../libio -I. -D_LIBC_REENTRANT -include /srv/glibc/glibc-obj/libc-modules.h -DMODULE_NAME=testsuite -include ../include/libc-symbols.h -DPIC -DTOP_NAMESPACE=glibc -o /srv/glibc/glibc-obj/debug/tst-fortify-cc-default-1.o -MD -MP -MF /srv/glibc/glibc-obj/debug/tst-fortify-cc-default-1.o.dt -MT /srv/glibc/glibc-obj/debug/tst-fortify-cc-default-1.o
> In file included from ../include/sys/cdefs.h:10,
> from ../include/features.h:490,
> from ./tst-fortify.c:20,
> from /srv/glibc/glibc-obj/debug/tst-fortify-cc-default-1.cc:3:
> ../misc/sys/cdefs.h:424:26: error: duplicate ‘inline’
> 424 | # define __always_inline __inline __attribute__ ((__always_inline__))
> | ^~~~~~~~
> ../misc/sys/cdefs.h:453:10: note: in expansion of macro ‘__always_inline’
> 453 | extern __always_inline __attribute__ ((__gnu_inline__))
> | ^~~~~~~~~~~~~~~
> ../misc/sys/cdefs.h:461:29: note: in expansion of macro ‘__extern_always_inline’
> 461 | # define __fortify_function __extern_always_inline __attribute_artificial__
> | ^~~~~~~~~~~~~~~~~~~~~~
> ../stdlib/bits/stdlib.h:116:17: note: in expansion of macro ‘__fortify_function’
> 116 | __always_inline __fortify_function size_t
> | ^~~~~~~~~~~~~~~~~~
> make[2]: *** [../o-iterator.mk:9: /srv/glibc/glibc-obj/debug/tst-fortify-cc-default-1.o] Error 1
>
> I am afraid I am a little lost in the macro expansions that cause the
> duplicate inline here.
>
> Cheers,
>
> Mark
>
Seems the issue is the extra __always_inline:
```
diff --git a/stdlib/bits/stdlib.h b/stdlib/bits/stdlib.h
index d9c2d822a5..de1c3b20f0 100644
--- a/stdlib/bits/stdlib.h
+++ b/stdlib/bits/stdlib.h
@@ -96,10 +96,10 @@ extern size_t __mbstowcs_chk (wchar_t *__restrict __dst,
const char *__restrict __src,
size_t __len, size_t __dstlen) __THROW
__attr_access ((__write_only__, 1, 3)) __attr_access ((__read_only__, 2));
-extern size_t __REDIRECT_NTH (__mbstowcs_chk_nulldst,
+extern size_t __REDIRECT_NTH (__mbstowcs_nulldst,
(wchar_t *__restrict __dst,
const char *__restrict __src,
- size_t __len), mbstowcs_chk)
+ size_t __len), mbstowcs)
__attr_access ((__read_only__, 2));
extern size_t __REDIRECT_NTH (__mbstowcs_alias,
(wchar_t *__restrict __dst,
@@ -113,12 +113,12 @@ extern size_t __REDIRECT_NTH (__mbstowcs_chk_warn,
__warnattr ("mbstowcs called with dst buffer smaller than len "
"* sizeof (wchar_t)");
-__always_inline __fortify_function size_t
+__fortify_function size_t
__NTH (mbstowcs (wchar_t *__restrict __dst, const char *__restrict __src,
size_t __len))
{
if (__builtin_constant_p (__dst == NULL) && __dst == NULL)
- return __mbstowcs_chk_nulldst (__dst, __src, __len);
+ return __mbstowcs_nulldst (__dst, __src, __len);
else
return __glibc_fortify_n (mbstowcs, __len, sizeof (wchar_t),
__glibc_objsize (__dst), __dst, __src, __len);
```
can you try this. I am totally unable to reproduce this but its obviously a bug.
What build flags are you using? Whatever I have is insufficient.
More information about the Libc-alpha
mailing list