[CRIU] [PATCH 1/2] zdtm:mnt_ext_auto: avoid segfault if ZDTM_NEWNS is not set

Dmitrii Shcherbakov dshcherbakov at virtuozzo.com
Mon Nov 21 01:54:14 PST 2016


If getenv returns a null pointer we get a segfault here.

Let's exit in a more sane way.

Signed-off-by: Dmitrii Shcherbakov <dshcherbakov at virtuozzo.com>
---
 test/zdtm/static/mnt_ext_auto.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/test/zdtm/static/mnt_ext_auto.c b/test/zdtm/static/mnt_ext_auto.c
index c361b97..44d774b 100644
--- a/test/zdtm/static/mnt_ext_auto.c
+++ b/test/zdtm/static/mnt_ext_auto.c
@@ -28,6 +28,7 @@ int main(int argc, char ** argv)
 	char src[PATH_MAX], dst[PATH_MAX], *root;
 	char *dname = "/tmp/zdtm_ext_auto.XXXXXX";
 	struct stat sta, stb;
+	char* zdtm_newns = getenv("ZDTM_NEWNS");
 
 	root = getenv("ZDTM_ROOT");
 	if (root == NULL) {
@@ -37,8 +38,12 @@ int main(int argc, char ** argv)
 
 	sprintf(dst, "%s/%s", get_current_dir_name(), dirname);
 
-	if (strcmp(getenv("ZDTM_NEWNS"), "1"))
+	if (!zdtm_newns) {
+		pr_perror("ZDTM_NEWNS is not set");
+		return 1;
+	} else if (strcmp(zdtm_newns, "1")) {
 		goto test;
+	}
 
 	mkdir(dname, 755);
 	sprintf(src, "%s/%s", dname, DDIR);
-- 
2.7.4



More information about the CRIU mailing list