Some patches to compile with gcc-next
Jeremy Allison
jra at samba.org
Tue Nov 29 23:39:19 UTC 2016
On Wed, Nov 30, 2016 at 11:13:47AM +1300, Douglas Bagnall wrote:
>
> Ah yes. It seems I poorly estimated my available time.
>
> This version uses talloc_asprintf() so the size calculations are all
> hidden away and hopefully correct.
Thanks Douglas,
It's close, but still needs a not-null pointer check after
the talloc_XXX() calls.
i.e.
if (rname == NULL) {
error out somehow...
}
I could fix it for you but I really want to help
Team members write out-of-the-box good patches
(sorry).
Cheers,
Jeremy.
> From 431bac8dc8678da24e2eb8bea8250f495da78c1c Mon Sep 17 00:00:00 2001
> From: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
> Date: Tue, 1 Nov 2016 14:18:38 +1300
> Subject: [PATCH] smbclient: fix string formatting in print command
>
> At one time, the variables lname and rname were char arrays, but now they
> are pointers. When they were arrays, sizeof(rname) was the length of the
> array, but now it gives the size of the pointer which is not what we want.
>
> In the case where the filename is -, rname was alloced as size 1, which
> could never fit the name it wanted to have contain ("stdin-<pid>").
>
> Signed-off-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
> ---
> source4/client/client.c | 18 ++++++++++--------
> 1 file changed, 10 insertions(+), 8 deletions(-)
>
> diff --git a/source4/client/client.c b/source4/client/client.c
> index 4807123..7ef1a0e 100644
> --- a/source4/client/client.c
> +++ b/source4/client/client.c
> @@ -1535,14 +1535,16 @@ static int cmd_print(struct smbclient_context *ctx, const char **args)
>
> lname = talloc_strdup(ctx, args[1]);
>
> - rname = talloc_strdup(ctx, lname);
> - p = strrchr_m(rname,'/');
> - if (p) {
> - slprintf(rname, sizeof(rname)-1, "%s-%d", p+1, (int)getpid());
> - }
> -
> - if (strequal(lname,"-")) {
> - slprintf(rname, sizeof(rname)-1, "stdin-%d", (int)getpid());
> + if (strequal(lname, "-")) {
> + rname = talloc_asprintf(ctx, "stdin-%d", (int)getpid());
> + } else {
> + p = strrchr_m(lname, '/');
> + if (p) {
> + rname = talloc_asprintf(ctx, "%s-%d", p + 1,
> + (int)getpid());
> + } else {
> + rname = talloc_strdup(ctx, lname);
> + }
> }
>
> return do_put(ctx, rname, lname, false);
> --
> 2.7.4
>
More information about the samba-technical
mailing list