diff options
author | Kevin Harwell <kharwell@digium.com> | 2016-12-08 11:06:24 -0600 |
---|---|---|
committer | Gerrit Code Review <gerrit2@gerrit.digium.api> | 2016-12-08 11:06:24 -0600 |
commit | 5a96e1fb5e0158bf29accff11aea8afea8b40f48 (patch) | |
tree | 25953a28647352a7e676d962eda96072ca986288 | |
parent | c796f00c35c43972bcbfa1cba55a8862f00248a9 (diff) | |
parent | 5c89604a32bff8682587dd67d9cf67a9a2c70598 (diff) |
Merge "res_format_attr_opus: Fix crash when fmtp contains spaces."
-rw-r--r-- | res/res_format_attr_opus.c | 38 |
1 files changed, 23 insertions, 15 deletions
diff --git a/res/res_format_attr_opus.c b/res/res_format_attr_opus.c index 45aa5e5c6..1367f9578 100644 --- a/res/res_format_attr_opus.c +++ b/res/res_format_attr_opus.c @@ -101,27 +101,35 @@ static int opus_clone(const struct ast_format *src, struct ast_format *dst) static void sdp_fmtp_get(const char *attributes, const char *name, int *attr) { - const char *kvp = ""; + const char *kvp = attributes; int val; - if (attributes && !(kvp = strstr(attributes, name))) { + if (ast_strlen_zero(attributes)) { return; } - /* - * If the named attribute is not at the start of the given attributes, and - * the preceding character is not a space or semicolon then it's not the - * attribute we are looking for. It's an attribute with the name embedded - * within it (e.g. ptime in maxptime, stereo in sprop-stereo). + /* This logic goes through each attribute in the fmtp line looking for the + * requested named attribute. */ - if (kvp != attributes && *(kvp - 1) != ' ' && *(kvp - 1) != ';') { - /* Keep searching as it might still be in the attributes string */ - sdp_fmtp_get(strchr(kvp, ';'), name, attr); - /* - * Otherwise it's a match, so retrieve the value and set the attribute. - */ - } else if (sscanf(kvp, "%*[^=]=%30d", &val) == 1) { - *attr = val; + while (*kvp) { + /* Skip any preceeding blanks as some implementations separate attributes using spaces too */ + kvp = ast_skip_blanks(kvp); + + /* If we are at at the requested attribute get its value and return */ + if (!strncmp(kvp, name, strlen(name)) && kvp[strlen(name)] == '=') { + if (sscanf(kvp, "%*[^=]=%30d", &val) == 1) { + *attr = val; + break; + } + } + + /* Move on to the next attribute if possible */ + kvp = strchr(kvp, ';'); + if (!kvp) { + break; + } + + kvp++; } } |