mount: skip '/' only if it is there

Submitted by Andrei Vagin on Oct. 18, 2016, 1:40 a.m.

Details

Message ID 1476754856-26735-1-git-send-email-avagin@openvz.org
State Accepted
Series "mount: skip '/' only if it is there"
Commit 0899745cc910d2614629a27b7ea021ca9a6302d3
Headers show

Commit Message

Andrei Vagin Oct. 18, 2016, 1:40 a.m.
From: Andrei Vagin <avagin@virtuozzo.com>

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?

Reported-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Cc: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
---
 criu/path.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

Patch hide | download patch | download mbox

diff --git a/criu/path.c b/criu/path.c
index c43b5e2..57773d5 100644
--- a/criu/path.c
+++ b/criu/path.c
@@ -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--;
+		if (path[off - 1] == '/') /* p->mountpoint = "./" */
+			off--;
+	}
 	len -= off;
 	path += off;
 

Comments

Kirill Tkhai Oct. 18, 2016, 8:16 a.m.
On 18.10.2016 04:40, Andrei Vagin wrote:
> From: Andrei Vagin <avagin@virtuozzo.com>
> 
> 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?
> 
> Reported-by: Kirill Tkhai <ktkhai@virtuozzo.com>
> Cc: Kirill Tkhai <ktkhai@virtuozzo.com>
> Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>

Acked-by: Kirill Tkhai <ktkhai@virtuozzo.com>

> ---
>  criu/path.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/criu/path.c b/criu/path.c
> index c43b5e2..57773d5 100644
> --- a/criu/path.c
> +++ b/criu/path.c
> @@ -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--;
> +		if (path[off - 1] == '/') /* p->mountpoint = "./" */
> +			off--;
> +	}
>  	len -= off;
>  	path += off;
>  
>
Pavel Emelianov Oct. 19, 2016, 7:28 a.m.
Applied