[SCM] Samba Shared Repository - branch master updated

Jeremy Allison jra at samba.org
Wed Oct 17 20:23:04 UTC 2018


The branch, master has been updated
       via  85ec864 gencache: Remove a redundant check
       via  0817d10 gencache: Remove a redundant check
       via  78b8b91 gencache: Make gencache_pull_timeout return a payload DATA_BLOB
       via  34fe8b1 gencache: Make gencache_pull_timeout a bit more robust
       via  6007c44 gencache: Call string_term_tdb_data() only once
       via  140a0e0 gencache: Swap tests: Do cheapest first
       via  2a29ffc gencache: Avoid counting characters manually
       via  4df055b auth3: Avoid an explicit ZERO_STRUCT
       via  fa1f959 netsamlogon_cache: Improve a DBG message
       via  030a3e5 netsamlogon_cache: Add some error checks
       via  9b6166f netsamlogon_cache: Use "goto fail", save some lines
       via  410ec70 netsamlogon_cache: Fix talloc_stackframe error return leaks
      from  fdb6b86 drs_util: Improve memory usage when joining large DB

https://git.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 85ec8644251eff0174c973747b59043180ac58c7
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Oct 9 21:41:52 2018 +0200

    gencache: Remove a redundant check
    
    tdb_storev itself is robust against overflow due to multiple buffers
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>
    
    Autobuild-User(master): Jeremy Allison <jra at samba.org>
    Autobuild-Date(master): Wed Oct 17 22:22:51 CEST 2018 on sn-devel-144

commit 0817d107a4af2640dbbf28b8316545a007660db8
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Oct 9 14:04:50 2018 +0200

    gencache: Remove a redundant check
    
    gencache_pull_timeout checks for NULL ptr already
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 78b8b9164679d782ed0eb2608961972eb08f73f9
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Oct 9 13:58:43 2018 +0200

    gencache: Make gencache_pull_timeout return a payload DATA_BLOB
    
    Both relevant callers created one anyway.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 34fe8b1ac6a79680fcbb34e9fcad2869d66d88e6
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Oct 9 13:51:46 2018 +0200

    gencache: Make gencache_pull_timeout a bit more robust
    
    The previous version assumed a well-formed "val", we just handed it to
    strtol without properly checking that it contains the delimiter. So
    strtol could well run off the end of "val" in case of data corruption.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 6007c444d946ed7eb7572fed02e448c61f86a394
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Oct 9 13:17:53 2018 +0200

    gencache: Call string_term_tdb_data() only once
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 140a0e053719e1482211d5937c73e6303c2397bd
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Oct 9 13:15:22 2018 +0200

    gencache: Swap tests: Do cheapest first
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 2a29ffc3e0527733217a6f62d1669f60fab6e2ac
Author: Volker Lendecke <vl at samba.org>
Date:   Mon Oct 8 09:07:59 2018 +0200

    gencache: Avoid counting characters manually
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 4df055bbbb231dc77ca698614fd836ba4c113691
Author: Volker Lendecke <vl at samba.org>
Date:   Sat Oct 13 10:41:22 2018 +0200

    auth3: Avoid an explicit ZERO_STRUCT
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit fa1f959321ae3df9a133e4c2b8992e1233337a2e
Author: Volker Lendecke <vl at samba.org>
Date:   Sat Oct 13 10:58:32 2018 +0200

    netsamlogon_cache: Improve a DBG message
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 030a3e506ec8dbe1808609b215f66b5e7e19951b
Author: Volker Lendecke <vl at samba.org>
Date:   Sat Oct 13 10:57:13 2018 +0200

    netsamlogon_cache: Add some error checks
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 9b6166f772c647fc72742e13ecd4c04d002b1d8f
Author: Volker Lendecke <vl at samba.org>
Date:   Sat Oct 13 10:55:00 2018 +0200

    netsamlogon_cache: Use "goto fail", save some lines
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 410ec70bb308980c2f2c5d555a64c44b8b610744
Author: Volker Lendecke <vl at samba.org>
Date:   Sat Oct 13 10:10:52 2018 +0200

    netsamlogon_cache: Fix talloc_stackframe error return leaks
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

