[PATCH] libosmocore[master]: CTRL: GET parsing: add '\n' as token delimiter

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Neels Hofmeyr gerrit-no-reply at lists.osmocom.org
Tue Sep 26 13:47:48 UTC 2017


Review at  https://gerrit.osmocom.org/4068

CTRL: GET parsing: add '\n' as token delimiter

For GET commands, we expect the command to end after the GET variable name.
However, the token parsing uses a single space as delimiter, potentially
parsing along the line ending.

Add line ending to token delimiters for GET parsing.

Adjust test expectations accordingly.

Change-Id: I33efb56f76cb7a41e94454666e218617e9b713ae
---
M src/ctrl/control_cmd.c
M tests/ctrl/ctrl_test.c
M tests/ctrl/ctrl_test.ok
3 files changed, 5 insertions(+), 5 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/68/4068/1

diff --git a/src/ctrl/control_cmd.c b/src/ctrl/control_cmd.c
index 24b388b..a0476dd 100644
--- a/src/ctrl/control_cmd.c
+++ b/src/ctrl/control_cmd.c
@@ -312,7 +312,7 @@
 
 	switch (cmd->type) {
 		case CTRL_TYPE_GET:
-			var = strtok_r(NULL, " ", &saveptr);
+			var = strtok_r(NULL, " \n", &saveptr);
 			if (!var) {
 				cmd->type = CTRL_TYPE_ERROR;
 				cmd->reply = "GET incomplete";
diff --git a/tests/ctrl/ctrl_test.c b/tests/ctrl/ctrl_test.c
index b8425c7..bf8abae 100644
--- a/tests/ctrl/ctrl_test.c
+++ b/tests/ctrl/ctrl_test.c
@@ -124,14 +124,14 @@
 		{
 			.type = CTRL_TYPE_GET,
 			.id = "1",
-			.variable = "variable\n", /* current bug */
+			.variable = "variable",
 		}
 	},
 	{ "GET 1 var\ni\nable",
 		{
 			.type = CTRL_TYPE_GET,
 			.id = "1",
-			.variable = "var\ni\nable", /* current bug */
+			.variable = "var",
 		}
 	},
 	{ "GET 1 variable value",
diff --git a/tests/ctrl/ctrl_test.ok b/tests/ctrl/ctrl_test.ok
index 9c8877b..bca5f4b 100644
--- a/tests/ctrl/ctrl_test.ok
+++ b/tests/ctrl/ctrl_test.ok
@@ -15,13 +15,13 @@
 ok
 test parsing: 'GET 1 variable\n'
 id = '1'
-variable = 'variable\n'
+variable = 'variable'
 value = NULL
 reply = NULL
 ok
 test parsing: 'GET 1 var\ni\nable'
 id = '1'
-variable = 'var\ni\nable'
+variable = 'var'
 value = NULL
 reply = NULL
 ok

-- 
To view, visit https://gerrit.osmocom.org/4068
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I33efb56f76cb7a41e94454666e218617e9b713ae
Gerrit-PatchSet: 1
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr <nhofmeyr at sysmocom.de>



More information about the gerrit-log mailing list