]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Fix sys/socket.h namespace issues from sys/uio.h inclusion (bug 21426).
authorJoseph Myers <joseph@codesourcery.com>
Tue, 25 Apr 2017 17:52:47 +0000 (17:52 +0000)
committerJoseph Myers <joseph@codesourcery.com>
Tue, 25 Apr 2017 17:52:47 +0000 (17:52 +0000)
sys/socket.h includes sys/uio.h to get the definition of the iovec
structure.

POSIX allows sys/socket.h to make all sys/uio.h symbols visible.
However, all of sys/uio.h is XSI-shaded, so for non-XSI POSIX this
results in conformtest failures (for sys/socket.h and other headers
that include it):

    Namespace violation: "UIO_MAXIOV"
    Namespace violation: "readv"
    Namespace violation: "writev"

Now, there is some ambiguity in POSIX about what namespace
reservations apply in this case - see
http://austingroupbugs.net/view.php?id=1127 - but glibc convention
would still avoid declaring readv and writev, for example, for feature
test macros that don't include them (if only headers from the relevant
standard are included), even if such declarations are permitted, so
there is a bug here according to glibc conventions.

This patch moves the struct iovec definition to a new
bits/types/struct_iovec.h header and includes that from sys/socket.h
instead of including the whole of sys/uio.h.  This fixes the namespace
issue; however, three files in glibc that were relying on the implicit
inclusion needed to be updated to include sys/uio.h explicitly.  So
there is a question of whether sys/socket.h should continue to include
sys/uio.h under some conditions, such as __USE_XOPEN or __USE_MISC or
__USE_XOPEN || __USE_MISC, for greater compatibility with code that
(wrongly) expects this optional inclusion to be present there.  (I
think the three affected files in glibc should still have explicit
sys/uio.h inclusions added in any case, however.)

Tested for x86_64.

