提高http/rtsp header解析兼容性 (#2670 #2693)

This commit is contained in:
夏楚 2023-07-22 17:31:02 +08:00 committed by GitHub
parent 09aa38334e
commit a97f1e503d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -48,8 +48,13 @@ void Parser::parse(const char *buf, size_t size) {
clear(); clear();
auto ptr = buf; auto ptr = buf;
while (true) { while (true) {
auto next_line = strstr(ptr, "\r\n"); auto next_line = strchr(ptr, '\n');
CHECK(next_line); auto offset = 1;
CHECK(next_line && next_line > ptr);
if (*(next_line - 1) == '\r') {
next_line -= 1;
offset = 2;
}
if (ptr == buf) { if (ptr == buf) {
auto blank = strchr(ptr, ' '); auto blank = strchr(ptr, ' ');
CHECK(blank > ptr && blank < next_line); CHECK(blank > ptr && blank < next_line);
@ -76,7 +81,7 @@ void Parser::parse(const char *buf, size_t size) {
} }
_headers.emplace_force(trim(std::move(key)), trim(std::move(value))); _headers.emplace_force(trim(std::move(key)), trim(std::move(value)));
} }
ptr = next_line + 2; ptr = next_line + offset;
if (strncmp(ptr, "\r\n", 2) == 0) { // 协议解析完毕 if (strncmp(ptr, "\r\n", 2) == 0) { // 协议解析完毕
_content.assign(ptr + 2, buf + size); _content.assign(ptr + 2, buf + size);
break; break;