Some patches to compile with gcc-next
Jeremy Allison
jra at samba.org
Wed Nov 30 17:05:13 UTC 2016
On Wed, Nov 30, 2016 at 02:35:29PM +1300, Douglas Bagnall wrote:
> On 30/11/16 12:39, Jeremy Allison wrote:
> > 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).
>
> Fair enough. My feeble excuse is I was following the existing practice
> in the source4 smb_client.
No worries, I'm trying to (slowly) improve the code :-).
Close enough, pushed (with one minor change, the check for
rname == NULL can be moved out of both if clauses, as rname
is always allocated in every code path).
Cheers,
Jeremy
> From 8aa95b4533f8d2c5eb1ba916bce58dcbc03bf262 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 | 28 +++++++++++++++++++++-------
> 1 file changed, 21 insertions(+), 7 deletions(-)
>
> diff --git a/source4/client/client.c b/source4/client/client.c
> index 4807123..7f07c8c 100644
> --- a/source4/client/client.c
> +++ b/source4/client/client.c
> @@ -1534,15 +1534,29 @@ 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 (lname == NULL) {
> + d_printf("Out of memory in cmd_print\n");
> + return 1;
> }
>
> - if (strequal(lname,"-")) {
> - slprintf(rname, sizeof(rname)-1, "stdin-%d", (int)getpid());
> + if (strequal(lname, "-")) {
> + rname = talloc_asprintf(ctx, "stdin-%d", (int)getpid());
> + if (rname == NULL) {
> + d_printf("Out of memory in cmd_print (stdin)\n");
> + return 1;
> + }
> + } else {
> + p = strrchr_m(lname, '/');
> + if (p) {
> + rname = talloc_asprintf(ctx, "%s-%d", p + 1,
> + (int)getpid());
> + } else {
> + rname = talloc_strdup(ctx, lname);
> + }
> + if (rname == NULL) {
> + d_printf("Out of memory in cmd_print (rname)\n");
> + return 1;
> + }
> }
>
> return do_put(ctx, rname, lname, false);
> --
> 2.7.4
>
More information about the samba-technical
mailing list