diff options
| author | Aaron Merey <amerey@redhat.com> | 2025-03-20 13:13:33 -0400 |
|---|---|---|
| committer | Aaron Merey <amerey@redhat.com> | 2025-03-24 14:43:03 -0400 |
| commit | e3a6e85d67f1a48dec3e2557a83d6ce1544a58cb (patch) | |
| tree | d6c34a63a2c4c2d9c362916f150c3255e1ac4fdf /inet/bits | |
| parent | a71db81ed1353edd00ca2901d2fefd98c53209d3 (diff) | |
| download | glibc-e3a6e85d67f1a48dec3e2557a83d6ce1544a58cb.tar.xz glibc-e3a6e85d67f1a48dec3e2557a83d6ce1544a58cb.zip | |
Add _FORTIFY_SOURCE support for inet_pton
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>
Reviewed-by: Florian Weimer <fweimer@redhat.com>
Diffstat (limited to 'inet/bits')
| -rw-r--r-- | inet/bits/inet-fortified-decl.h | 7 | ||||
| -rw-r--r-- | inet/bits/inet-fortified.h | 20 |
2 files changed, 27 insertions, 0 deletions
diff --git a/inet/bits/inet-fortified-decl.h b/inet/bits/inet-fortified-decl.h index 23e3cf4b22..748a119f14 100644 --- a/inet/bits/inet-fortified-decl.h +++ b/inet/bits/inet-fortified-decl.h @@ -32,4 +32,11 @@ extern const char *__REDIRECT_NTH (__inet_ntop_chk_warn, __warnattr ("inet_ntop called with bigger length than " "size of destination buffer"); +extern int __inet_pton_chk (int, const char *, void *, size_t); + +extern int __REDIRECT_FORTIFY_NTH (__inet_pton_alias, + (int, const char *, void *), inet_pton); +extern int __REDIRECT_NTH (__inet_pton_chk_warn, + (int, const char *, void *, size_t), __inet_pton_chk) + __warnattr ("inet_pton called with a destination buffer size too small"); #endif /* bits/inet-fortified-decl.h. */ diff --git a/inet/bits/inet-fortified.h b/inet/bits/inet-fortified.h index 4f6bc34b0f..6738221a54 100644 --- a/inet/bits/inet-fortified.h +++ b/inet/bits/inet-fortified.h @@ -38,4 +38,24 @@ __NTH (inet_ntop (int __af, __af, __src, __dst, __dst_size); }; +__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 sz = 0; + if (__af == AF_INET) + sz = sizeof (struct in_addr); + else if (__af == AF_INET6) + sz = sizeof (struct in6_addr); + else + return __inet_pton_alias (__af, __src, __dst); + + return __glibc_fortify (inet_pton, sz, sizeof (char), + __glibc_objsize (__dst), + __af, __src, __dst); +}; + #endif /* bits/inet-fortified.h. */ |
