linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/4] bootconfig: Fix quote-character issue and return value
@ 2020-06-16 10:13 Masami Hiramatsu
  2020-06-16 10:14 ` [PATCH v2 1/4] proc/bootconfig: Fix to use correct quotes for value Masami Hiramatsu
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Masami Hiramatsu @ 2020-06-16 10:13 UTC (permalink / raw)
  To: Steven Rostedt; +Cc: stable, LKML

Hi,

This is the 2nd version of bootconfig bugfixes.
The previous version is here.

https://lkml.kernel.org/r/159197538852.80267.10091816844311950396.stgit@devnote2

This version fixes the patch description and modify(cleanup) code
according to Steve's comment.

Thank you,

---

Masami Hiramatsu (4):
      proc/bootconfig: Fix to use correct quotes for value
      tools/bootconfig: Fix to use correct quotes for value
      tools/bootconfig: Fix to return 0 if succeeded to show the bootconfig
      tools/bootconfig: Add testcase for show-command and quotes test


 fs/proc/bootconfig.c                |   15 ++++++++++-----
 tools/bootconfig/main.c             |   24 ++++++++++++++----------
 tools/bootconfig/test-bootconfig.sh |   10 ++++++++++
 3 files changed, 34 insertions(+), 15 deletions(-)

--
Masami Hiramatsu (Linaro) <mhiramat@kernel.org>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2 1/4] proc/bootconfig: Fix to use correct quotes for value
  2020-06-16 10:13 [PATCH v2 0/4] bootconfig: Fix quote-character issue and return value Masami Hiramatsu
@ 2020-06-16 10:14 ` Masami Hiramatsu
  2020-06-16 10:14 ` [PATCH v2 2/4] tools/bootconfig: " Masami Hiramatsu
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Masami Hiramatsu @ 2020-06-16 10:14 UTC (permalink / raw)
  To: Steven Rostedt; +Cc: stable, LKML

Fix /proc/bootconfig to select double or single quotes
corrctly according to the value.

If a bootconfig value includes a double quote character,
we must use single-quotes to quote that value.

This modifies if() condition and blocks for avoiding
double-quote in value check in 2 places. Anyway, since
xbc_array_for_each_value() can handle the array which
has a single node correctly.
Thus,

if (vnode && xbc_node_is_array(vnode)) {
	xbc_array_for_each_value(vnode)	/* vnode->next != NULL */
		...
} else {
	snprintf(val); /* val is an empty string if !vnode */
}

is equivalent to

if (vnode) {
	xbc_array_for_each_value(vnode)	/* vnode->next can be NULL */
		...
} else {
	snprintf("");	/* value is always empty */
}

Fixes: c1a3c36017d4 ("proc: bootconfig: Add /proc/bootconfig to show boot config list")
Cc: stable@vger.kernel.org
Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
 Changes in v2:
  - Sort local vars definition as upside-down xmas tree format.
  - Fix patch description (typo and add comments)
---
 fs/proc/bootconfig.c |   15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/fs/proc/bootconfig.c b/fs/proc/bootconfig.c
index 9955d75c0585..ad31ec4ad627 100644
--- a/fs/proc/bootconfig.c
+++ b/fs/proc/bootconfig.c
@@ -26,8 +26,9 @@ static int boot_config_proc_show(struct seq_file *m, void *v)
 static int __init copy_xbc_key_value_list(char *dst, size_t size)
 {
 	struct xbc_node *leaf, *vnode;
-	const char *val;
 	char *key, *end = dst + size;
+	const char *val;
+	char q;
 	int ret = 0;
 
 	key = kzalloc(XBC_KEYLEN_MAX, GFP_KERNEL);
@@ -41,16 +42,20 @@ static int __init copy_xbc_key_value_list(char *dst, size_t size)
 			break;
 		dst += ret;
 		vnode = xbc_node_get_child(leaf);
-		if (vnode && xbc_node_is_array(vnode)) {
+		if (vnode) {
 			xbc_array_for_each_value(vnode, val) {
-				ret = snprintf(dst, rest(dst, end), "\"%s\"%s",
-					val, vnode->next ? ", " : "\n");
+				if (strchr(val, '"'))
+					q = '\'';
+				else
+					q = '"';
+				ret = snprintf(dst, rest(dst, end), "%c%s%c%s",
+					q, val, q, vnode->next ? ", " : "\n");
 				if (ret < 0)
 					goto out;
 				dst += ret;
 			}
 		} else {
-			ret = snprintf(dst, rest(dst, end), "\"%s\"\n", val);
+			ret = snprintf(dst, rest(dst, end), "\"\"\n");
 			if (ret < 0)
 				break;
 			dst += ret;


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v2 2/4] tools/bootconfig: Fix to use correct quotes for value
  2020-06-16 10:13 [PATCH v2 0/4] bootconfig: Fix quote-character issue and return value Masami Hiramatsu
  2020-06-16 10:14 ` [PATCH v2 1/4] proc/bootconfig: Fix to use correct quotes for value Masami Hiramatsu
