[3/3] Add tests for bz 32573, 32575

Message ID gfcki2zlnhes2lusplcovup3ns4tgwwfgcyxhohfecj5nts3ym@pbg5rgnq6lsz (mailing list archive)
State Superseded
Delegated to: Adhemerval Zanella Netto
Headers
Series [1/3] Check octets more often in inet_network (bz 32575) |

Checks

Context Check Description
redhat-pt-bot/TryBot-apply_patch success Patch applied to master at the time it was sent
linaro-tcwg-bot/tcwg_glibc_build--master-aarch64 success Build passed
redhat-pt-bot/TryBot-32bit success Build for i686
linaro-tcwg-bot/tcwg_glibc_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_glibc_check--master-aarch64 success Test passed
linaro-tcwg-bot/tcwg_glibc_check--master-arm success Test passed

Commit Message

Tobias Stoeckmann Jan. 19, 2025, 3:05 p.m. UTC
  Check validity of /etc/networks parser.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
---
 nss/Makefile                |  1 +
 nss/tst-nss-files-network.c | 66 +++++++++++++++++++++++++++++++++++++
 support/namespace.h         |  2 ++
 support/support_chroot.c    |  2 ++
 4 files changed, 71 insertions(+)
 create mode 100644 nss/tst-nss-files-network.c

--
2.48.1
  

Comments

Adhemerval Zanella Netto Feb. 4, 2025, 2:29 p.m. UTC | #1
On 19/01/25 12:05, Tobias Stoeckmann wrote:
> Check validity of /etc/networks parser.
> 
> Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
> ---
>  nss/Makefile                |  1 +
>  nss/tst-nss-files-network.c | 66 +++++++++++++++++++++++++++++++++++++
>  support/namespace.h         |  2 ++
>  support/support_chroot.c    |  2 ++
>  4 files changed, 71 insertions(+)
>  create mode 100644 nss/tst-nss-files-network.c
> 
> diff --git a/nss/Makefile b/nss/Makefile
> index 3ee51f309e..09ce94aae7 100644
> --- a/nss/Makefile
> +++ b/nss/Makefile
> @@ -367,6 +367,7 @@ tests += tst-nss-files-hosts-multi
>  tests += tst-nss-files-hosts-getent
>  tests += tst-nss-files-alias-leak
>  tests += tst-nss-files-alias-truncated
> +tests += tst-nss-files-network

Ok.

