From 553ac4f02de689a711dc2dd3b46c9e5a603dadfa Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Tue, 13 Jan 2015 17:04:26 +0100 Subject: [PATCH] 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 Signed-off-by: Andreas Schneider Signed-off-by: Michael Adam Reviewed-by: Jeremy Allison (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 56ce8f71ad6..595d903c0be 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.47.2