Blob Blame History Raw
From 389170e609310395cb77edafdd7298cdfdfdc235 Mon Sep 17 00:00:00 2001
From: Michael Adam <obnox@samba.org>
Date: Fri, 16 Jan 2015 16:18:45 +0100
Subject: [PATCH 1/2] cli_connect_nb_send: don't segfault on host == NULL.

The functions called futher down can cope with host == NULL.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=11058

This is part one of the bugfix:
This ensures that it is enough to pass one of host or address to the function.

Pair-Programmed-With: Andreas Schneider <asn@samba.org>

Signed-off-by: Michael Adam <obnox@samba.org>
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
(cherry picked from commit a0a254f74234bed6c9a0c71a5bda8254fa6f633f)
---
 source3/libsmb/cliconnect.c | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)

diff --git a/source3/libsmb/cliconnect.c b/source3/libsmb/cliconnect.c
index 13e7704..5255e8a 100644
--- a/source3/libsmb/cliconnect.c
+++ b/source3/libsmb/cliconnect.c
@@ -2995,21 +2995,29 @@ static struct tevent_req *cli_connect_nb_send(
 {
 	struct tevent_req *req, *subreq;
 	struct cli_connect_nb_state *state;
-	char *p;
 
 	req = tevent_req_create(mem_ctx, &state, struct cli_connect_nb_state);
 	if (req == NULL) {
 		return NULL;
 	}
-	state->desthost = host;
 	state->signing_state = signing_state;
 	state->flags = flags;
 
-	p = strchr(host, '#');
-	if (p != NULL) {
-		name_type = strtol(p+1, NULL, 16);
-		host = talloc_strndup(state, host, p - host);
-		if (tevent_req_nomem(host, req)) {
+	if (host != NULL) {
+		char *p = strchr(host, '#');
+
+		if (p != NULL) {
+			name_type = strtol(p+1, NULL, 16);
+			host = talloc_strndup(state, host, p - host);
+			if (tevent_req_nomem(host, req)) {
+				return tevent_req_post(req, ev);
+			}
+		}
+
+		state->desthost = host;
+	} else {
+		state->desthost = print_canonical_sockaddr(state, dest_ss);
+		if (tevent_req_nomem(state->desthost, req)) {
 			return tevent_req_post(req, ev);
 		}
 	}
-- 
2.2.2


From ff6f3e175262d802fa64ef78e7047dbf136b2722 Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn@samba.org>
Date: Tue, 13 Jan 2015 17:04:26 +0100
Subject: [PATCH 2/2] utils: Fix 'net time' segfault.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=11058

This is part two of the bugfix. Make sure we pass the IP we found to
cli_servertime(). Hence we always pass at least one of name or IP.

Pair-Programmed-With: Michael Adam <obnox@samba.org>

Signed-off-by: Andreas Schneider <asn@samba.org>
Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
(cherry picked from commit 45829800eb3f3a8aeccfe7c1114dcf9df60371d5)
---
 source3/utils/net_time.c | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/source3/utils/net_time.c b/source3/utils/net_time.c
index 56ce8f7..595d903 100644
--- a/source3/utils/net_time.c
+++ b/source3/utils/net_time.c
@@ -226,16 +226,23 @@ int net_time(struct net_context *c, int argc, const char **argv)
 		return 0;
 	}
 
-	if (!c->opt_host && !c->opt_have_ip &&
-	    !find_master_ip(c->opt_target_workgroup, &c->opt_dest_ip)) {
-		d_fprintf(stderr, _("Could not locate a time server.  Try "
-				    "specifying a target host.\n"));
-		net_time_usage(c, argc,argv);
-		return -1;
+	if (c->opt_host == NULL && !c->opt_have_ip) {
+		bool ok;
+
+		ok = find_master_ip(c->opt_target_workgroup, &c->opt_dest_ip);
+		if (!ok) {
+			d_fprintf(stderr,
+				  _("Could not locate a time server.  "
+				    "Try specifying a target host.\n"));
+			net_time_usage(c, argc, argv);
+			return -1;
+		}
+		c->opt_have_ip = true;
 	}
 
 	/* default - print the time */
-	t = cli_servertime(c->opt_host, c->opt_have_ip? &c->opt_dest_ip : NULL,
+	t = cli_servertime(c->opt_host,
+			   c->opt_have_ip? &c->opt_dest_ip : NULL,
 			   NULL);
 	if (t == 0) return -1;
 
-- 
2.2.2