[PATCH] osmo-mgw[master]: client: eliminate destructive head parsing

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/.

dexter gerrit-no-reply at lists.osmocom.org
Sat Jan 20 00:00:08 UTC 2018


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

client: eliminate destructive head parsing

While parsing the head of an MGCP response the r->body buffer is
manipulated in order to NUL terminate the extracted comment filed.

- Use a static buffer to store and manipulate the comment field.

Change-Id: Ib273c13d6fe7ee042fb4e3b8ed46ac02602226f6
---
M include/osmocom/mgcp/mgcp_common.h
M include/osmocom/mgcp_client/mgcp_client.h
M src/libosmo-mgcp-client/mgcp_client.c
3 files changed, 5 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-mgw refs/changes/36/5936/1

diff --git a/include/osmocom/mgcp/mgcp_common.h b/include/osmocom/mgcp/mgcp_common.h
index 7aa5d3f..d23339f 100644
--- a/include/osmocom/mgcp/mgcp_common.h
+++ b/include/osmocom/mgcp/mgcp_common.h
@@ -68,6 +68,9 @@
 	return 0;
 }
 
+/* Maximum length of the comment field */
+#define MGCP_COMMENT_MAXLEN 256
+
 /* String length of Connection Identifiers
  * (see also RFC3435 2.1.3.2 Names of Connections) */
 #define MGCP_CONN_ID_LENGTH 32+1
diff --git a/include/osmocom/mgcp_client/mgcp_client.h b/include/osmocom/mgcp_client/mgcp_client.h
index 676850f..73f3bba 100644
--- a/include/osmocom/mgcp_client/mgcp_client.h
+++ b/include/osmocom/mgcp_client/mgcp_client.h
@@ -29,7 +29,7 @@
 struct mgcp_response_head {
 	int response_code;
 	mgcp_trans_id_t trans_id;
-	const char *comment;
+	char comment[MGCP_COMMENT_MAXLEN];
 	char conn_id[MGCP_CONN_ID_LENGTH];
 	char endpoint[MGCP_ENDPOINT_MAXLEN];
 };
diff --git a/src/libosmo-mgcp-client/mgcp_client.c b/src/libosmo-mgcp-client/mgcp_client.c
index 494b09a..13c6529 100644
--- a/src/libosmo-mgcp-client/mgcp_client.c
+++ b/src/libosmo-mgcp-client/mgcp_client.c
@@ -139,13 +139,12 @@
 		   &comment_pos) != 2)
 		goto response_parse_failure;
 
-	r->head.comment = r->body + comment_pos;
+	osmo_strlcpy(r->head.comment, r->body + comment_pos, sizeof(r->head.comment));
 	end = strchr(r->head.comment, '\r');
 	if (!end)
 		goto response_parse_failure;
 	/* Mark the end of the comment */
 	*end = '\0';
-	r->body = end + 1;
 	return 0;
 
 response_parse_failure:

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib273c13d6fe7ee042fb4e3b8ed46ac02602226f6
Gerrit-PatchSet: 1
Gerrit-Project: osmo-mgw
Gerrit-Branch: master
Gerrit-Owner: dexter <pmaier at sysmocom.de>



More information about the gerrit-log mailing list