about summary refs log tree commit diff
path: root/resolv/resolv_conf.c
diff options
context:
space:
mode:
authorFlorian Weimer <fweimer@redhat.com>2017-07-04 11:18:34 +0200
committerFlorian Weimer <fweimer@redhat.com>2017-07-04 11:18:34 +0200
commit89f6307c5d270ed4f11cee373031fa9f2222f2b9 (patch)
tree36ff15d6ad1d7ffe766754d3be10ffd0ae04777f /resolv/resolv_conf.c
parente237357a5a0559dee92261f1914d1fa2cd43a1a8 (diff)
downloadglibc-89f6307c5d270ed4f11cee373031fa9f2222f2b9.tar.gz
glibc-89f6307c5d270ed4f11cee373031fa9f2222f2b9.tar.xz
glibc-89f6307c5d270ed4f11cee373031fa9f2222f2b9.zip
resolv: Fix improper assert in __resolv_conf_attach
Diffstat (limited to 'resolv/resolv_conf.c')
-rw-r--r--resolv/resolv_conf.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/resolv/resolv_conf.c b/resolv/resolv_conf.c
index b98cf92890..0ed36cde02 100644
--- a/resolv/resolv_conf.c
+++ b/resolv/resolv_conf.c
@@ -58,8 +58,10 @@ struct resolv_conf_global
      the array element is overwritten with NULL.  */
   struct resolv_conf_array array;
 
-  /* Start of the free list in the array.  The MSB is set if this
-     field has been initialized.  */
+  /* Start of the free list in the array.  Zero if the free list is
+     empty.  Otherwise, free_list_start >> 1 is the first element of
+     the free list (and the free list entries all have their LSB set
+     and are shifted one to the left).  */
   uintptr_t free_list_start;
 
   /* Cached current configuration object for /etc/resolv.conf.  */
@@ -567,11 +569,7 @@ decrement_at_index (struct resolv_conf_global *global_copy, size_t index)
           struct resolv_conf *conf = (struct resolv_conf *) *slot;
           conf_decrement (conf);
           /* Put the slot onto the free list.  */
-          if (global_copy->free_list_start == 0)
-            /* Not yet initialized.  */
-            *slot = 1;
-          else
-            *slot = global_copy->free_list_start;
+          *slot = global_copy->free_list_start;
           global_copy->free_list_start = (index << 1) | 1;
         }
     }
@@ -598,7 +596,8 @@ __resolv_conf_attach (struct __res_state *resp, struct resolv_conf *conf)
         index = global_copy->free_list_start >> 1;
         uintptr_t *slot = resolv_conf_array_at (&global_copy->array, index);
         global_copy->free_list_start = *slot;
-        assert (global_copy->free_list_start & 1);
+        assert (global_copy->free_list_start == 0
+                || global_copy->free_list_start & 1);
         /* Install the configuration pointer.  */
         *slot = (uintptr_t) conf;
       }