[SCM] Samba Shared Repository - branch v3-2-test updated - initial-v3-2-unstable-230-ga0d0a06

Stefan Metzmacher metze at samba.org
Wed Nov 7 11:39:49 GMT 2007


The branch, v3-2-test has been updated
       via  a0d0a06a9e39ea4fd07e9381f4b3397f403ab79d (commit)
       via  55d01b3f5b55cab3228270c0f6c164f11b0803f5 (commit)
       via  be1f2f1abf15b34f8ab08d9e63637962fa762853 (commit)
       via  91ccaa8e70f1665bd759a80363cda9605399464e (commit)
       via  aa155b2c2936c0e9996eda0a21f137773270343a (commit)
       via  f3dde8c7b73b619a54814bc6a862fa917455b624 (commit)
       via  1563a08cb07738c11ea7b68ba9e814885060b0b7 (commit)
       via  b542eaf825aa42b53f08c73e2b86ee9fafb33256 (commit)
       via  52c422f4d7f8549a11d637de1abceabc1ae86497 (commit)
       via  8ed241532a069c4207945d5f1ceb1ec817ba7976 (commit)
      from  c14db81be5212dfa6fbcf8bfdcf725d7db3376ca (commit)

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=v3-2-test


- Log -----------------------------------------------------------------
commit a0d0a06a9e39ea4fd07e9381f4b3397f403ab79d
Author: metze <metze at 0c0555d6-39d7-0310-84fc-f1cc0bd64818>
Date:   Fri Nov 2 11:01:18 2007 +0000

    - check return value of ndr_push_set_switch_value()
    - fix memory leaks in error pathes
    
    metze
    
    git-svn-id: svn+ssh://svn.samba.org/data/svn/samba/branches/SAMBA_4_0@25798 0c0555d6-39d7-0310-84fc-f1cc0bd64818

commit 55d01b3f5b55cab3228270c0f6c164f11b0803f5
Author: metze <metze at samba.org>
Date:   Fri Nov 2 10:59:43 2007 +0000

    use error and out logic
    
    metze
    
    git-svn-id: svn+ssh://svn.samba.org/data/svn/samba/branches/SAMBA_4_0@25797 0c0555d6-39d7-0310-84fc-f1cc0bd64818

commit be1f2f1abf15b34f8ab08d9e63637962fa762853
Author: metze <metze at 0c0555d6-39d7-0310-84fc-f1cc0bd64818>
Date:   Fri Nov 2 10:49:51 2007 +0000

    use NT_STATUS_HAVE_NO_MEMORY()
    
    metze
    
    git-svn-id: svn+ssh://svn.samba.org/data/svn/samba/branches/SAMBA_4_0@25796 0c0555d6-39d7-0310-84fc-f1cc0bd64818

commit 91ccaa8e70f1665bd759a80363cda9605399464e
Author: metze <metze at 0c0555d6-39d7-0310-84fc-f1cc0bd64818>
Date:   Fri Nov 2 10:32:47 2007 +0000

    use NDR_CHECK()
    
    metze
    
    git-svn-id: svn+ssh://svn.samba.org/data/svn/samba/branches/SAMBA_4_0@25794 0c0555d6-39d7-0310-84fc-f1cc0bd64818

commit aa155b2c2936c0e9996eda0a21f137773270343a
Author: metze <metze at 0c0555d6-39d7-0310-84fc-f1cc0bd64818>
Date:   Fri Nov 2 10:29:19 2007 +0000

    check the return value of ndr_push_set_switch_value()
    
    metze
    
    git-svn-id: svn+ssh://svn.samba.org/data/svn/samba/branches/SAMBA_4_0@25793 0c0555d6-39d7-0310-84fc-f1cc0bd64818

commit f3dde8c7b73b619a54814bc6a862fa917455b624
Author: metze <metze at 0c0555d6-39d7-0310-84fc-f1cc0bd64818>
Date:   Fri Nov 2 10:26:49 2007 +0000

    use NT_STATUS_HAVE_NO_MEMORY() and NDR_CHECK()
    
    metze
    
    git-svn-id: svn+ssh://svn.samba.org/data/svn/samba/branches/SAMBA_4_0@25792 0c0555d6-39d7-0310-84fc-f1cc0bd64818

