[PATCH] Fix 'net time' segfault
Michael Adam
obnox at samba.org
Fri Jan 16 02:59:19 MST 2015
I am looking at the patch, but I'm not convinced yet that the
logic is correct. More later...
Michael
On 2015-01-16 at 10:03 +0100, Andreas Schneider wrote:
> Hello,
>
> the attached patch fixes a segfault for 'net time'. I opened
>
> https://bugzilla.samba.org/show_bug.cgi?id=11058
>
> for that. It is related to https://bugzilla.samba.org/show_bug.cgi?id=10728
>
>
> Please push if the patch is fine with you.
>
>
> Thanks!
>
>
> -- andreas
>
> --
> Andreas Schneider GPG-ID: CC014E3D
> Samba Team asn at samba.org
> www.samba.org
> >From fea4a9adbb5a131e71ccb27f6a8e4ee35489a2be Mon Sep 17 00:00:00 2001
> From: Andreas Schneider <asn at samba.org>
> 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
>
> Signed-off-by: Andreas Schneider <asn at samba.org>
> ---
> source3/utils/net_time.c | 39 ++++++++++++++++++++++++++++++++-------
> 1 file changed, 32 insertions(+), 7 deletions(-)
>
> diff --git a/source3/utils/net_time.c b/source3/utils/net_time.c
> index 56ce8f7..858abfd 100644
> --- a/source3/utils/net_time.c
> +++ b/source3/utils/net_time.c
> @@ -21,6 +21,7 @@
> #include "libsmb/nmblib.h"
> #include "libsmb/libsmb.h"
> #include "../libcli/smb/smbXcli_base.h"
> +#include "lib/param/loadparm.h"
>
> /*
> return the time on a server. This does not require any authentication
> @@ -184,6 +185,7 @@ static int net_time_zone(struct net_context *c, int argc, const char **argv)
> int net_time(struct net_context *c, int argc, const char **argv)
> {
> time_t t;
> + const char *dest_host;
> struct functable func[] = {
> {
> "system",
> @@ -226,16 +228,39 @@ 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;
> + dest_host = c->opt_host;
> + if (dest_host == NULL) {
> + bool ok;
> +
> + if (!c->opt_have_ip) {
> + 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;
> + }
> + }
> +
> + ok = strequal(lp_workgroup(), c->opt_target_workgroup);
> + if (!ok) {
> + dest_host = lp_realm();
> + }
> +
> + if (dest_host == NULL) {
> + d_fprintf(stderr,
> + _("Could not locate a time server. "
> + "Try specifying a target host.\n"));
> + net_time_usage(c, argc,argv);
> + return -1;
> + }
> }
>
> /* default - print the time */
> - t = cli_servertime(c->opt_host, c->opt_have_ip? &c->opt_dest_ip : NULL,
> + t = cli_servertime(dest_host,
> + c->opt_have_ip? &c->opt_dest_ip : NULL,
> NULL);
> if (t == 0) return -1;
>
> --
> 2.2.2
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://lists.samba.org/pipermail/samba-technical/attachments/20150116/b74af1d6/attachment.pgp>
More information about the samba-technical
mailing list