[PATCH v2] Add _FORTIFY_SOURCE support for inet_pton

Florian Weimer fweimer@redhat.com
Mon Mar 24 15:45:02 GMT 2025


* Aaron Merey:

> Add function __inet_pton_chk which calls __chk_fail when the size of
> argument dst is too small.   inet_pton is redirected to __inet_pton_chk
> or __inet_pton_warn when _FORTIFY_SOURCE is > 0.
>
> Also add tests to debug/tst-fortify.c, update the abilist with
> __inet_pton_chk and mention inet_pton fortification in maint.texi.
>
> Co-authored-by: Frédéric Bérat <fberat@redhat.com>
> ---
>
> On Mon, Mar 24, 2025 at 6:23 AM Florian Weimer <fweimer@redhat.com> wrote:
>>
>> * Aaron Merey:
>>
>> > +__fortify_function __attribute_overloadable__ int
>> > +__NTH (inet_pton (int __af,
>> > +        const char *__restrict __src,
>> > +        __fortify_clang_overload_arg (void *, __restrict, __dst)))
>> > +    __fortify_clang_warning_only_if_bos0_lt
>> > +     (4, __dst, "inet_pton called with destination buffer size less than 4")
>> > +{
>> > +  size_t scale = 0;
>> > +  if (__af == AF_INET)
>> > +    scale = 1;
>> > +  else if (__af == AF_INET6)
>> > +    scale = 4;
>> > +  else
>> > +    return __inet_pton_alias (__af, __src, __dst);
>> > +
>> > +  return __glibc_fortify (inet_pton, 4, scale,
>> > +                       __glibc_objsize (__dst),
>> > +                       __af, __src, __dst);
>> > +};
>>
>> Why not set scale to 1 and use the byte sizes directly?   This looks a
>> bit obfuscated.
>
> I've updated the patch with scale set to 1 and the sizes of
> in_addr/in6_addr used directly.

This new version looks okay to me.  Please add:

Reviewed-by: Florian Weimer <fweimer@redhat.com>

before pushing.

Thanks,
Florian



More information about the Libc-alpha mailing list