summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2017-04-28 13:58:48 +0200
committerVolker Lendecke <vl@samba.org>2017-05-01 14:39:41 +0200
commit2951c592f72b3c2f3e9318730063771846d7aa82 (patch)
treeb36338e6d948b023cdbada17c920041381a7b72b
parent6f81f07303773d15ce16629c6759540b1d9adab7 (diff)
downloadsamba-2951c592f72b3c2f3e9318730063771846d7aa82.tar.gz
torture3: Make sure dbwrap_parse_record returns NOT_FOUND for invalid watchers data
Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org> Autobuild-User(master): Volker Lendecke <vl@samba.org> Autobuild-Date(master): Mon May 1 14:39:41 CEST 2017 on sn-devel-144
-rwxr-xr-xsource3/selftest/tests.py1
-rw-r--r--source3/torture/proto.h1
-rw-r--r--source3/torture/test_dbwrap_watch.c68
-rw-r--r--source3/torture/torture.c1
4 files changed, 71 insertions, 0 deletions
diff --git a/source3/selftest/tests.py b/source3/selftest/tests.py
index 7a1359f4bb8..1d02bd25ef5 100755
--- a/source3/selftest/tests.py
+++ b/source3/selftest/tests.py
@@ -147,6 +147,7 @@ local_tests = [
"LOCAL-PTHREADPOOL-TEVENT",
"LOCAL-CANONICALIZE-PATH",
"LOCAL-DBWRAP-WATCH1",
+ "LOCAL-DBWRAP-WATCH2",
"LOCAL-hex_encode_buf",
"LOCAL-remove_duplicate_addrs2"]
diff --git a/source3/torture/proto.h b/source3/torture/proto.h
index da0c69f4f69..129c05d7e7a 100644
--- a/source3/torture/proto.h
+++ b/source3/torture/proto.h
@@ -109,6 +109,7 @@ bool run_cleanup4(int dummy);
bool run_notify_bench2(int dummy);
bool run_notify_bench3(int dummy);
bool run_dbwrap_watch1(int dummy);
+bool run_dbwrap_watch2(int dummy);
bool run_idmap_tdb_common_test(int dummy);
bool run_local_dbwrap_ctdb(int dummy);
bool run_qpathinfo_bufsize(int dummy);
diff --git a/source3/torture/test_dbwrap_watch.c b/source3/torture/test_dbwrap_watch.c
index 88e0e1cd9fe..5aa0430b111 100644
--- a/source3/torture/test_dbwrap_watch.c
+++ b/source3/torture/test_dbwrap_watch.c
@@ -108,3 +108,71 @@ fail:
TALLOC_FREE(ev);
return ret;
}
+
+/*
+ * Make sure dbwrap_parse_record does not return NT_STATUS_OK on
+ * invalid data
+ */
+
+bool run_dbwrap_watch2(int dummy)
+{
+ struct tevent_context *ev = NULL;
+ struct messaging_context *msg = NULL;
+ struct db_context *backend = NULL;
+ struct db_context *db = NULL;
+ const char *keystr = "key";
+ TDB_DATA key = string_term_tdb_data(keystr);
+ NTSTATUS status;
+ bool ret = false;
+
+ ev = samba_tevent_context_init(talloc_tos());
+ if (ev == NULL) {
+ fprintf(stderr, "tevent_context_init failed\n");
+ goto fail;
+ }
+ msg = messaging_init(ev, ev);
+ if (msg == NULL) {
+ fprintf(stderr, "messaging_init failed\n");
+ goto fail;
+ }
+ backend = db_open(msg, "test_watch.tdb", 0, TDB_CLEAR_IF_FIRST,
+ O_CREAT|O_RDWR, 0644, DBWRAP_LOCK_ORDER_1,
+ DBWRAP_FLAG_NONE);
+ if (backend == NULL) {
+ fprintf(stderr, "db_open failed: %s\n", strerror(errno));
+ goto fail;
+ }
+
+ /*
+ * Store invalid data (from the dbwrap_watch point of view)
+ * directly into the backend database
+ */
+ status = dbwrap_store_uint32_bystring(backend, keystr, UINT32_MAX);
+ if (!NT_STATUS_IS_OK(status)) {
+ fprintf(stderr, "dbwrap_store_uint32_bystring failed: %s\n",
+ nt_errstr(status));
+ goto fail;
+ }
+
+ db = db_open_watched(ev, backend, msg);
+ if (db == NULL) {
+ fprintf(stderr, "db_open_watched failed\n");
+ goto fail;
+ }
+ backend = NULL; /* open_watch talloc_moves backend */
+
+ status = dbwrap_parse_record(db, key, NULL, NULL);
+ if (!NT_STATUS_EQUAL(status, NT_STATUS_NOT_FOUND)) {
+ fprintf(stderr, "dbwrap_parse_record returned %s, expected "
+ "NT_STATUS_NOT_FOUND\n", nt_errstr(status));
+ goto fail;
+ }
+
+ (void)unlink("test_watch.tdb");
+ ret = true;
+fail:
+ TALLOC_FREE(db);
+ TALLOC_FREE(msg);
+ TALLOC_FREE(ev);
+ return ret;
+}
diff --git a/source3/torture/torture.c b/source3/torture/torture.c
index 0d9a653cf20..bdcf1e13f17 100644
--- a/source3/torture/torture.c
+++ b/source3/torture/torture.c
@@ -11448,6 +11448,7 @@ static struct {
{ "LOCAL-GENCACHE", run_local_gencache, 0},
{ "LOCAL-TALLOC-DICT", run_local_talloc_dict, 0},
{ "LOCAL-DBWRAP-WATCH1", run_dbwrap_watch1, 0 },
+ { "LOCAL-DBWRAP-WATCH2", run_dbwrap_watch2, 0 },
{ "LOCAL-MESSAGING-READ1", run_messaging_read1, 0 },
{ "LOCAL-MESSAGING-READ2", run_messaging_read2, 0 },
{ "LOCAL-MESSAGING-READ3", run_messaging_read3, 0 },