On Mon, Sep 1, 2008 at 8:34 PM, Abhishek Kulkarni <[EMAIL PROTECTED]> wrote:
> While adding the change directory bit to the namespace buffer, xrx messes up
> the namespace buffer.
>
> [EMAIL PROTECTED]:~/xcpu2$ xrx 0 /bin/date Import 127.0.0.1 /mnt/term
> "9p" 0 access=any,msize=32792,port=36331 NULL
> Bind /mnt/term///Linux/i686 /mnt/sandbox NULL MS_BIND NULL
> Bind /mnt/term/home /mnt/sandbox/home NULL MS_BIND NULL
> Bind /dev /mnt/sandbox/dev NULL MS_BIND NULL
> Bind /proc /mnt/sandbox/proc NULL MS_BIND NULL
> Bind /sys /mnt/sandbox/sys NULL MS_BIND NULL
> chroot /mnt/sandbox
> cd /home/abhishek/xcpu2
> namespace: invalid operation
> xnamespace failed: : No child processes
>
> This patch makes sure we don't have any trailing junk in the namespace
> buffer.
>
> Signed-off-by: Abhishek Kulkarni <[EMAIL PROTECTED]>
>
>
> Index: utils/xrx.c
> ===================================================================
> --- utils/xrx.c (revision 685)
> +++ utils/xrx.c (working copy)
> @@ -396,7 +396,7 @@
>
>         thisarch = getarch();
>         if (getcwd(buf, sizeof(buf)) >= 0)
> -               cwd = strdup(buf);
> +               cwd = strndup(buf, sizeof(buf));
>
>         env = getenv("XCPUENV");
>         if (env)
> @@ -454,8 +454,9 @@
>                         cwd = buf;
>                 }
>
> -               ns = sp_malloc(strlen(default_ns) + strlen(cwd) + 8);
> -               sprintf(ns, "%s\ncd %s\n", default_ns, cwd);
> +               n = strlen(default_ns) + strlen(cwd) + 8;
> +               ns = sp_malloc(n);
> +               snprintf(ns, n, "%s\ncd %s\n", default_ns, cwd);
>         }

assuming that ns (a) gets freed somewhere or (b) the proc exits  or
execs and this is really not a storage leak,

Acked-by: Ronald G. Minnich <[EMAIL PROTECTED]>

Reply via email to