From: Zack Weinberg Date: Wed, 22 May 2019 16:03:57 +0000 (-0400) Subject: Don’t include string.h from sys/un.h. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=225a0f4ef94a6505f2bb28d44d85bb3a9a45e5ef;p=thirdparty%2Fglibc.git Don’t include string.h from sys/un.h. sys/un.h needs strlen in order to define SUN_LEN, but does not need any of the other things declared by string.h; the path of least resistance is to prototype strlen locally. Also, the construct being used to get the size of everything up to the sun_path member contains a formal dereference of a null pointer and therefore has undefined behavior. Replace with __SOCKADDR_COMMON_SIZE. Some old RPC code was relying on sys/un.h to provide all of string.h. * sys/un.h [__USE_MISC]: Don’t include string.h. Include bits/types/size_t.h. Prototype strlen locally. Use __SOCKADDR_COMMON_SIZE for size of leading members of struct sockaddr_un. * nis/nis_domain_of.c, nis/yp_xdr.c, sunrpc/svc.c: Include string.h. * scripts/check-obsolete-constructs.py (HEADER_ALLOWED_INCLUDES): Update. --- diff --git a/nis/nis_domain_of.c b/nis/nis_domain_of.c index 06b2c54aeb3..e8f714069a0 100644 --- a/nis/nis_domain_of.c +++ b/nis/nis_domain_of.c @@ -17,6 +17,7 @@ . */ #include +#include #include nis_name diff --git a/nis/yp_xdr.c b/nis/yp_xdr.c index 3b576731da2..4c9f1d22a02 100644 --- a/nis/yp_xdr.c +++ b/nis/yp_xdr.c @@ -31,6 +31,7 @@ #include #include +#include #include /* The NIS v2 protocol suggests 1024 bytes as a maximum length of all fields. diff --git a/scripts/check-obsolete-constructs.py b/scripts/check-obsolete-constructs.py index 48a21cde0f9..9008892dafc 100755 --- a/scripts/check-obsolete-constructs.py +++ b/scripts/check-obsolete-constructs.py @@ -539,7 +539,6 @@ HEADER_ALLOWED_INCLUDES = { "sys/types.h": [ "endian.h" ], "sys/uio.h": [ "sys/types.h" ], - "sys/un.h": [ "string.h" ], # POSIX networking headers # allowed: netdb.h -> netinet/in.h diff --git a/socket/sys/un.h b/socket/sys/un.h index 8bc9c3adb88..d174e37ea66 100644 --- a/socket/sys/un.h +++ b/socket/sys/un.h @@ -34,11 +34,13 @@ struct sockaddr_un #ifdef __USE_MISC -# include /* For prototype of `strlen'. */ +#include + +extern size_t strlen (const char *__s) + __THROW __attribute_pure__ __nonnull ((1)); /* Evaluate to actual length of the `sockaddr_un' structure. */ -# define SUN_LEN(ptr) ((size_t) (((struct sockaddr_un *) 0)->sun_path) \ - + strlen ((ptr)->sun_path)) +# define SUN_LEN(ptr) (__SOCKADDR_COMMON_SIZE + strlen ((ptr)->sun_path)) #endif __END_DECLS diff --git a/sunrpc/svc.c b/sunrpc/svc.c index 1aa11094bf4..5c0d4dcaebc 100644 --- a/sunrpc/svc.c +++ b/sunrpc/svc.c @@ -53,6 +53,7 @@ */ #include +#include #include #include #include