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.orgReview at https://gerrit.osmocom.org/5935 client: eliminate destructive parameter parsing The function mgcp_response_parse_params() that is used to parse the SDP parameters edits the content of the r->body. - Create a local copy of r->body and work on this copy to keep the original r-body in its original state. Change-Id: Ia475036f7f3802b1638e0511a5e9162fea1592eb --- M src/libosmo-mgcp-client/mgcp_client.c 1 file changed, 19 insertions(+), 14 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmo-mgw refs/changes/35/5935/1 diff --git a/src/libosmo-mgcp-client/mgcp_client.c b/src/libosmo-mgcp-client/mgcp_client.c index fa59a61..494b09a 100644 --- a/src/libosmo-mgcp-client/mgcp_client.c +++ b/src/libosmo-mgcp-client/mgcp_client.c @@ -244,24 +244,25 @@ int rc; OSMO_ASSERT(r->body); char *data = mgcp_find_section_end(r->body); + char *data_ptr; - /* Warning: This function performs a destructive parsing on r->body. - * Since this function is called at the very end of the persing - * process, destructive parsing is acceptable. */ + /* Since this functions performs a destructive parsing, we create a + * local copy of the body data */ + data = talloc_zero_size(NULL, strlen(r->body)+1); + OSMO_ASSERT(data); + data_ptr = data; + osmo_strlcpy(data, r->body, strlen(r->body)); + /* Find beginning of the parameter (SDP) section */ + data_ptr = mgcp_find_section_end(data); if (!data) { LOGP(DLMGCP, LOGL_ERROR, "MGCP response: cannot find start of parameters\n"); - return -EINVAL; + rc = -EINVAL; + goto exit; } - /* Advance to after the \n\n, replace the second \n with \0. That's - * where the parameters start. */ - data ++; - *data = '\0'; - data ++; - - for_each_non_empty_line(line, data) { + for_each_non_empty_line(line, data_ptr) { if (!mgcp_line_is_valid(line)) return -EINVAL; @@ -269,19 +270,23 @@ case 'm': rc = mgcp_parse_audio_port(r, line); if (rc) - return rc; + goto exit; break; case 'c': rc = mgcp_parse_audio_ip(r, line); if (rc) - return rc; + goto exit; break; default: /* skip unhandled parameters */ break; } } - return 0; + + rc = 0; +exit: + talloc_free(data); + return rc; } /* Parse a line like "X: something" */ -- To view, visit https://gerrit.osmocom.org/5935 To unsubscribe, visit https://gerrit.osmocom.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ia475036f7f3802b1638e0511a5e9162fea1592eb Gerrit-PatchSet: 1 Gerrit-Project: osmo-mgw Gerrit-Branch: master Gerrit-Owner: dexter <pmaier at sysmocom.de>