[PATCH] Some cleanups around nbt

Volker Lendecke Volker.Lendecke at SerNet.DE
Thu Apr 12 18:56:10 UTC 2018


Hi!

Review appreciated!

Thanks, Volker

-- 
SerNet GmbH, Bahnhofsallee 1b, 37081 Göttingen
phone: +49-551-370000-0, fax: +49-551-370000-9
AG Göttingen, HRB 2816, GF: Dr. Johannes Loxen
http://www.sernet.de, mailto:kontakt at sernet.de
-------------- next part --------------
From 28c35a6e5200541715cc7fdec67f92a320720999 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Sun, 4 Feb 2018 12:16:14 +0000
Subject: [PATCH 1/3] libnbt: Add an explicit "mem_ctx" to name_request_send

Implicitly hanging requests off nbtsock is too inflexible for future use

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 libcli/nbt/namequery.c    | 4 ++--
 libcli/nbt/namerefresh.c  | 2 +-
 libcli/nbt/nameregister.c | 2 +-
 libcli/nbt/namerelease.c  | 2 +-
 libcli/nbt/nbt_proto.h    | 3 ++-
 libcli/nbt/nbtsocket.c    | 5 +++--
 6 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/libcli/nbt/namequery.c b/libcli/nbt/namequery.c
index e344235faa8..49ab10c3c02 100644
--- a/libcli/nbt/namequery.c
+++ b/libcli/nbt/namequery.c
@@ -56,7 +56,7 @@ _PUBLIC_ struct nbt_name_request *nbt_name_query_send(struct nbt_name_socket *nb
 	dest = socket_address_from_strings(packet, nbtsock->sock->backend_name,
 					   io->in.dest_addr, io->in.dest_port);
 	if (dest == NULL) goto failed;
-	req = nbt_name_request_send(nbtsock, dest, packet,
+	req = nbt_name_request_send(nbtsock, nbtsock, dest, packet,
 				    io->in.timeout, io->in.retries, false);
 	if (req == NULL) goto failed;
 
@@ -160,7 +160,7 @@ _PUBLIC_ struct nbt_name_request *nbt_name_status_send(struct nbt_name_socket *n
 	dest = socket_address_from_strings(packet, nbtsock->sock->backend_name,
 					   io->in.dest_addr, io->in.dest_port);
 	if (dest == NULL) goto failed;
-	req = nbt_name_request_send(nbtsock, dest, packet,
+	req = nbt_name_request_send(nbtsock, nbtsock, dest, packet,
 				    io->in.timeout, io->in.retries, false);
 	if (req == NULL) goto failed;
 
diff --git a/libcli/nbt/namerefresh.c b/libcli/nbt/namerefresh.c
index b525356c747..b3aef76a5c6 100644
--- a/libcli/nbt/namerefresh.c
+++ b/libcli/nbt/namerefresh.c
@@ -72,7 +72,7 @@ struct nbt_name_request *nbt_name_refresh_send(struct nbt_name_socket *nbtsock,
 					   nbtsock->sock->backend_name,
 					   io->in.dest_addr, io->in.dest_port);
 	if (dest == NULL) goto failed;
-	req = nbt_name_request_send(nbtsock, dest, packet,
+	req = nbt_name_request_send(nbtsock, nbtsock, dest, packet,
 				    io->in.timeout, io->in.retries, false);
 	if (req == NULL) goto failed;
 
diff --git a/libcli/nbt/nameregister.c b/libcli/nbt/nameregister.c
index ff5418c85e5..8e8271d5731 100644
--- a/libcli/nbt/nameregister.c
+++ b/libcli/nbt/nameregister.c
@@ -80,7 +80,7 @@ struct nbt_name_request *nbt_name_register_send(struct nbt_name_socket *nbtsock,
 	dest = socket_address_from_strings(packet, nbtsock->sock->backend_name,
 					   io->in.dest_addr, io->in.dest_port);
 	if (dest == NULL) goto failed;
-	req = nbt_name_request_send(nbtsock, dest, packet,
+	req = nbt_name_request_send(nbtsock, nbtsock, dest, packet,
 				    io->in.timeout, io->in.retries, false);
 	if (req == NULL) goto failed;
 
diff --git a/libcli/nbt/namerelease.c b/libcli/nbt/namerelease.c
index 8f4698169d8..68c8252078b 100644
--- a/libcli/nbt/namerelease.c
+++ b/libcli/nbt/namerelease.c
@@ -69,7 +69,7 @@ _PUBLIC_ struct nbt_name_request *nbt_name_release_send(struct nbt_name_socket *
 	dest = socket_address_from_strings(packet, nbtsock->sock->backend_name,
 					   io->in.dest_addr, io->in.dest_port);
 	if (dest == NULL) goto failed;
-	req = nbt_name_request_send(nbtsock, dest, packet,
+	req = nbt_name_request_send(nbtsock, nbtsock, dest, packet,
 				    io->in.timeout, io->in.retries, false);
 	if (req == NULL) goto failed;
 
diff --git a/libcli/nbt/nbt_proto.h b/libcli/nbt/nbt_proto.h
index 281ce25a864..e6ee46bab86 100644
--- a/libcli/nbt/nbt_proto.h
+++ b/libcli/nbt/nbt_proto.h
@@ -33,7 +33,8 @@
 
 /* The following definitions come from ../libcli/nbt/nbtsocket.c  */
 
-struct nbt_name_request *nbt_name_request_send(struct nbt_name_socket *nbtsock,
+struct nbt_name_request *nbt_name_request_send(TALLOC_CTX *mem_ctx,
+					       struct nbt_name_socket *nbtsock,
 					       struct socket_address *dest,
 					       struct nbt_name_packet *request,
 					       int timeout, int retries,
diff --git a/libcli/nbt/nbtsocket.c b/libcli/nbt/nbtsocket.c
index 711e39cbdc5..94ec4627d80 100644
--- a/libcli/nbt/nbtsocket.c
+++ b/libcli/nbt/nbtsocket.c
@@ -367,7 +367,8 @@ failed:
 /*
   send off a nbt name request
 */
-struct nbt_name_request *nbt_name_request_send(struct nbt_name_socket *nbtsock,
+struct nbt_name_request *nbt_name_request_send(TALLOC_CTX *mem_ctx,
+					       struct nbt_name_socket *nbtsock,
 					       struct socket_address *dest,
 					       struct nbt_name_packet *request,
 					       int timeout, int retries,
@@ -377,7 +378,7 @@ struct nbt_name_request *nbt_name_request_send(struct nbt_name_socket *nbtsock,
 	int id;
 	enum ndr_err_code ndr_err;
 
-	req = talloc_zero(nbtsock, struct nbt_name_request);
+	req = talloc_zero(mem_ctx, struct nbt_name_request);
 	if (req == NULL) goto failed;
 
 	req->nbtsock                = nbtsock;
-- 
2.11.0


From f4beb76724fafaf173238812bdc1c21477734b12 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Thu, 12 Apr 2018 20:40:32 +0200
Subject: [PATCH 2/3] libnbt: Align data types

ARRAY_SIZE returns size_t

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 libcli/nbt/nbtsocket.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libcli/nbt/nbtsocket.c b/libcli/nbt/nbtsocket.c
index 94ec4627d80..33d53fba993 100644
--- a/libcli/nbt/nbtsocket.c
+++ b/libcli/nbt/nbtsocket.c
@@ -527,7 +527,7 @@ NTSTATUS nbt_set_unexpected_handler(struct nbt_name_socket *nbtsock,
 */
 _PUBLIC_ NTSTATUS nbt_rcode_to_ntstatus(uint8_t rcode)
 {
-	int i;
+	size_t i;
 	struct {
 		enum nbt_rcode rcode;
 		NTSTATUS status;
-- 
2.11.0


From ad543b3cbd1e06b7c40df2b97c1bdf7842af18cd Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Sun, 25 Feb 2018 13:00:39 +0100
Subject: [PATCH 3/3] libdgram: Fix an error path memleak

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source4/libcli/dgram/mailslot.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/source4/libcli/dgram/mailslot.c b/source4/libcli/dgram/mailslot.c
index 466c603432d..bae26e06c8c 100644
--- a/source4/libcli/dgram/mailslot.c
+++ b/source4/libcli/dgram/mailslot.c
@@ -171,6 +171,7 @@ NTSTATUS dgram_mailslot_send(struct nbt_dgram_socket *dgmsock,
 	packet.dgram_id = generate_random() % UINT16_MAX;
 	src = socket_get_my_addr(dgmsock->sock, tmp_ctx);
 	if (!src) {
+		talloc_free(tmp_ctx);
 		return NT_STATUS_NO_MEMORY;
 	}
 	packet.src_addr = src->addr;
-- 
2.11.0



More information about the samba-technical mailing list