mirror of
https://github.com/curl/curl.git
synced 2025-04-12 16:20:35 +08:00
rtsp: error out on empty Session ID, unified the code
This commit is contained in:
parent
77a7b93c25
commit
8bdee98187
36
lib/rtsp.c
36
lib/rtsp.c
@ -776,6 +776,8 @@ CURLcode Curl_rtsp_parseheader(struct connectdata *conn,
|
||||
}
|
||||
else if(checkprefix("Session:", header)) {
|
||||
char *start;
|
||||
char *end;
|
||||
size_t idlen;
|
||||
|
||||
/* Find the first non-space letter */
|
||||
start = header + 8;
|
||||
@ -784,16 +786,21 @@ CURLcode Curl_rtsp_parseheader(struct connectdata *conn,
|
||||
|
||||
if(!*start) {
|
||||
failf(data, "Got a blank Session ID");
|
||||
return CURLE_RTSP_SESSION_ERROR;
|
||||
}
|
||||
else if(data->set.str[STRING_RTSP_SESSION_ID]) {
|
||||
char *end;
|
||||
size_t idlen;
|
||||
|
||||
/* Find the end of Session ID */
|
||||
end = start + 1;
|
||||
while(*end && !ISSPACE(*end))
|
||||
end++;
|
||||
idlen = end - start;
|
||||
/* Find the end of Session ID
|
||||
*
|
||||
* Allow any non whitespace content, up to the field separator or end of
|
||||
* line. RFC 2326 isn't 100% clear on the session ID and for example
|
||||
* gstreamer does url-encoded session ID's not covered by the standard.
|
||||
*/
|
||||
end = start;
|
||||
while(*end && *end != ';' && !ISSPACE(*end))
|
||||
end++;
|
||||
idlen = end - start;
|
||||
|
||||
if(data->set.str[STRING_RTSP_SESSION_ID]) {
|
||||
|
||||
/* If the Session ID is set, then compare */
|
||||
if(strlen(data->set.str[STRING_RTSP_SESSION_ID]) != idlen ||
|
||||
@ -806,21 +813,14 @@ CURLcode Curl_rtsp_parseheader(struct connectdata *conn,
|
||||
else {
|
||||
/* If the Session ID is not set, and we find it in a response, then set
|
||||
* it.
|
||||
*
|
||||
* Allow any non whitespace content, up to the field separator or end of
|
||||
* line. RFC 2326 isn't 100% clear on the session ID and for example
|
||||
* gstreamer does url-encoded session ID's not covered by the standard.
|
||||
*/
|
||||
char *end = start;
|
||||
while(*end && *end != ';' && !ISSPACE(*end))
|
||||
end++;
|
||||
|
||||
/* Copy the id substring into a new buffer */
|
||||
data->set.str[STRING_RTSP_SESSION_ID] = malloc(end - start + 1);
|
||||
data->set.str[STRING_RTSP_SESSION_ID] = malloc(idlen + 1);
|
||||
if(data->set.str[STRING_RTSP_SESSION_ID] == NULL)
|
||||
return CURLE_OUT_OF_MEMORY;
|
||||
memcpy(data->set.str[STRING_RTSP_SESSION_ID], start, end - start);
|
||||
(data->set.str[STRING_RTSP_SESSION_ID])[end - start] = '\0';
|
||||
memcpy(data->set.str[STRING_RTSP_SESSION_ID], start, idlen);
|
||||
(data->set.str[STRING_RTSP_SESSION_ID])[idlen] = '\0';
|
||||
}
|
||||
}
|
||||
return CURLE_OK;
|
||||
|
Loading…
x
Reference in New Issue
Block a user