>  # tst_fgetgrent currently only works with shared libraries
>  test-srcs :=  tst_fgetgrent
>  ifeq ($(run-built-tests),yes)
> diff --git a/nss/tst-nss-files-network.c b/nss/tst-nss-files-network.c
> new file mode 100644
> index 0000000000..c298c0b732
> --- /dev/null
> +++ b/nss/tst-nss-files-network.c
> @@ -0,0 +1,66 @@
> +/* Check handling of long and truncated numbers in /etc/networks (bug 24059).

I think it should reference the 32573/32575.

> +   Copyright (C) 2025 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
> +   <https://www.gnu.org/licenses/>.  */
> +
> +#include <netdb.h>
> +#include <gnu/lib-names.h>
> +#include <nss.h>
> +#include <stddef.h>
> +#include <support/check.h>
> +#include <support/check_nss.h>
> +#include <support/namespace.h>
> +#include <support/test-driver.h>
> +#include <support/xdlfcn.h>
> +#include <support/xunistd.h>
> +
> +struct support_chroot *chroot_env;
> +
> +static void
> +prepare (int argc, char **argv)
> +{
> +  chroot_env = support_chroot_create
> +    ((struct support_chroot_configuration)
> +     {
> +       .networks = "net1 x0000000000Ff.077\n" /* legal 255.63.0.0 */
> +        "net2 xFF00000000.0.0.0\n" /* illegal */
> +     });
> +

Could you also add an entry similar to the one used on BZ#32573 that triggers
the stack overflow? Maybe it can tune down the stack limit with setrlimit to
require a smaller entry.

> +}
> +
> +static int
> +do_test (void)
> +{
> +  support_become_root ();
> +  if (!support_can_chroot ())
> +    return EXIT_UNSUPPORTED;
> +
> +  __nss_configure_lookup ("networks", "files");
> +  xdlopen (LIBNSS_FILES_SO, RTLD_NOW);
> +
> +  xchroot (chroot_env->path_chroot);
> +
> +  check_netent ("net1", getnetbyname ("net1"),
> +    "name: net1\n"
> +    "net: 0xff3f0000\n");
> +  check_netent ("net2", getnetbyname ("net2"), "error: HOST_NOT_FOUND\n");
> +
> +  support_chroot_free (chroot_env);
> +  return 0;
> +}
> +
> +#define PREPARE prepare
> +#include <support/test-driver.c>
> diff --git a/support/namespace.h b/support/namespace.h
> index 456157a4e0..6b9b226f95 100644
> --- a/support/namespace.h
> +++ b/support/namespace.h
> @@ -75,6 +75,7 @@ struct support_chroot_configuration
>    const char *hosts;            /* /etc/hosts.  */
>    const char *host_conf;        /* /etc/host.conf.  */
>    const char *aliases;          /* /etc/aliases.  */
> +  const char *networks;         /* /etc/networks.  */
>  };
> 
>  /* The result of the creation of a chroot.  */
> @@ -92,6 +93,7 @@ struct support_chroot
>    char *path_hosts;             /* /etc/hosts.  */
>    char *path_host_conf;         /* /etc/host.conf.  */
>    char *path_aliases;           /* /etc/aliases.  */
> +  char *path_networks;          /* /etc/networks.  */
>  };
> 
>  /* Create a chroot environment.  The returned data should be freed
> diff --git a/support/support_chroot.c b/support/support_chroot.c
> index 2637dd1522..92c2a453aa 100644
> --- a/support/support_chroot.c
> +++ b/support/support_chroot.c
> @@ -57,6 +57,7 @@ support_chroot_create (struct support_chroot_configuration conf)
>    write_file (path_etc, "hosts", conf.hosts, &chroot->path_hosts);
>    write_file (path_etc, "host.conf", conf.host_conf, &chroot->path_host_conf);
>    write_file (path_etc, "aliases", conf.aliases, &chroot->path_aliases);
> +  write_file (path_etc, "networks", conf.networks, &chroot->path_networks);
> 
>    free (path_etc);
> 
> @@ -79,5 +80,6 @@ support_chroot_free (struct support_chroot *chroot)
>    free (chroot->path_hosts);
>    free (chroot->path_host_conf);
>    free (chroot->path_aliases);
> +  free (chroot->path_networks);
>    free (chroot);
>  }
> --
> 2.48.1
>
  
Tobias Stoeckmann Feb. 4, 2025, 5:25 p.m. UTC | #2
Check validity of /etc/networks parser.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
---
On Tue, Feb 04, 2025 at 11:29:26AM -0300, Adhemerval Zanella Netto wrote:
> > +/* Check handling of long and truncated numbers in /etc/networks (bug 24059).
>
> I think it should reference the 32573/32575.

Yes, thanks. Fixed.

> Could you also add an entry similar to the one used on BZ#32573 that triggers
> the stack overflow? Maybe it can tune down the stack limit with setrlimit to
> require a smaller entry.

I have added a test, based on the stack limit idea in math/test-nan-overflow.c.

I am totally fine if the commits are squashed. Should I do so?
---
 nss/Makefile                |  1 +
 nss/tst-nss-files-network.c | 96 +++++++++++++++++++++++++++++++++++++
 support/namespace.h         |  2 +
 support/support_chroot.c    |  2 +
 4 files changed, 101 insertions(+)
 create mode 100644 nss/tst-nss-files-network.c

diff --git a/nss/Makefile b/nss/Makefile
index 3ee51f309e..09ce94aae7 100644
--- a/nss/Makefile
+++ b/nss/Makefile
@@ -367,6 +367,7 @@ tests += tst-nss-files-hosts-multi
 tests += tst-nss-files-hosts-getent
 tests += tst-nss-files-alias-leak
 tests += tst-nss-files-alias-truncated
+tests += tst-nss-files-network
 # tst_fgetgrent currently only works with shared libraries
 test-srcs :=  tst_fgetgrent
 ifeq ($(run-built-tests),yes)
diff --git a/nss/tst-nss-files-network.c b/nss/tst-nss-files-network.c
new file mode 100644
index 0000000000..5aa0cd1db2
--- /dev/null
+++ b/nss/tst-nss-files-network.c
@@ -0,0 +1,96 @@
+/* Test long entries and truncated numbers in /etc/networks (bug 32573/32575).
+   Copyright (C) 2025 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
+   <https://www.gnu.org/licenses/>.  */
+
+#include <netdb.h>
+#include <gnu/lib-names.h>
+#include <nss.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <support/check.h>
+#include <support/check_nss.h>
+#include <support/namespace.h>
+#include <support/test-driver.h>
+#include <support/xdlfcn.h>
+#include <support/xunistd.h>
+#include <sys/resource.h>
+
+#define STACK_LIM 1048576
+#define STRING_SIZE (2 * STACK_LIM)
+
+struct support_chroot *chroot_env;
+
+static void
+prepare (int argc, char **argv)
+{
+  int ret;
+  char *content;
+  char *entry = malloc (STRING_SIZE);
+  struct rlimit lim;
+  getrlimit (RLIMIT_STACK, &lim);
+  lim.rlim_cur = STACK_LIM;
+  setrlimit (RLIMIT_STACK, &lim);
+  if (entry == NULL)
+    {
+      puts ("malloc failed, cannot test");
+      exit (1);
+    }
+  memset (entry, 'A', STRING_SIZE);
+  entry[STRING_SIZE - 1] = 0;
+  ret = asprintf (&content, "%s\n%s\nnet3 %s\n",
+    "net1 x0000000000Ff.077", /* legal 255.63.0.0 */
+    "net2 xFF00000000.0.0.0", /* illegal */
+    entry /* illegal */);
+  if (ret == -1)
+    {
+      puts ("asprintf failed, cannot test");
+      exit (1);
+    }
+  free (entry);
+  chroot_env = support_chroot_create
+    ((struct support_chroot_configuration)
+     {
+       .networks = content
+     });
+
+}
+
+static int
+do_test (void)
+{
+  support_become_root ();
+  if (!support_can_chroot ())
+    return EXIT_UNSUPPORTED;
+
+  __nss_configure_lookup ("networks", "files");
+  xdlopen (LIBNSS_FILES_SO, RTLD_NOW);
+
+  xchroot (chroot_env->path_chroot);
+
+  check_netent ("net1", getnetbyname ("net1"),
+    "name: net1\n"
+    "net: 0xff3f0000\n");
+  check_netent ("net2", getnetbyname ("net2"), "error: HOST_NOT_FOUND\n");
+
+  support_chroot_free (chroot_env);
+  return 0;
+}
+
+#define PREPARE prepare
+#include <support/test-driver.c>
diff --git a/support/namespace.h b/support/namespace.h
index 456157a4e0..6b9b226f95 100644
--- a/support/namespace.h
+++ b/support/namespace.h
@@ -75,6 +75,7 @@ struct support_chroot_configuration
   const char *hosts;            /* /etc/hosts.  */
   const char *host_conf;        /* /etc/host.conf.  */
   const char *aliases;          /* /etc/aliases.  */
