From patchwork Wed Jun 26 17:50:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Zack Weinberg X-Patchwork-Id: 33435 Received: (qmail 54409 invoked by alias); 26 Jun 2019 18:06:21 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 54353 invoked by uid 89); 26 Jun 2019 18:06:20 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-16.8 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.1 spammy=resistance X-HELO: l2mail1.panix.com From: Zack Weinberg To: libc-alpha@sourceware.org Cc: joseph@codesourcery.com, carlos@redhat.com Subject: [PATCH 19/25] =?UTF-8?q?Don=E2=80=99t=20include=20string.h=20from?= =?UTF-8?q?=20sys/un.h.?= Date: Wed, 26 Jun 2019 13:50:23 -0400 Message-Id: <20190626175029.4699-10-zackw@panix.com> In-Reply-To: <20190626175029.4699-1-zackw@panix.com> References: <20190626175029.4699-1-zackw@panix.com> MIME-Version: 1.0 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. --- nis/nis_domain_of.c | 1 + nis/yp_xdr.c | 1 + scripts/check-obsolete-constructs.py | 1 - socket/sys/un.h | 8 +++++--- sunrpc/svc.c | 1 + 5 files changed, 8 insertions(+), 4 deletions(-) diff --git a/nis/nis_domain_of.c b/nis/nis_domain_of.c index 44c5b04c8c..da26df36c7 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 3b576731da..4c9f1d22a0 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 bca0f12c18..d230fcf892 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 8c7433a3dc..540560e256 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 95ecfbb2d1..8042019ce9 100644 --- a/sunrpc/svc.c +++ b/sunrpc/svc.c @@ -53,6 +53,7 @@ */ #include +#include #include #include #include