From: Michael Adam Date: Fri, 16 Jan 2015 15:18:45 +0000 (+0100) Subject: cli_connect_nb_send: don't segfault on host == NULL. X-Git-Tag: samba-4.2.0rc5~50 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a5d30bd2ecd8269de1071f535209cc2a33c5cbcd;p=thirdparty%2Fsamba.git 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 Signed-off-by: Michael Adam Signed-off-by: Andreas Schneider Reviewed-by: Jeremy Allison (cherry picked from commit a0a254f74234bed6c9a0c71a5bda8254fa6f633f) --- diff --git a/source3/libsmb/cliconnect.c b/source3/libsmb/cliconnect.c index 950865167d1..7292805d3d6 100644 --- a/source3/libsmb/cliconnect.c +++ b/source3/libsmb/cliconnect.c @@ -3013,21 +3013,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); } }