+  const char *networks;         /* /etc/networks.  */
 };

 /* The result of the creation of a chroot.  */
@@ -92,6 +93,7 @@ struct support_chroot
   char *path_hosts;             /* /etc/hosts.  */
   char *path_host_conf;         /* /etc/host.conf.  */
   char *path_aliases;           /* /etc/aliases.  */
+  char *path_networks;          /* /etc/networks.  */
 };

 /* Create a chroot environment.  The returned data should be freed
diff --git a/support/support_chroot.c b/support/support_chroot.c
index 2637dd1522..92c2a453aa 100644
--- a/support/support_chroot.c
+++ b/support/support_chroot.c
@@ -57,6 +57,7 @@ support_chroot_create (struct support_chroot_configuration conf)
   write_file (path_etc, "hosts", conf.hosts, &chroot->path_hosts);
   write_file (path_etc, "host.conf", conf.host_conf, &chroot->path_host_conf);
   write_file (path_etc, "aliases", conf.aliases, &chroot->path_aliases);
+  write_file (path_etc, "networks", conf.networks, &chroot->path_networks);

   free (path_etc);

@@ -79,5 +80,6 @@ support_chroot_free (struct support_chroot *chroot)
   free (chroot->path_hosts);
   free (chroot->path_host_conf);
   free (chroot->path_aliases);
+  free (chroot->path_networks);
   free (chroot);
 }
--
2.48.1
  
Adhemerval Zanella Netto Feb. 11, 2025, 6:05 p.m. UTC | #3
On 04/02/25 14:25, Tobias Stoeckmann wrote:
> Check validity of /etc/networks parser.
> 
> Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
> ---
> On Tue, Feb 04, 2025 at 11:29:26AM -0300, Adhemerval Zanella Netto wrote:
>>> +/* Check handling of long and truncated numbers in /etc/networks (bug 24059).
>>
>> I think it should reference the 32573/32575.
> 
> Yes, thanks. Fixed.
> 
>> Could you also add an entry similar to the one used on BZ#32573 that triggers
>> the stack overflow? Maybe it can tune down the stack limit with setrlimit to
>> require a smaller entry.
> 
> I have added a test, based on the stack limit idea in math/test-nan-overflow.c.
> 
> I am totally fine if the commits are squashed. Should I do so?

LGTM, thanks.  Could you send a proper patch with a title and the
commit message, so I can pull from patchwork and apply?

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>

> ---
>  nss/Makefile                |  1 +
>  nss/tst-nss-files-network.c | 96 +++++++++++++++++++++++++++++++++++++
>  support/namespace.h         |  2 +
>  support/support_chroot.c    |  2 +
>  4 files changed, 101 insertions(+)
>  create mode 100644 nss/tst-nss-files-network.c
> 
> diff --git a/nss/Makefile b/nss/Makefile
> index 3ee51f309e..09ce94aae7 100644
> --- a/nss/Makefile
> +++ b/nss/Makefile
> @@ -367,6 +367,7 @@ tests += tst-nss-files-hosts-multi
>  tests += tst-nss-files-hosts-getent
>  tests += tst-nss-files-alias-leak
>  tests += tst-nss-files-alias-truncated
> +tests += tst-nss-files-network
>  # tst_fgetgrent currently only works with shared libraries
>  test-srcs :=  tst_fgetgrent
>  ifeq ($(run-built-tests),yes)
> diff --git a/nss/tst-nss-files-network.c b/nss/tst-nss-files-network.c
> new file mode 100644
> index 0000000000..5aa0cd1db2
> --- /dev/null
> +++ b/nss/tst-nss-files-network.c
> @@ -0,0 +1,96 @@
> +/* Test long entries and truncated numbers in /etc/networks (bug 32573/32575).
> +   Copyright (C) 2025 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
> +   <https://www.gnu.org/licenses/>.  */
> +
> +#include <netdb.h>
> +#include <gnu/lib-names.h>
> +#include <nss.h>
> +#include <stddef.h>
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <string.h>
> +#include <support/check.h>
> +#include <support/check_nss.h>
> +#include <support/namespace.h>
> +#include <support/test-driver.h>
> +#include <support/xdlfcn.h>
> +#include <support/xunistd.h>
> +#include <sys/resource.h>
> +
> +#define STACK_LIM 1048576
> +#define STRING_SIZE (2 * STACK_LIM)
> +
> +struct support_chroot *chroot_env;
> +
> +static void
> +prepare (int argc, char **argv)
> +{
> +  int ret;
> +  char *content;
> +  char *entry = malloc (STRING_SIZE);
> +  struct rlimit lim;
> +  getrlimit (RLIMIT_STACK, &lim);
> +  lim.rlim_cur = STACK_LIM;
> +  setrlimit (RLIMIT_STACK, &lim);
> +  if (entry == NULL)
> +    {
> +      puts ("malloc failed, cannot test");
> +      exit (1);
> +    }
> +  memset (entry, 'A', STRING_SIZE);
> +  entry[STRING_SIZE - 1] = 0;
> +  ret = asprintf (&content, "%s\n%s\nnet3 %s\n",
> +    "net1 x0000000000Ff.077", /* legal 255.63.0.0 */
> +    "net2 xFF00000000.0.0.0", /* illegal */
> +    entry /* illegal */);
> +  if (ret == -1)
> +    {
> +      puts ("asprintf failed, cannot test");
> +      exit (1);
> +    }
> +  free (entry);
> +  chroot_env = support_chroot_create
> +    ((struct support_chroot_configuration)
> +     {
> +       .networks = content
> +     });
> +
> +}
> +
> +static int
> +do_test (void)
> +{
> +  support_become_root ();
> +  if (!support_can_chroot ())
> +    return EXIT_UNSUPPORTED;
> +
> +  __nss_configure_lookup ("networks", "files");
> +  xdlopen (LIBNSS_FILES_SO, RTLD_NOW);
> +
> +  xchroot (chroot_env->path_chroot);
> +
> +  check_netent ("net1", getnetbyname ("net1"),
> +    "name: net1\n"
> +    "net: 0xff3f0000\n");
> +  check_netent ("net2", getnetbyname ("net2"), "error: HOST_NOT_FOUND\n");
> +
> +  support_chroot_free (chroot_env);
> +  return 0;
> +}
> +
> +#define PREPARE prepare
> +#include <support/test-driver.c>
> diff --git a/support/namespace.h b/support/namespace.h
> index 456157a4e0..6b9b226f95 100644
> --- a/support/namespace.h
> +++ b/support/namespace.h
> @@ -75,6 +75,7 @@ struct support_chroot_configuration
>    const char *hosts;            /* /etc/hosts.  */
>    const char *host_conf;        /* /etc/host.conf.  */
>    const char *aliases;          /* /etc/aliases.  */
> +  const char *networks;         /* /etc/networks.  */
>  };
> 
>  /* The result of the creation of a chroot.  */
> @@ -92,6 +93,7 @@ struct support_chroot
>    char *path_hosts;             /* /etc/hosts.  */
>    char *path_host_conf;         /* /etc/host.conf.  */
>    char *path_aliases;           /* /etc/aliases.  */
> +  char *path_networks;          /* /etc/networks.  */
>  };
> 
>  /* Create a chroot environment.  The returned data should be freed
> diff --git a/support/support_chroot.c b/support/support_chroot.c
> index 2637dd1522..92c2a453aa 100644
> --- a/support/support_chroot.c
> +++ b/support/support_chroot.c
> @@ -57,6 +57,7 @@ support_chroot_create (struct support_chroot_configuration conf)
>    write_file (path_etc, "hosts", conf.hosts, &chroot->path_hosts);
>    write_file (path_etc, "host.conf", conf.host_conf, &chroot->path_host_conf);
>    write_file (path_etc, "aliases", conf.aliases, &chroot->path_aliases);
> +  write_file (path_etc, "networks", conf.networks, &chroot->path_networks);
> 
>    free (path_etc);
> 
> @@ -79,5 +80,6 @@ support_chroot_free (struct support_chroot *chroot)
>    free (chroot->path_hosts);
>    free (chroot->path_host_conf);
>    free (chroot->path_aliases);
> +  free (chroot->path_networks);
>    free (chroot);
>  }
> --
> 2.48.1
>
  

Patch

diff --git a/nss/Makefile b/nss/Makefile
index 3ee51f309e..09ce94aae7 100644
--- a/nss/Makefile
+++ b/nss/Makefile
@@ -367,6 +367,7 @@  tests += tst-nss-files-hosts-multi
 tests += tst-nss-files-hosts-getent
 tests += tst-nss-files-alias-leak
 tests += tst-nss-files-alias-truncated
+tests += tst-nss-files-network
 # tst_fgetgrent currently only works with shared libraries
 test-srcs :=  tst_fgetgrent
 ifeq ($(run-built-tests),yes)
diff --git a/nss/tst-nss-files-network.c b/nss/tst-nss-files-network.c
new file mode 100644
index 0000000000..c298c0b732
--- /dev/null
+++ b/nss/tst-nss-files-network.c
@@ -0,0 +1,66 @@ 
+/* Check handling of long and truncated numbers in /etc/networks (bug 24059).
+   Copyright (C) 2025 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
+   <https://www.gnu.org/licenses/>.  */
+
+#include <netdb.h>
+#include <gnu/lib-names.h>
+#include <nss.h>
+#include <stddef.h>
+#include <support/check.h>
+#include <support/check_nss.h>
+#include <support/namespace.h>
+#include <support/test-driver.h>
+#include <support/xdlfcn.h>
+#include <support/xunistd.h>
+
+struct support_chroot *chroot_env;
+
+static void
+prepare (int argc, char **argv)
+{
+  chroot_env = support_chroot_create
+    ((struct support_chroot_configuration)
+     {
+       .networks = "net1 x0000000000Ff.077\n" /* legal 255.63.0.0 */
+        "net2 xFF00000000.0.0.0\n" /* illegal */
+     });
+
+}
+
+static int
+do_test (void)
+{
+  support_become_root ();
+  if (!support_can_chroot ())
+    return EXIT_UNSUPPORTED;
+
+  __nss_configure_lookup ("networks", "files");
+  xdlopen (LIBNSS_FILES_SO, RTLD_NOW);
+
+  xchroot (chroot_env->path_chroot);
+
+  check_netent ("net1", getnetbyname ("net1"),
+    "name: net1\n"
+    "net: 0xff3f0000\n");
+  check_netent ("net2", getnetbyname ("net2"), "error: HOST_NOT_FOUND\n");
+
+  support_chroot_free (chroot_env);
+  return 0;
+}
+
+#define PREPARE prepare
+#include <support/test-driver.c>
diff --git a/support/namespace.h b/support/namespace.h
index 456157a4e0..6b9b226f95 100644
--- a/support/namespace.h
+++ b/support/namespace.h
@@ -75,6 +75,7 @@  struct support_chroot_configuration
   const char *hosts;            /* /etc/hosts.  */
   const char *host_conf;        /* /etc/host.conf.  */
   const char *aliases;          /* /etc/aliases.  */