@ 2020-06-16 10:14 ` Masami Hiramatsu
  2020-06-16 10:14 ` [PATCH v2 3/4] tools/bootconfig: Fix to return 0 if succeeded to show the bootconfig Masami Hiramatsu
  2020-06-16 10:14 ` [PATCH v2 4/4] tools/bootconfig: Add testcase for show-command and quotes test Masami Hiramatsu
  3 siblings, 0 replies; 5+ messages in thread
From: Masami Hiramatsu @ 2020-06-16 10:14 UTC (permalink / raw)
  To: Steven Rostedt; +Cc: stable, LKML

Fix bootconfig tool to select double or single quotes
correctly according to the value.

If a bootconfig value includes a double quote character,
we must use single-quotes to quote that value.

Fixes: 950313ebf79c ("tools: bootconfig: Add bootconfig command")
Cc: stable@vger.kernel.org
Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
  Changes in v2:
   - Fix patch description.
---
 tools/bootconfig/main.c |   14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/tools/bootconfig/main.c b/tools/bootconfig/main.c
index 0efaf45f7367..21896a6675fd 100644
--- a/tools/bootconfig/main.c
+++ b/tools/bootconfig/main.c
@@ -14,13 +14,18 @@
 #include <linux/kernel.h>
 #include <linux/bootconfig.h>
 
-static int xbc_show_array(struct xbc_node *node)
+static int xbc_show_value(struct xbc_node *node)
 {
 	const char *val;
+	char q;
 	int i = 0;
 
 	xbc_array_for_each_value(node, val) {
-		printf("\"%s\"%s", val, node->next ? ", " : ";\n");
+		if (strchr(val, '"'))
+			q = '\'';
+		else
+			q = '"';
+		printf("%c%s%c%s", q, val, q, node->next ? ", " : ";\n");
 		i++;
 	}
 	return i;
@@ -48,10 +53,7 @@ static void xbc_show_compact_tree(void)
 			continue;
 		} else if (cnode && xbc_node_is_value(cnode)) {
 			printf("%s = ", xbc_node_get_data(node));
-			if (cnode->next)
-				xbc_show_array(cnode);
-			else
-				printf("\"%s\";\n", xbc_node_get_data(cnode));
+			xbc_show_value(cnode);
 		} else {
 			printf("%s;\n", xbc_node_get_data(node));
 		}


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v2 3/4] tools/bootconfig: Fix to return 0 if succeeded to show the bootconfig
  2020-06-16 10:13 [PATCH v2 0/4] bootconfig: Fix quote-character issue and return value Masami Hiramatsu
  2020-06-16 10:14 ` [PATCH v2 1/4] proc/bootconfig: Fix to use correct quotes for value Masami Hiramatsu
  2020-06-16 10:14 ` [PATCH v2 2/4] tools/bootconfig: " Masami Hiramatsu
@ 2020-06-16 10:14 ` Masami Hiramatsu
  2020-06-16 10:14 ` [PATCH v2 4/4] tools/bootconfig: Add testcase for show-command and quotes test Masami Hiramatsu
  3 siblings, 0 replies; 5+ messages in thread
From: Masami Hiramatsu @ 2020-06-16 10:14 UTC (permalink / raw)
  To: Steven Rostedt; +Cc: stable, LKML

Fix bootconfig to return 0 if succeeded to show the bootconfig
in initrd. Without this fix, "bootconfig INITRD" command
returns !0 even if the command succeeded to show the bootconfig.

Fixes: 950313ebf79c ("tools: bootconfig: Add bootconfig command")
Cc: stable@vger.kernel.org
Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
  Changes in v2:
   - Use goto for better reading.
---
 tools/bootconfig/main.c |   10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/tools/bootconfig/main.c b/tools/bootconfig/main.c
index 21896a6675fd..e0878f5f74b1 100644
--- a/tools/bootconfig/main.c
+++ b/tools/bootconfig/main.c
@@ -207,11 +207,13 @@ int show_xbc(const char *path)
 	}
 
 	ret = load_xbc_from_initrd(fd, &buf);
-	if (ret < 0)
+	if (ret < 0) {
 		pr_err("Failed to load a boot config from initrd: %d\n", ret);
-	else
-		xbc_show_compact_tree();
-
+		goto out;
+	}
+	xbc_show_compact_tree();
+	ret = 0;
+out:
 	close(fd);
 	free(buf);
 


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v2 4/4] tools/bootconfig: Add testcase for show-command and quotes test
  2020-06-16 10:13 [PATCH v2 0/4] bootconfig: Fix quote-character issue and return value Masami Hiramatsu
                   ` (2 preceding siblings ...)
  2020-06-16 10:14 ` [PATCH v2 3/4] tools/bootconfig: Fix to return 0 if succeeded to show the bootconfig Masami Hiramatsu
@ 2020-06-16 10:14 ` Masami Hiramatsu
  3 siblings, 0 replies; 5+ messages in thread
