[OpenWrt-Devel] [PATCH] delta: fix parsing malformed delta lines

Yousong Zhou yszhou4tech at gmail.com
Sat Aug 11 02:53:56 EDT 2018


Signed-off-by: Yousong Zhou <yszhou4tech at gmail.com>
---
 delta.c                  |  6 ++++++
 test/tests.d/100_changes | 33 +++++++++++++++++++++++++++++++++
 2 files changed, 39 insertions(+)
 create mode 100644 test/tests.d/100_changes

diff --git a/delta.c b/delta.c
index e9c79ab..386167d 100644
--- a/delta.c
+++ b/delta.c
@@ -163,6 +163,9 @@ static inline int uci_parse_delta_tuple(struct uci_context *ctx, struct uci_ptr
 	int c;
 
 	UCI_INTERNAL(uci_parse_argument, ctx, ctx->pctx->file, &str, &arg);
+	if (str && *str) {
+		goto error;
+	}
 	for (c = 0; c <= __UCI_CMD_LAST; c++) {
 		if (uci_command_char[c] == *arg)
 			break;
@@ -179,6 +182,9 @@ static inline int uci_parse_delta_tuple(struct uci_context *ctx, struct uci_ptr
 		goto error;
 	if (ptr->flags & UCI_LOOKUP_EXTENDED)
 		goto error;
+	if (c != UCI_CMD_REMOVE && !ptr->value) {
+		goto error;
+	}
 
 	switch(c) {
 	case UCI_CMD_REORDER:
diff --git a/test/tests.d/100_changes b/test/tests.d/100_changes
new file mode 100644
index 0000000..6204de8
--- /dev/null
+++ b/test/tests.d/100_changes
@@ -0,0 +1,33 @@
+test_changes_tailing_parts()
+{
+	for c in + '' @ ^ '|' '~'; do
+		touch ${CONFIG_DIR}/network
+		cat >${CHANGES_DIR}/network <<-EOF
+			${c}network.foo bar
+			${c}network.foo bar=baz
+			${c}network.foo.bar baz
+			${c}network.foo.bar baz=bazz
+		EOF
+		val=$(${UCI} changes)
+		assertNotSegFault "$?"
+		assertNull "$val"
+		#cat ${CHANGES_DIR}/network
+	done
+}
+
+test_changes_missing_value()
+{
+	local c
+
+	for c in + '' @ ^ '|' '~'; do
+		touch ${CONFIG_DIR}/network
+		mkdir -p ${CHANGES_DIR}
+		cat >${CHANGES_DIR}/network <<-EOF
+			${c}network.foo
+			${c}network.foo.bar
+		EOF
+		val=$(${UCI} changes)
+		assertNotSegFault "$?"
+		assertNull "$val"
+	done
+}

_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel



More information about the openwrt-devel mailing list