+  const char *networks;         /* /etc/networks.  */
 };

 /* The result of the creation of a chroot.  */
@@ -92,6 +93,7 @@  struct support_chroot
   char *path_hosts;             /* /etc/hosts.  */
   char *path_host_conf;         /* /etc/host.conf.  */
   char *path_aliases;           /* /etc/aliases.  */
+  char *path_networks;          /* /etc/networks.  */
 };

 /* Create a chroot environment.  The returned data should be freed
diff --git a/support/support_chroot.c b/support/support_chroot.c
index 2637dd1522..92c2a453aa 100644
--- a/support/support_chroot.c
+++ b/support/support_chroot.c
@@ -57,6 +57,7 @@  support_chroot_create (struct support_chroot_configuration conf)
   write_file (path_etc, "hosts", conf.hosts, &chroot->path_hosts);
   write_file (path_etc, "host.conf", conf.host_conf, &chroot->path_host_conf);
   write_file (path_etc, "aliases", conf.aliases, &chroot->path_aliases);
+  write_file (path_etc, "networks", conf.networks, &chroot->path_networks);

   free (path_etc);

@@ -79,5 +80,6 @@  support_chroot_free (struct support_chroot *chroot)
   free (chroot->path_hosts);
   free (chroot->path_host_conf);
   free (chroot->path_aliases);
+  free (chroot->path_networks);
   free (chroot);
 }