[PATCH] add attribute nonstring

Martin Sebor msebor@gmail.com
Wed Nov 15 23:05:00 GMT 2017


On 11/15/2017 03:09 PM, Steve Ellcey wrote:
> On Fri, 2017-11-10 at 16:11 -0700, Martin Sebor wrote:
>>
>> Okay, thanks.  I've read that you run periodic Glibc builds with
>> the latest GCC so I wanted to give you a heads up on this change
>> and the patch to avoid breaking them.  Unless that's not a concern
>> (do you use -Werror in those builds?) what is the best way to
>> coordinate this update?
>>
>> I CC Paul for his input in case updating tzcode first is important.
>>
>> Martin
>
> Martin, were you going to update this patch with Joseph's comments and
> resubmit?  The tz changes are checked in and the ifreq struct is taken
> care of so all that remains are the changes to cdefs.h to define
> __NONSTRING and then to use in utmp.h.  I don't have any comments on
> that change beyond what Joseph made but I did do a build and run on
> aarch64 with the latest GCC to verify that those changes work for me.

Sure.  I've got the attached patch.  According to the Linux utmp
man page:
        String fields are terminated by a null byte ('\0')
        if they are shorter than the size of the field.

The patch lets Glibc compile fine with the top of GCC 8 trunk.

As a heads up, the new attribute triggers warnings with my patch
that enhances GCC to check for string functions being passed
arrays declared with the attribute.  Some are false positives
that I'll try to handle in GCC but at least one of these looks
like a Glibc bug.  Assuming the GCC patch gets approved there
may be some more fallout for Glibc to deal with.

../sysdeps/unix/getlogin_r.c:83:23: warning: ‘strlen’ argument 1 
declared attribute ‘nonstring’ [-Wstringop-overflow=]
        size_t needed = strlen (ut->ut_user) + 1;
                        ^~~~~~~~~~~~~~~~~~~~
In file included from ../login/utmp.h:29,
                  from ../include/utmp.h:2,
                  from ../sysdeps/unix/getlogin_r.c:26,
                  from ../sysdeps/unix/sysv/linux/getlogin_r.c:25:
../sysdeps/gnu/bits/utmp.h:65:8: note: argument ‘ut_user’ declared here
    char ut_user[UT_NAMESIZE]
         ^~~~~~~

Martin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: glibc-nonstring.diff
Type: text/x-patch
Size: 2297 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/libc-alpha/attachments/20171115/84d6747a/attachment.bin>


More information about the Libc-alpha mailing list