lib/ldb: Use better variable names in ldb_unpack_only_attr_list
authorAdrian Cochrane <adrianc@catalyst.net.nz>
Tue, 1 Sep 2015 01:27:52 +0000 (13:27 +1200)
committerAndrew Bartlett <abartlet@samba.org>
Thu, 17 Dec 2015 02:23:20 +0000 (03:23 +0100)
BUG: https://bugzilla.samba.org/show_bug.cgi?id=11602
Signed-off-by: Adrian Cochrane <adrianc@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Garming Sam <garming@catalyst.net.nz>
lib/ldb/common/ldb_pack.c

index 50bf9b80eeae50d968d4327fc118288823ea0a6b..946e8d7f9e8151bfe0cf37d76da7bb95475e8f0d 100644 (file)
@@ -260,18 +260,23 @@ int ldb_unpack_data_only_attr_list(struct ldb_context *ldb,
 
        for (i=0;i<message->num_elements;i++) {
                const char *attr = NULL;
+               size_t attr_len;
                struct ldb_message_element *element = NULL;
 
                if (remaining < 10) {
                        errno = EIO;
                        goto failed;
                }
-               len = strnlen((char *)p, remaining-6);
-               if (len == remaining-6) {
+               /*
+                * With this check, we know that the attribute name at
+                * p is \0 terminated.
+                */
+               attr_len = strnlen((char *)p, remaining-6);
+               if (attr_len == remaining-6) {
                        errno = EIO;
                        goto failed;
                }
-               if (len == 0) {
+               if (attr_len == 0) {
                        errno = EIO;
                        goto failed;
                }
@@ -302,8 +307,8 @@ int ldb_unpack_data_only_attr_list(struct ldb_context *ldb,
                        }
 
                        if (!keep) {
-                               remaining -= len + 1;
-                               p += len + 1;
+                               remaining -= attr_len + 1;
+                               p += attr_len + 1;
                                if (!ldb_consume_element_data(&p, &remaining)) {
                                        errno = EIO;
                                        goto failed;
@@ -312,14 +317,14 @@ int ldb_unpack_data_only_attr_list(struct ldb_context *ldb,
                        }
                }
                element = &message->elements[nelem];
-               element->name = talloc_strndup(message->elements, (char *)p, len);
+               element->name = talloc_strndup(message->elements, (char *)p, attr_len);
                if (element->name == NULL) {
                        errno = ENOMEM;
                        goto failed;
                }
                element->flags = 0;
-               remaining -= len + 1;
-               p += len + 1;
+               remaining -= attr_len + 1;
+               p += attr_len + 1;
                element->num_values = pull_uint32(p, 0);
                element->values = NULL;
                if (element->num_values != 0) {