commit 1563a08cb07738c11ea7b68ba9e814885060b0b7
Author: metze <metze at 0c0555d6-39d7-0310-84fc-f1cc0bd64818>
Date:   Thu Nov 1 10:15:13 2007 +0000

    the return value of ndr_pull_set_switch_value() should be checked
    
    metze
    
    git-svn-id: svn+ssh://svn.samba.org/data/svn/samba/branches/SAMBA_4_0@25779 0c0555d6-39d7-0310-84fc-f1cc0bd64818

commit b542eaf825aa42b53f08c73e2b86ee9fafb33256
Author: metze <metze at 0c0555d6-39d7-0310-84fc-f1cc0bd64818>
Date:   Thu Nov 1 10:13:36 2007 +0000

    use NT_STATUS_HAVE_NO_MEMORY() and NDR_CHECK() macros
    
    metze
    
    git-svn-id: svn+ssh://svn.samba.org/data/svn/samba/branches/SAMBA_4_0@25778 0c0555d6-39d7-0310-84fc-f1cc0bd64818

commit 52c422f4d7f8549a11d637de1abceabc1ae86497
Author: metze <metze at 0c0555d6-39d7-0310-84fc-f1cc0bd64818>
Date:   Thu Nov 1 09:50:24 2007 +0000

    add NDR_ERR_UNREAD_BYTES and don't use NTSTATUS directly
    
    metze
    
    git-svn-id: svn+ssh://svn.samba.org/data/svn/samba/branches/SAMBA_4_0@25777 0c0555d6-39d7-0310-84fc-f1cc0bd64818

commit 8ed241532a069c4207945d5f1ceb1ec817ba7976
Author: metze <metze at 0c0555d6-39d7-0310-84fc-f1cc0bd64818>
Date:   Thu Nov 1 08:10:54 2007 +0000

    create ndr_pull_union_blob_all() and match the logic of the struct fns
    
    metze
    
    git-svn-id: svn+ssh://svn.samba.org/data/svn/samba/branches/SAMBA_4_0@25774 0c0555d6-39d7-0310-84fc-f1cc0bd64818

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

Summary of changes:
 source/librpc/ndr/libndr.h    |    3 +-
 source/librpc/ndr/ndr.c       |  103 ++++++++++++++++++++++-------------------
 source/librpc/ndr/ndr_basic.c |    7 +--
 3 files changed, 61 insertions(+), 52 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source/librpc/ndr/libndr.h b/source/librpc/ndr/libndr.h
index ee27464..f09693f 100644
--- a/source/librpc/ndr/libndr.h
+++ b/source/librpc/ndr/libndr.h
@@ -175,7 +175,8 @@ enum ndr_err_code {
 	NDR_ERR_RANGE,
 	NDR_ERR_TOKEN,
 	NDR_ERR_IPV4ADDRESS,
-	NDR_ERR_INVALID_POINTER
+	NDR_ERR_INVALID_POINTER,
+	NDR_ERR_UNREAD_BYTES
 };
 
 enum ndr_compression_alg {
diff --git a/source/librpc/ndr/ndr.c b/source/librpc/ndr/ndr.c
index 326ab12..1538891 100644
--- a/source/librpc/ndr/ndr.c
+++ b/source/librpc/ndr/ndr.c
@@ -330,6 +330,8 @@ static NTSTATUS ndr_map_error(enum ndr_err_code ndr_err)
 		return NT_STATUS_ARRAY_BOUNDS_EXCEEDED;
 	case NDR_ERR_INVALID_POINTER:
 		return NT_STATUS_INVALID_PARAMETER_MIX;
+	case NDR_ERR_UNREAD_BYTES:
+		return NT_STATUS_PORT_MESSAGE_TOO_LONG;
 	default:
 		break;
 	}
