sdp: check for token-char in C++ style
BUG=None
Change-Id: I391711b479dd82aa094248a2d47d61ebe90a29a8
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/237600
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Commit-Queue: Philipp Hancke <philipp.hancke@googlemail.com>
Cr-Commit-Position: refs/heads/main@{#35343}
diff --git a/modules/rtp_rtcp/include/rtp_rtcp_defines.cc b/modules/rtp_rtcp/include/rtp_rtcp_defines.cc
index 5aa41fc..78e730f 100644
--- a/modules/rtp_rtcp/include/rtp_rtcp_defines.cc
+++ b/modules/rtp_rtcp/include/rtp_rtcp_defines.cc
@@ -25,6 +25,9 @@
constexpr size_t kMidRsidMaxSize = 16;
// Check if passed character is a "token-char" from RFC 4566.
+// https://datatracker.ietf.org/doc/html/rfc4566#section-9
+// token-char = %x21 / %x23-27 / %x2A-2B / %x2D-2E / %x30-39
+// / %x41-5A / %x5E-7E
bool IsTokenChar(char ch) {
return ch == 0x21 || (ch >= 0x23 && ch <= 0x27) || ch == 0x2a || ch == 0x2b ||
ch == 0x2d || ch == 0x2e || (ch >= 0x30 && ch <= 0x39) ||
diff --git a/pc/webrtc_sdp.cc b/pc/webrtc_sdp.cc
index 6def54a..8439616 100644
--- a/pc/webrtc_sdp.cc
+++ b/pc/webrtc_sdp.cc
@@ -107,14 +107,15 @@
// <type>=<value>
// where <type> MUST be exactly one case-significant character.
-// Legal characters in a <token> value (RFC 4566 section 9):
+// Check if passed character is a "token-char" from RFC 4566.
+// https://datatracker.ietf.org/doc/html/rfc4566#section-9
// token-char = %x21 / %x23-27 / %x2A-2B / %x2D-2E / %x30-39
// / %x41-5A / %x5E-7E
-static const char kLegalTokenCharacters[] =
- "!#$%&'*+-." // %x21, %x23-27, %x2A-2B, %x2D-2E
- "0123456789" // %x30-39
- "ABCDEFGHIJKLMNOPQRSTUVWXYZ" // %x41-5A
- "^_`abcdefghijklmnopqrstuvwxyz{|}~"; // %x5E-7E
+bool IsTokenChar(char ch) {
+ return ch == 0x21 || (ch >= 0x23 && ch <= 0x27) || ch == 0x2a || ch == 0x2b ||
+ ch == 0x2d || ch == 0x2e || (ch >= 0x30 && ch <= 0x39) ||
+ (ch >= 0x41 && ch <= 0x5a) || (ch >= 0x5e && ch <= 0x7e);
+}
static const int kLinePrefixLength = 2; // Length of <type>=
static const char kLineTypeVersion = 'v';
static const char kLineTypeOrigin = 'o';
@@ -637,7 +638,7 @@
if (!GetValue(message, attribute, value, error)) {
return false;
}
- if (strspn(value->c_str(), kLegalTokenCharacters) != value->size()) {
+ if (!absl::c_all_of(absl::string_view(*value), IsTokenChar)) {
rtc::StringBuilder description;
description << "Illegal character found in the value of " << attribute;
return ParseFailed(message, description.Release(), error);