[lxc-devel] [lxc/master] proposed fix for #2892 - fix lxcbasename in lxc/lxccontainer.c

promlow on Github lxc-bot at linuxcontainers.org
Wed Jun 5 19:16:36 UTC 2019


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 603 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20190605/4dc56935/attachment.bin>
-------------- next part --------------
From 85e02f56000be3bc41859a15ccac7c57c3baf92b Mon Sep 17 00:00:00 2001
From: Paul Romlow <paul at romlow.com>
Date: Wed, 5 Jun 2019 13:28:21 -0500
Subject: [PATCH] proposed fix for #2892 - fix lxcbasename in
 lxc/lxccontainer.c

Signed-off-by: Paul Romlow <paul at romlow.com>
---
 src/lxc/lxccontainer.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c
index 9dbc6e022f..253f07f683 100644
--- a/src/lxc/lxccontainer.c
+++ b/src/lxc/lxccontainer.c
@@ -1320,12 +1320,13 @@ static struct lxc_storage *do_storage_create(struct lxc_container *c,
 	return bdev;
 }
 
-static char *lxcbasename(char *path)
+/* Strip path and return name of file for argv[0] passed to execvp */
+static char *lxctemplatefilename(char *tpath)
 {
 	char *p;
 
-	p = path + strlen(path) - 1;
-	while (*p != '/' && p > path)
+	p = tpath + strlen(tpath) - 1;
+	while ( (p-1) >= tpath && *(p-1) != '/')
 		p--;
 
 	return p;
@@ -1451,7 +1452,7 @@ static bool create_run_template(struct lxc_container *c, char *tpath,
 		newargv = malloc(nargs * sizeof(*newargv));
 		if (!newargv)
 			_exit(EXIT_FAILURE);
-		newargv[0] = lxcbasename(tpath);
+		newargv[0] = lxctemplatefilename(tpath);
 
 		/* --path */
 		len = strlen(c->config_path) + strlen(c->name) + strlen("--path=") + 2;


More information about the lxc-devel mailing list