From: Masami Hiramatsu @ 2020-06-16 10:14 UTC (permalink / raw)
  To: Steven Rostedt; +Cc: stable, LKML

Add testcases for the return value of the command to show
bootconfig in initrd, and double/single quotes selecting.

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
  Changes in v2:
   - Update patch description.
---
 tools/bootconfig/test-bootconfig.sh |   10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/tools/bootconfig/test-bootconfig.sh b/tools/bootconfig/test-bootconfig.sh
index eff16b77d5eb..3c2ab9e75730 100755
--- a/tools/bootconfig/test-bootconfig.sh
+++ b/tools/bootconfig/test-bootconfig.sh
@@ -55,6 +55,9 @@ echo "Apply command test"
 xpass $BOOTCONF -a $TEMPCONF $INITRD
 new_size=$(stat -c %s $INITRD)
 
+echo "Show command test"
+xpass $BOOTCONF $INITRD
+
 echo "File size check"
 xpass test $new_size -eq $(expr $bconf_size + $initrd_size + 9 + 12)
 
@@ -114,6 +117,13 @@ xpass grep -q "bar" $OUTFILE
 xpass grep -q "baz" $OUTFILE
 xpass grep -q "qux" $OUTFILE
 
+echo "Double/single quotes test"
+echo "key = '\"string\"';" > $TEMPCONF
+$BOOTCONF -a $TEMPCONF $INITRD
+$BOOTCONF $INITRD > $TEMPCONF
+cat $TEMPCONF
+xpass grep \'\"string\"\' $TEMPCONF
+
 echo "=== expected failure cases ==="
 for i in samples/bad-* ; do
   xfail $BOOTCONF -a $i $INITRD


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-06-16 10:14 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-16 10:13 [PATCH v2 0/4] bootconfig: Fix quote-character issue and return value Masami Hiramatsu
2020-06-16 10:14 ` [PATCH v2 1/4] proc/bootconfig: Fix to use correct quotes for value Masami Hiramatsu
2020-06-16 10:14 ` [PATCH v2 2/4] tools/bootconfig: " Masami Hiramatsu
2020-06-16 10:14 ` [PATCH v2 3/4] tools/bootconfig: Fix to return 0 if succeeded to show the bootconfig Masami Hiramatsu
2020-06-16 10:14 ` [PATCH v2 4/4] tools/bootconfig: Add testcase for show-command and quotes test Masami Hiramatsu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).