diff --git a/src/libosmo-mgcp-client/mgcp_client.c b/src/libosmo-mgcp-client/mgcp_client.c index 60c54a65b..8df65cdc0 100644 --- a/src/libosmo-mgcp-client/mgcp_client.c +++ b/src/libosmo-mgcp-client/mgcp_client.c @@ -323,10 +323,6 @@ static int mgcp_parse_audio_port_pt(struct mgcp_response *r, char *line) pt_str = strtok(line, " "); while (1) { - /* Do not allow excessive payload types */ - if (ptmap_len >= ARRAY_SIZE(r->ptmap)) - goto response_parse_failure_pt; - pt_str = strtok(NULL, " "); if (!pt_str) break; @@ -344,6 +340,10 @@ static int mgcp_parse_audio_port_pt(struct mgcp_response *r, char *line) if (r->ptmap[i].pt == pt) goto response_parse_failure_pt; + /* Do not allow excessive payload types */ + if (ptmap_len >= ARRAY_SIZE(r->ptmap)) + goto response_parse_failure_pt; + /* Some payload type numbers imply a specific codec. For those, using the PT number as enum mgcp_codecs * yields the correct result. If no more specific information on the codec follows in "a=rtpmap:N" * lines, then this default number takes over. This only applies for PT below the dynamic range (<96). */