-----------------------------------------------------------------------

Summary of changes:
 source3/auth/server_info.c      |  4 +--
 source3/lib/gencache.c          | 69 +++++++++++++++++++++--------------------
 source3/libsmb/samlogon_cache.c | 21 ++++++++-----
 3 files changed, 49 insertions(+), 45 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source3/auth/server_info.c b/source3/auth/server_info.c
index 339cce6..6d5e9fb 100644
--- a/source3/auth/server_info.c
+++ b/source3/auth/server_info.c
@@ -503,7 +503,7 @@ NTSTATUS samu_to_SamInfo3(TALLOC_CTX *mem_ctx,
 	struct netr_SamInfo3 *info3;
 	const struct dom_sid *user_sid;
 	const struct dom_sid *group_sid;
-	struct dom_sid domain_sid;
+	struct dom_sid domain_sid = {0};
 	struct dom_sid *group_sids;
 	uint32_t num_group_sids = 0;
 	const char *tmp;
@@ -523,8 +523,6 @@ NTSTATUS samu_to_SamInfo3(TALLOC_CTX *mem_ctx,
 		return NT_STATUS_NO_MEMORY;
 	}
 
-	ZERO_STRUCT(domain_sid);
-
 	status = SamInfo3_handle_sids(pdb_get_username(samu),
 				user_sid,
 				group_sid,
diff --git a/source3/lib/gencache.c b/source3/lib/gencache.c
index 787ef98..6f7734c 100644
--- a/source3/lib/gencache.c
+++ b/source3/lib/gencache.c
@@ -127,10 +127,12 @@ static bool gencache_init(void)
 
 static TDB_DATA last_stabilize_key(void)
 {
-	TDB_DATA result;
-	result.dptr = discard_const_p(uint8_t, "@LAST_STABILIZED");
-	result.dsize = 17;
-	return result;
+	const char key[] = "@LAST_STABILIZED";
+
+	return (TDB_DATA) {
+		.dptr = discard_const_p(uint8_t, key),
+		.dsize = sizeof(key),
+	};
 }
 
 struct gencache_have_val_state {
@@ -264,6 +266,7 @@ static int last_stabilize_parser(TDB_DATA key, TDB_DATA data,
 bool gencache_set_data_blob(const char *keystr, DATA_BLOB blob,
 			    time_t timeout)
 {
+	TDB_DATA key;
 	int ret;
 	fstring hdr;
 	int hdr_len;
@@ -271,13 +274,15 @@ bool gencache_set_data_blob(const char *keystr, DATA_BLOB blob,
 	static int writecount;
 	TDB_DATA dbufs[2];
 
-	if (tdb_data_cmp(string_term_tdb_data(keystr),
-			 last_stabilize_key()) == 0) {
-		DEBUG(10, ("Can't store %s as a key\n", keystr));
+	if ((keystr == NULL) || (blob.data == NULL)) {
 		return false;
 	}
 
-	if ((keystr == NULL) || (blob.data == NULL)) {
+	key = string_term_tdb_data(keystr);
+
+	ret = tdb_data_cmp(key, last_stabilize_key());
+	if (ret == 0) {
+		DEBUG(10, ("Can't store %s as a key\n", keystr));
 		return false;
 	}
 
@@ -296,9 +301,6 @@ bool gencache_set_data_blob(const char *keystr, DATA_BLOB blob,
 	if (hdr_len == -1) {
 		return false;
 	}
-	if ((blob.length + (size_t)hdr_len) < blob.length) {
-		return false;
-	}
 
 	dbufs[0] = (TDB_DATA) { .dptr = (uint8_t *)hdr, .dsize = hdr_len };
 	dbufs[1] = (TDB_DATA) { .dptr = blob.data, .dsize = blob.length };
@@ -309,8 +311,7 @@ bool gencache_set_data_blob(const char *keystr, DATA_BLOB blob,
 		   (int)(timeout - time(NULL)), 
 		   timeout > time(NULL) ? "ahead" : "in the past"));
 
-	ret = tdb_storev(cache_notrans->tdb, string_term_tdb_data(keystr),
-			 dbufs, 2, 0);
+	ret = tdb_storev(cache_notrans->tdb, key, dbufs, 2, 0);
 	if (ret != 0) {
 		return false;
 	}
@@ -404,26 +405,35 @@ bool gencache_del(const char *keystr)
 	return result;
 }
 
-static bool gencache_pull_timeout(uint8_t *val, time_t *pres, char **payload)
+static bool gencache_pull_timeout(TDB_DATA data, time_t *pres, DATA_BLOB *payload)
 {
 	time_t res;
+	char *slash = NULL;
 	char *endptr;
 
-	if (val == NULL) {
+	if (data.dptr == NULL) {
+		return false;
+	}
+	slash = memchr(data.dptr, '/', data.dsize);
+	if (slash == NULL) {
 		return false;
 	}
 
-	res = strtol((char *)val, &endptr, 10);
+	res = strtol((char *)data.dptr, &endptr, 10);
 
 	if ((endptr == NULL) || (*endptr != '/')) {
-		DEBUG(2, ("Invalid gencache data format: %s\n", (char *)val));
+		DBG_WARNING("Invalid gencache data format\n");
 		return false;
 	}
 	if (pres != NULL) {
 		*pres = res;
 	}
 	if (payload != NULL) {
-		*payload = endptr+1;
+		endptr += 1;
+		*payload = (DATA_BLOB) {
+			.data = discard_const_p(uint8_t, endptr),
+			.length = data.dsize - PTR_DIFF(endptr, data.dptr),
+		};
 	}
 	return true;
 }
@@ -439,22 +449,16 @@ struct gencache_parse_state {
 static int gencache_parse_fn(TDB_DATA key, TDB_DATA data, void *private_data)
 {
 	struct gencache_parse_state *state;
-	DATA_BLOB blob;
 	struct gencache_timeout t;
-	char *payload;
+	DATA_BLOB payload;
 	bool ret;
 
-	if (data.dptr == NULL) {
-		return -1;
-	}
-	ret = gencache_pull_timeout(data.dptr, &t.timeout, &payload);
+	ret = gencache_pull_timeout(data, &t.timeout, &payload);
 	if (!ret) {
 		return -1;
 	}
 	state = (struct gencache_parse_state *)private_data;
-	blob = data_blob_const(
-		payload, data.dsize - PTR_DIFF(payload, data.dptr));
-	state->parser(&t, blob, state->private_data);
+	state->parser(&t, payload, state->private_data);
 
 	if (state->copy_to_notrans) {
 		tdb_store(cache_notrans->tdb, key, data, 0);
@@ -712,7 +716,7 @@ static int stabilize_fn(struct tdb_context *tdb, TDB_DATA key, TDB_DATA val,
 		return 0;
 	}
 
-	if (!gencache_pull_timeout(val.dptr, &timeout, NULL)) {
+	if (!gencache_pull_timeout(val, &timeout, NULL)) {
 		DEBUG(10, ("Ignoring invalid entry\n"));
 		return 0;
 	}
@@ -817,7 +821,7 @@ static int gencache_iterate_blobs_fn(struct tdb_context *tdb, TDB_DATA key,
 	char *keystr;
 	char *free_key = NULL;
 	time_t timeout;
-	char *payload;
+	DATA_BLOB payload;
 
 	if (tdb_data_cmp(key, last_stabilize_key()) == 0) {
 		return 0;
@@ -837,7 +841,7 @@ static int gencache_iterate_blobs_fn(struct tdb_context *tdb, TDB_DATA key,
 		}
 	}
 
-	if (!gencache_pull_timeout(data.dptr, &timeout, &payload)) {
+	if (!gencache_pull_timeout(data, &timeout, &payload)) {
 		goto done;
 	}
 
@@ -854,10 +858,7 @@ static int gencache_iterate_blobs_fn(struct tdb_context *tdb, TDB_DATA key,
 		   "(key=[%s], timeout=[%s])\n",
 		   keystr, timestring(talloc_tos(), timeout)));
 
-	state->fn(keystr,
-		  data_blob_const(payload,
-				  data.dsize - PTR_DIFF(payload, data.dptr)),
-		  timeout, state->private_data);
+	state->fn(keystr, payload, timeout, state->private_data);
 
  done:
 	TALLOC_FREE(free_key);
diff --git a/source3/libsmb/samlogon_cache.c b/source3/libsmb/samlogon_cache.c
index 74e89d7..9638df6 100644
--- a/source3/libsmb/samlogon_cache.c
+++ b/source3/libsmb/samlogon_cache.c
@@ -134,13 +134,13 @@ bool netsamlogon_cache_store(const char *username, struct netr_SamInfo3 *info3)
 	int ret;
 
 	if (!info3) {
-		return false;
+		goto fail;
 	}
 
 	if (!netsamlogon_cache_init()) {
 		DEBUG(0,("netsamlogon_cache_store: cannot open %s for write!\n",
 			NETSAMLOGON_TDB));
-		return false;
+		goto fail;
 	}
 
 	/*
@@ -156,8 +156,7 @@ bool netsamlogon_cache_store(const char *username, struct netr_SamInfo3 *info3)
 	if ((ret == -1) && (tdb_error(netsamlogon_tdb) != TDB_ERR_EXISTS)) {
 		DBG_WARNING("Could not store domain marker for %s: %s\n",
 			    keystr, tdb_errorstr(netsamlogon_tdb));
-		TALLOC_FREE(tmp_ctx);
-		return false;
+		goto fail;
 	}
 
 	sid_compose(&user_sid, info3->base.domain_sid, info3->base.rid);
@@ -180,6 +179,9 @@ bool netsamlogon_cache_store(const char *username, struct netr_SamInfo3 *info3)
 
 		if (full_name != NULL) {
 			info3->base.full_name.string = talloc_strdup(info3, full_name);
+			if (info3->base.full_name.string == NULL) {
+				goto fail;
+			}
 		}
 	}
 
@@ -188,6 +190,9 @@ bool netsamlogon_cache_store(const char *username, struct netr_SamInfo3 *info3)
 
 	if (!info3->base.account_name.string) {
 		info3->base.account_name.string = talloc_strdup(info3, username);
+		if (info3->base.account_name.string == NULL) {
+			goto fail;
+		}
 	}
 
 	r.timestamp = time(NULL);
@@ -204,9 +209,9 @@ bool netsamlogon_cache_store(const char *username, struct netr_SamInfo3 *info3)
 	ndr_err = ndr_push_struct_blob(&blob, tmp_ctx, &r,
 				       (ndr_push_flags_fn_t)ndr_push_netsamlogoncache_entry);
 	if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
-		DEBUG(0,("netsamlogon_cache_store: failed to push entry to cache\n"));
-		TALLOC_FREE(tmp_ctx);
-		return false;
+		DBG_WARNING("failed to push entry to cache: %s\n",
+			    ndr_errstr(ndr_err));
+		goto fail;
 	}
 
 	data.dsize = blob.length;
@@ -216,8 +221,8 @@ bool netsamlogon_cache_store(const char *username, struct netr_SamInfo3 *info3)
 		result = true;
 	}
 
+fail:
 	TALLOC_FREE(tmp_ctx);
-
 	return result;
 }
 


-- 
Samba Shared Repository



More information about the samba-cvs mailing list