[BZ #21426]
* misc/bits/types/struct_iovec.h: New file.
* misc/Makefile (headers): Add bits/types/struct_iovec.h.
* include/bits/types/struct_iovec.h: New file.
* bits/uio.h (struct iovec): Replace by inclusion of
<bits/types/struct_iovec.h>.
* sysdeps/unix/sysv/linux/bits/uio.h (struct iovec): Likewise.
* socket/sys/socket.h: Include <bits/types/struct_iovec.h> instead
of <sys/uio.h>.
* nptl/tst-cancel4.c: Include <sys/uio.h>
* posix/test-errno.c: Likewise.
* support/resolv_test.c: Likewise.
* conform/Makefile (test-xfail-POSIX2008/arpa/inet.h/conform):
Remove.
(test-xfail-POSIX2008/netdb.h/conform): Likewise.
(test-xfail-POSIX2008/netinet/in.h/conform): Likewise.
(test-xfail-POSIX2008/sys/socket.h/conform): Likewise.

ChangeLog
bits/uio.h
conform/Makefile
include/bits/types/struct_iovec.h [new file with mode: 0644]
misc/Makefile
misc/bits/types/struct_iovec.h [new file with mode: 0644]
nptl/tst-cancel4.c
posix/test-errno.c
socket/sys/socket.h
support/resolv_test.c
sysdeps/unix/sysv/linux/bits/uio.h

index 90ddfe0eae6cf107ac22778e66ebf9daac23b515..8867578f250eb5ecb7b2ad6344354a10f0305130 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,23 @@
 2017-04-25  Joseph Myers  <joseph@codesourcery.com>
 
+       [BZ #21426]
+       * misc/bits/types/struct_iovec.h: New file.
+       * misc/Makefile (headers): Add bits/types/struct_iovec.h.
+       * include/bits/types/struct_iovec.h: New file.
+       * bits/uio.h (struct iovec): Replace by inclusion of
+       <bits/types/struct_iovec.h>.
+       * sysdeps/unix/sysv/linux/bits/uio.h (struct iovec): Likewise.
+       * socket/sys/socket.h: Include <bits/types/struct_iovec.h> instead
+       of <sys/uio.h>.
+       * nptl/tst-cancel4.c: Include <sys/uio.h>
+       * posix/test-errno.c: Likewise.
+       * support/resolv_test.c: Likewise.
+       * conform/Makefile (test-xfail-POSIX2008/arpa/inet.h/conform):
+       Remove.
+       (test-xfail-POSIX2008/netdb.h/conform): Likewise.
+       (test-xfail-POSIX2008/netinet/in.h/conform): Likewise.
+       (test-xfail-POSIX2008/sys/socket.h/conform): Likewise.
+
        * conform/data/sys/socket.h-data (*_t): Allow.
 
 2017-04-24  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
index def26dfbb6e129faec2e65fbaba0e80f046b3c8e..96a3a71d427f5850a0da44c92d71481ef5ab241d 100644 (file)
 #endif
 
 
-/* `struct iovec' -- Structure describing a section of memory.  */
-
-struct iovec
-{
-  /* Starting address.  */
-  __ptr_t iov_base;
-  /* Length in bytes.  */
-  size_t iov_len;
-};
+#include <bits/types/struct_iovec.h>
index 9638ddaa5a3cd235853e8f29444e63c22f437dd9..19404fdaf8261684497f06ff9101dde2e1ad4a88 100644 (file)
@@ -180,11 +180,7 @@ test-xfail-XOPEN2K/semaphore.h/conform = yes
 test-xfail-XOPEN2K/signal.h/conform = yes
 test-xfail-XOPEN2K/sys/wait.h/conform = yes
 test-xfail-XOPEN2K/ucontext.h/conform = yes
-test-xfail-POSIX2008/arpa/inet.h/conform = yes
-test-xfail-POSIX2008/netdb.h/conform = yes
-test-xfail-POSIX2008/netinet/in.h/conform = yes
 test-xfail-POSIX2008/signal.h/conform = yes
-test-xfail-POSIX2008/sys/socket.h/conform = yes
 test-xfail-POSIX2008/sys/wait.h/conform = yes
 test-xfail-XOPEN2K8/signal.h/conform = yes
 test-xfail-XOPEN2K8/sys/wait.h/conform = yes
diff --git a/include/bits/types/struct_iovec.h b/include/bits/types/struct_iovec.h
new file mode 100644 (file)
index 0000000..116a247
--- /dev/null
@@ -0,0 +1 @@
+#include "../../misc/bits/types/struct_iovec.h"
index ed988c3967243ed614fd3cd1f675fa2d7177e71a..622da676779b5b481c6e81b48ebb801b5ca1d8c6 100644 (file)
@@ -35,7 +35,7 @@ headers       := sys/uio.h bits/uio.h sys/ioctl.h bits/ioctls.h bits/ioctl-types.h \
           syslog.h sys/syslog.h \
           bits/syslog.h bits/syslog-ldbl.h bits/syslog-path.h bits/error.h \
           bits/select2.h bits/hwcap.h sys/auxv.h \
-          sys/sysmacros.h bits/sysmacros.h
+          sys/sysmacros.h bits/sysmacros.h bits/types/struct_iovec.h
 
 routines := brk sbrk sstk ioctl \
            readv writev preadv preadv64 pwritev pwritev64 \
diff --git a/misc/bits/types/struct_iovec.h b/misc/bits/types/struct_iovec.h
new file mode 100644 (file)
index 0000000..bd625a3
--- /dev/null
@@ -0,0 +1,32 @@
+/* Define struct iovec.
+   Copyright (C) 1996-2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#ifndef __iovec_defined
+#define __iovec_defined 1
+
+#define __need_size_t
+#include <stddef.h>
+
+/* Structure for scatter/gather I/O.  */
+struct iovec
+  {
+    void *iov_base;    /* Pointer to data.  */
+    size_t iov_len;    /* Length of data.  */
+  };
+
+#endif
index a68a3efb682cf83f8085d4b2cb670dbb06c11f1e..590ce0ab5d001691add1dcf2ec632bfd44b89b9e 100644 (file)
@@ -38,6 +38,7 @@
 #include <sys/poll.h>
 #include <sys/wait.h>
 #include <sys/stat.h>
+#include <sys/uio.h>
 
 
 /* Since STREAMS are not supported in the standard Linux kernel and
index c2bfd8a80f67541d443a3e18a723f842a8719538..6aa297f8376aadd864bf5ffcc4fa380ee69b0815 100644 (file)
@@ -31,6 +31,7 @@
 #include <sys/types.h>
 #include <sys/statfs.h>
 #include <sys/mman.h>
+#include <sys/uio.h>
 #include <unistd.h>
 #include <netinet/in.h>
 
index 609a08d7568cfe1ebaf62bb5643250c4f83a541e..7af41097bb4bd09f39fb3c91893680e1bff93ef0 100644 (file)
@@ -23,7 +23,7 @@
 
 __BEGIN_DECLS
 
-#include <sys/uio.h>
+#include <bits/types/struct_iovec.h>
 #define        __need_size_t
 #include <stddef.h>
 #ifdef __USE_GNU
index 5c5a46353d5692a011077b8574d6dd8bd4bb1e90..050cd7154bfcb9567ef3a3f43f5ea1b2ab483476 100644 (file)
@@ -33,6 +33,7 @@
 #include <support/xsocket.h>
 #include <support/xthread.h>
 #include <support/xunistd.h>
+#include <sys/uio.h>
 #include <unistd.h>
 
 /* Response builder.  */
index 065a5d500a21e14a30d14e84bc45d2eb9d358a5f..1583f0455b6f36f97abbe9824a4ebdab22ce357c 100644 (file)
 #define UIO_MAXIOV     1024
 
 
-/* Structure for scatter/gather I/O.  */
-struct iovec
-  {
-    void *iov_base;    /* Pointer to data.  */
-    size_t iov_len;    /* Length of data.  */
-  };
+#include <bits/types/struct_iovec.h>
 
 #endif