about summary refs log tree commit diff
path: root/resolv/tst-resolv-res_init-skeleton.c
diff options
context:
space:
mode:
authorFlorian Weimer <fweimer@redhat.com>2017-07-04 14:47:29 +0200
committerFlorian Weimer <fweimer@redhat.com>2017-07-04 15:26:05 +0200
commit4446a885f3aeb3a33b95c72bae1f115bed77f0cb (patch)
treecb00db2c2f0dddc2898640dd46331876e72b6171 /resolv/tst-resolv-res_init-skeleton.c
parentf0107724c92eefbc0637e2a7e142adf57e87e30b (diff)
downloadglibc-4446a885f3aeb3a33b95c72bae1f115bed77f0cb.tar.gz
glibc-4446a885f3aeb3a33b95c72bae1f115bed77f0cb.tar.xz
glibc-4446a885f3aeb3a33b95c72bae1f115bed77f0cb.zip
resolv: Fix resolv_conf _res matching
A dot-less host name without an /etc/resolv.conf file caused an
assertion failure in update_from_conf because the function would not
deal correctly with the empty search list case.

Thanks to Andreas Schwab for debugging assistence.
Diffstat (limited to 'resolv/tst-resolv-res_init-skeleton.c')
-rw-r--r--resolv/tst-resolv-res_init-skeleton.c31
1 files changed, 29 insertions, 2 deletions
diff --git a/resolv/tst-resolv-res_init-skeleton.c b/resolv/tst-resolv-res_init-skeleton.c
index 9e496a3212..8f395d8ce9 100644
--- a/resolv/tst-resolv-res_init-skeleton.c
+++ b/resolv/tst-resolv-res_init-skeleton.c
@@ -307,6 +307,10 @@ struct test_case
   /* Setting for the RES_OPTIONS environment variable.  NULL if the
      variable is not to be set.  */
   const char *res_options;
+
+  /* Override the system host name.  NULL means that no change is made
+     and the default is used (test_hostname).  */
+  const char *hostname;
 };
 
 enum test_init
@@ -358,6 +362,14 @@ run_res_init (void *closure)
     setenv ("LOCALDOMAIN", ctx->t->localdomain, 1);
   if (ctx->t->res_options != NULL)
     setenv ("RES_OPTIONS", ctx->t->res_options, 1);
+  if (ctx->t->hostname != NULL)
+    {
+      /* This test needs its own namespace, to avoid changing the host
+         name for the parent, too.  */
+      TEST_VERIFY_EXIT (unshare (CLONE_NEWUTS) == 0);
+      if (sethostname (ctx->t->hostname, strlen (ctx->t->hostname)) != 0)
+        FAIL_EXIT1 ("sethostname (\"%s\"): %m", ctx->t->hostname);
+    }
 
   switch (ctx->init)
     {
@@ -434,6 +446,12 @@ struct test_case test_cases[] =
      "nameserver 127.0.0.1\n"
      "; nameserver[0]: [127.0.0.1]:53\n"
     },
+    {.name = "empty file, no-dot hostname",
+     .conf = "",
+     .expected = "nameserver 127.0.0.1\n"
+     "; nameserver[0]: [127.0.0.1]:53\n",
+     .hostname = "example",
+    },
     {.name = "empty file with LOCALDOMAIN",
      .conf = "",
      .expected = "search example.net\n"
@@ -462,8 +480,7 @@ struct test_case test_cases[] =
      .res_options = "edns0 attempts:5",
     },
     {.name = "basic",
-     .conf = "domain example.net\n"
-     "search corp.example.com example.com\n"
+     .conf =  "search corp.example.com example.com\n"
      "nameserver 192.0.2.1\n",
      .expected = "search corp.example.com example.com\n"
      "; search[0]: corp.example.com\n"
@@ -471,6 +488,16 @@ struct test_case test_cases[] =
      "nameserver 192.0.2.1\n"
      "; nameserver[0]: [192.0.2.1]:53\n"
     },
+    {.name = "basic with no-dot hostname",
+     .conf = "search corp.example.com example.com\n"
+     "nameserver 192.0.2.1\n",
+     .expected = "search corp.example.com example.com\n"
+     "; search[0]: corp.example.com\n"
+     "; search[1]: example.com\n"
+     "nameserver 192.0.2.1\n"
+     "; nameserver[0]: [192.0.2.1]:53\n",
+     .hostname = "example",
+    },
     {.name = "basic no-reload",
      .conf = "options no-reload\n"
      "search corp.example.com example.com\n"