@@ -524,9 +526,7 @@ NTSTATUS ndr_token_store(TALLOC_CTX *mem_ctx,
 {
 	struct ndr_token_list *tok;
 	tok = talloc(mem_ctx, struct ndr_token_list);
-	if (tok == NULL) {
-		return NT_STATUS_NO_MEMORY;
-	}
+	NT_STATUS_HAVE_NO_MEMORY(tok);
 	tok->key = key;
 	tok->value = value;
 	DLIST_ADD((*list), tok);
@@ -569,9 +569,13 @@ uint32_t ndr_token_peek(struct ndr_token_list **list, const void *key)
 {
 	NTSTATUS status;
 	uint32_t v;
-	status = ndr_token_retrieve_cmp_fn(list, key, &v, NULL, False);
-	if (NT_STATUS_IS_OK(status)) return v;
-	return 0;
+
+	status = ndr_token_retrieve_cmp_fn(list, key, &v, NULL, false);
+	if (!NT_STATUS_IS_OK(status)) {
+		return 0;
+	}
+
+	return v;
 }
 
 /*
@@ -689,10 +693,9 @@ NTSTATUS ndr_pull_struct_blob(const DATA_BLOB *blob, TALLOC_CTX *mem_ctx, void *
 {
 	struct ndr_pull *ndr;
 	ndr = ndr_pull_init_blob(blob, mem_ctx);
-	if (!ndr) {
-		return NT_STATUS_NO_MEMORY;
-	}
-	return fn(ndr, NDR_SCALARS|NDR_BUFFERS, p);
+	NT_STATUS_HAVE_NO_MEMORY(ndr);
+	NDR_CHECK(fn(ndr, NDR_SCALARS|NDR_BUFFERS, p));
+	return NT_STATUS_OK;
 }
 
 /*
@@ -702,18 +705,15 @@ NTSTATUS ndr_pull_struct_blob_all(const DATA_BLOB *blob, TALLOC_CTX *mem_ctx, vo
 				  ndr_pull_flags_fn_t fn)
 {
 	struct ndr_pull *ndr;
-	NTSTATUS status;
-
 	ndr = ndr_pull_init_blob(blob, mem_ctx);
-	if (!ndr) {
-		return NT_STATUS_NO_MEMORY;
-	}
-	status = fn(ndr, NDR_SCALARS|NDR_BUFFERS, p);
-	if (!NT_STATUS_IS_OK(status)) return status;
+	NT_STATUS_HAVE_NO_MEMORY(ndr);
+	NDR_CHECK(fn(ndr, NDR_SCALARS|NDR_BUFFERS, p));
 	if (ndr->offset < ndr->data_size) {
-		return NT_STATUS_PORT_MESSAGE_TOO_LONG;
+		return ndr_pull_error(ndr, NDR_ERR_UNREAD_BYTES,
+				      "not all bytes consumed ofs[%u] size[%u]",
+				      ndr->offset, ndr->data_size);
 	}
-	return status;
+	return NT_STATUS_OK;
 }
 
 /*
@@ -723,19 +723,31 @@ NTSTATUS ndr_pull_union_blob(const DATA_BLOB *blob, TALLOC_CTX *mem_ctx, void *p
 			     uint32_t level, ndr_pull_flags_fn_t fn)
 {
 	struct ndr_pull *ndr;
-	NTSTATUS status;
+	ndr = ndr_pull_init_blob(blob, mem_ctx);
+	NT_STATUS_HAVE_NO_MEMORY(ndr);
+	NDR_CHECK(ndr_pull_set_switch_value(ndr, p, level));
+	NDR_CHECK(fn(ndr, NDR_SCALARS|NDR_BUFFERS, p));
+	return NT_STATUS_OK;
+}
 
+/*
+  pull a union from a blob using NDR, given the union discriminator,
+  failing if all bytes are not consumed
+*/
+_PUBLIC_ NTSTATUS ndr_pull_union_blob_all(const DATA_BLOB *blob, TALLOC_CTX *mem_ctx, void *p,
+			     uint32_t level, ndr_pull_flags_fn_t fn)
+{
+	struct ndr_pull *ndr;
 	ndr = ndr_pull_init_blob(blob, mem_ctx);
-	if (!ndr) {
-		return NT_STATUS_NO_MEMORY;
-	}
-	ndr_pull_set_switch_value(ndr, p, level);
-	status = fn(ndr, NDR_SCALARS|NDR_BUFFERS, p);
-	if (!NT_STATUS_IS_OK(status)) return status;
-	if (ndr->offset != ndr->data_size) {
-		return NT_STATUS_BUFFER_TOO_SMALL;
+	NT_STATUS_HAVE_NO_MEMORY(ndr);
+	NDR_CHECK(ndr_pull_set_switch_value(ndr, p, level));
+	NDR_CHECK(fn(ndr, NDR_SCALARS|NDR_BUFFERS, p));
+	if (ndr->offset < ndr->data_size) {
+		return ndr_pull_error(ndr, NDR_ERR_UNREAD_BYTES,
+				      "not all bytes consumed ofs[%u] size[%u]",
+				      ndr->offset, ndr->data_size);
 	}
-	return status;
+	return NT_STATUS_OK;
 }
 
 /*
@@ -744,16 +756,11 @@ NTSTATUS ndr_pull_union_blob(const DATA_BLOB *blob, TALLOC_CTX *mem_ctx, void *p
 NTSTATUS ndr_push_struct_blob(DATA_BLOB *blob, TALLOC_CTX *mem_ctx, const void *p,
 			      ndr_push_flags_fn_t fn)
 {
-	NTSTATUS status;
 	struct ndr_push *ndr;
 	ndr = ndr_push_init_ctx(mem_ctx);
-	if (!ndr) {
-		return NT_STATUS_NO_MEMORY;
-	}
-	status = fn(ndr, NDR_SCALARS|NDR_BUFFERS, p);
-	if (!NT_STATUS_IS_OK(status)) {
-		return status;
-	}
+	NT_STATUS_HAVE_NO_MEMORY(ndr);
+
+	NDR_CHECK(fn(ndr, NDR_SCALARS|NDR_BUFFERS, p));
 
 	*blob = ndr_push_blob(ndr);
 	talloc_steal(mem_ctx, blob->data);
@@ -768,17 +775,12 @@ NTSTATUS ndr_push_struct_blob(DATA_BLOB *blob, TALLOC_CTX *mem_ctx, const void *
 NTSTATUS ndr_push_union_blob(DATA_BLOB *blob, TALLOC_CTX *mem_ctx, void *p,
 			     uint32_t level, ndr_push_flags_fn_t fn)
 {
-	NTSTATUS status;
 	struct ndr_push *ndr;
 	ndr = ndr_push_init_ctx(mem_ctx);
-	if (!ndr) {
-		return NT_STATUS_NO_MEMORY;
-	}
-	ndr_push_set_switch_value(ndr, p, level);
-	status = fn(ndr, NDR_SCALARS|NDR_BUFFERS, p);
-	if (!NT_STATUS_IS_OK(status)) {
-		return status;
-	}
+	NT_STATUS_HAVE_NO_MEMORY(ndr);
+
+	NDR_CHECK(ndr_push_set_switch_value(ndr, p, level));
+	NDR_CHECK(fn(ndr, NDR_SCALARS|NDR_BUFFERS, p));
 
 	*blob = ndr_push_blob(ndr);
 	talloc_steal(mem_ctx, blob->data);
@@ -804,6 +806,7 @@ size_t ndr_size_struct(const void *p, int flags, ndr_push_flags_fn_t push)
 	ndr->flags |= flags | LIBNDR_FLAG_NO_NDR_SIZE;
 	status = push(ndr, NDR_SCALARS|NDR_BUFFERS, p);
 	if (!NT_STATUS_IS_OK(status)) {
+		talloc_free(ndr);
 		return 0;
 	}
 	ret = ndr->offset;
@@ -826,9 +829,15 @@ size_t ndr_size_union(const void *p, int flags, uint32_t level, ndr_push_flags_f
 	ndr = ndr_push_init_ctx(NULL);
 	if (!ndr) return 0;
 	ndr->flags |= flags | LIBNDR_FLAG_NO_NDR_SIZE;
-	ndr_push_set_switch_value(ndr, p, level);
+
+	status = ndr_push_set_switch_value(ndr, p, level);
+	if (!NT_STATUS_IS_OK(status)) {
+		talloc_free(ndr);
+		return 0;
+	}
 	status = push(ndr, NDR_SCALARS|NDR_BUFFERS, p);
 	if (!NT_STATUS_IS_OK(status)) {
+		talloc_free(ndr);
 		return 0;
 	}
 	ret = ndr->offset;
diff --git a/source/librpc/ndr/ndr_basic.c b/source/librpc/ndr/ndr_basic.c
index e036eae..5377ed3 100644
--- a/source/librpc/ndr/ndr_basic.c
+++ b/source/librpc/ndr/ndr_basic.c
@@ -128,12 +128,11 @@ NTSTATUS ndr_pull_uint32(struct ndr_pull *ndr, int ndr_flags, uint32_t *v)
 */
 NTSTATUS ndr_pull_generic_ptr(struct ndr_pull *ndr, uint32_t *v)
 {
-	NTSTATUS status;
-	status = ndr_pull_uint32(ndr, NDR_SCALARS, v);
-	if (NT_STATUS_IS_OK(status) && *v != 0) {
+	NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, v));
+	if (*v != 0) {
 		ndr->ptr_count++;
 	}
-	return status;
+	return NT_STATUS_OK;
 }
 
 /*


-- 
Samba Shared Repository


More information about the samba-cvs mailing list