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
This commit is contained in:
Philipp Maier
2018-01-20 00:15:12 +01:00
committed by Harald Welte
parent e9d645b3b3
commit abe8c897fd
3 changed files with 5 additions and 3 deletions

View File

@@ -68,6 +68,9 @@ static inline int mgcp_msg_terminate_nul(struct msgb *msg)
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

View File

@@ -29,7 +29,7 @@ typedef unsigned int mgcp_trans_id_t;
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];
};

View File

@@ -139,13 +139,12 @@ static int mgcp_response_parse_head(struct mgcp_response *r, struct msgb *msg)
&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: