summaryrefslogtreecommitdiffstats
path: root/src/providers
diff options
context:
space:
mode:
authorSumit Bose <sbose@redhat.com>2016-11-04 17:13:30 +0100
committerJakub Hrozek <jhrozek@redhat.com>2017-02-22 12:30:10 +0100
commit08bf6b4a281ef4308119dccbba4e86cf28b505d2 (patch)
treeb1e7805b6cceb947190ebc130617e47362edc139 /src/providers
parentd694d4fdcc81f24c2f9e3bb5a0dbe0a52498f196 (diff)
downloadsssd-08bf6b4a281ef4308119dccbba4e86cf28b505d2.tar.gz
sssd-08bf6b4a281ef4308119dccbba4e86cf28b505d2.tar.xz
sssd-08bf6b4a281ef4308119dccbba4e86cf28b505d2.zip
sdap_extend_map: make sure memory can be freed
If there is an error after calling talloc_realloc() the caller cannot free the memory properly because neither src_map nor _map were pointing to a valid memory location. With this patch _map will always point to the current valid location so that it can always be used with talloc_free(). Reviewed-by: Petr Cech <pcech@redhat.com>
Diffstat (limited to 'src/providers')
-rw-r--r--src/providers/ldap/sdap.c4
-rw-r--r--src/providers/ldap/sdap.h21
2 files changed, 23 insertions, 2 deletions
diff --git a/src/providers/ldap/sdap.c b/src/providers/ldap/sdap.c
index bfb7fc6d2..342667aae 100644
--- a/src/providers/ldap/sdap.c
+++ b/src/providers/ldap/sdap.c
@@ -162,9 +162,9 @@ int sdap_extend_map(TALLOC_CTX *memctx,
char *sysdb_attr;
errno_t ret;
+ *_map = src_map;
if (extra_attrs == NULL) {
DEBUG(SSSDBG_FUNC_DATA, "No extra attributes\n");
- *_map = src_map;
*_new_size = num_entries;
return EOK;
}
@@ -177,6 +177,7 @@ int sdap_extend_map(TALLOC_CTX *memctx,
if (map == NULL) {
return ENOMEM;
}
+ *_map = map;
for (i = 0; *extra_attrs != NULL; extra_attrs++) {
ret = split_extra_attr(map, *extra_attrs, &sysdb_attr, &ldap_attr);
@@ -221,7 +222,6 @@ int sdap_extend_map(TALLOC_CTX *memctx,
/* Sentinel */
memset(&map[num_entries+nextra], 0, sizeof(struct sdap_attr_map));
- *_map = map;
*_new_size = num_entries + nextra;
return EOK;
}
diff --git a/src/providers/ldap/sdap.h b/src/providers/ldap/sdap.h
index 6d4543ed4..6079a8bf6 100644
--- a/src/providers/ldap/sdap.h
+++ b/src/providers/ldap/sdap.h
@@ -512,6 +512,27 @@ int sdap_copy_map(TALLOC_CTX *memctx,
int num_entries,
struct sdap_attr_map **_map);
+/**
+ * @brief Add attributes to a map
+ *
+ * sdap_extend_map() will call talloc_realloc() on the second argument so the
+ * original storage location might change. The return value _map will always
+ * contain the current memory location which can be used with talloc_free()
+ * even if there is an error.
+ *
+ * @param[in] memctx Talloc memory context
+ * @param[in] src_map Original map, should not be accessed anymore
+ * @param[in] num_entries Number of entries in the original map
+ * @param[in] extra_attrs NULL-terminated array of extra attribute pairs
+ * sysdb_attr:ldap_attr
+ * @param[out] _map New map
+ * @param[out] _new_size Number of entries in the new map
+ *
+ * @return
+ * - EOK success
+ * - ENOMEM memory allocation failed
+ * - ERR_DUP_EXTRA_ATTR sysdb attribute is already used
+ */
int sdap_extend_map(TALLOC_CTX *memctx,
struct sdap_attr_map *src_map,
size_t num_entries,