Commit 6fc5e41f authored by Andrei Vagin's avatar Andrei Vagin Committed by Pavel Emelyanov

mount: skip '/' only if it is there

If p->mountpoint is "/", off will be 0 and we will
try to acess path[-1].

 On Tue, Sep 20, 2016 at 05:17:27PM +0300, Kirill Tkhai wrote:
> >
> > int off = 0;
> >
> > ...
> >
> > if (p->mountpoint[1] != 0) /* not / */
> >    off = snprintf(path, len, %s, p->mountpoint);
> > if (path[off - 1] == '/') /* p->mountpoint = ./ */
> >
> >          ^^^
> > The above looks like off-by-one when off == 0. Is there is
> > a condition which guarantees that off is not zero?

travis-ci: success for mount: skip '/' only if it is there
Reported-by: 's avatarKirill Tkhai <ktkhai@virtuozzo.com>
Cc: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: 's avatarAndrei Vagin <avagin@virtuozzo.com>
Acked-by: 's avatarKirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
parent c3e184f1
......@@ -72,10 +72,11 @@ char *mnt_get_sibling_path(struct mount_info *m,
cut_root = cut_root_for_bind(pa->root, p->root);
if (cut_root == NULL)
return NULL;
if (p->mountpoint[1] != 0) /* not "/" */
if (p->mountpoint[1] != 0) /* not "/" */ {
off = snprintf(path, len, "%s", p->mountpoint);
if (path[off - 1] == '/') /* p->mountpoint = "./" */
off--;
}
len -= off;
path += off;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment