[lxc-devel] [lxc/master] parse: do not mask failed parse

brauner on Github lxc-bot at linuxcontainers.org
Mon Oct 8 20:54:28 UTC 2018


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 364 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20181008/0f9b54f9/attachment.bin>
-------------- next part --------------
From 576fb366f86f5ae33f1893026e948023476586ae Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Mon, 8 Oct 2018 22:49:57 +0200
Subject: [PATCH 1/2] parse: do not mask failed parse

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 src/lxc/parse.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/lxc/parse.c b/src/lxc/parse.c
index bab842a21..05764b964 100644
--- a/src/lxc/parse.c
+++ b/src/lxc/parse.c
@@ -111,9 +111,11 @@ int lxc_file_for_each_line_mmap(const char *file, lxc_file_cb callback, void *da
 	}
 
 on_error:
-	ret = lxc_strmunmap(buf, st.st_size);
-	if (ret < 0)
+	if (lxc_strmunmap(buf, st.st_size) < 0) {
 		SYSERROR("Failed to unmap config file \"%s\"", file);
+		if (ret == 0)
+			ret = -1;
+	}
 
 	saved_errno = errno;
 	close(fd);

From 646e6c8b465fafde9447c87ca967da9e82f50f7b Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Mon, 8 Oct 2018 22:53:16 +0200
Subject: [PATCH 2/2] test: test invalid config keys

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 src/tests/get_item.c          | 6 ++++++
 src/tests/parse_config_file.c | 5 +++++
 2 files changed, 11 insertions(+)

diff --git a/src/tests/get_item.c b/src/tests/get_item.c
index f4c8d9228..f2757c29d 100644
--- a/src/tests/get_item.c
+++ b/src/tests/get_item.c
@@ -600,6 +600,12 @@ int main(int argc, char *argv[])
 		goto out;
 	}
 
+	if (c->set_config_item(c, "lxc.notaconfigkey", "invalid")) {
+		fprintf(stderr, "%d: Managed to set \"lxc.notaconfigkey\"\n", __LINE__);
+		goto out;
+	}
+
+
 	printf("All get_item tests passed\n");
 	fret = EXIT_SUCCESS;
 
diff --git a/src/tests/parse_config_file.c b/src/tests/parse_config_file.c
index b13982d30..b8b71c8e1 100644
--- a/src/tests/parse_config_file.c
+++ b/src/tests/parse_config_file.c
@@ -778,6 +778,11 @@ int main(int argc, char *argv[])
 		goto non_test_error;
 	}
 
+	if (c->set_config_item(c, "lxc.notaconfigkey", "invalid")) {
+		lxc_error("%s\n", "Managed to set to set invalid config item \"lxc.notaconfigkey\" to \"invalid\"");
+		return -1;
+	}
+
 	fret = EXIT_SUCCESS;
 
 non_test_error:


More information about the lxc-devel mailing list