Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(303)

Unified Diff: webrtc/pc/webrtcsdp.cc

Issue 2675273003: Fixing SDP parsing crash due to invalid port numbers. (Closed)
Patch Set: IsValidPort function Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webrtc/base/socketaddress.h ('k') | webrtc/pc/webrtcsdp_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/pc/webrtcsdp.cc
diff --git a/webrtc/pc/webrtcsdp.cc b/webrtc/pc/webrtcsdp.cc
index 11eefe5c3d5098f88ce8a884c5535d7dd14248cf..79378b10aa76d031d4572475b41bc36af2a05699 100644
--- a/webrtc/pc/webrtcsdp.cc
+++ b/webrtc/pc/webrtcsdp.cc
@@ -79,6 +79,8 @@ namespace cricket {
class SessionDescription;
}
+// TODO(deadbeef): Switch to using anonymous namespace rather than declaring
+// everything "static".
namespace webrtc {
// Line type
@@ -790,6 +792,10 @@ static void GetCandidatesByMindex(const SessionDescriptionInterface& desci,
}
}
+static bool IsValidPort(int port) {
+ return port >= 0 && port <= 65535;
+}
+
std::string SdpSerialize(const JsepSessionDescription& jdesc,
bool unified_plan_sdp) {
const cricket::SessionDescription* desc = jdesc.description();
@@ -1026,6 +1032,9 @@ bool ParseCandidate(const std::string& message, Candidate* candidate,
if (!GetValueFromString(first_line, fields[5], &port, error)) {
return false;
}
+ if (!IsValidPort(port)) {
+ return ParseFailed(first_line, "Invalid port number.", error);
+ }
SocketAddress address(connection_address, port);
cricket::ProtocolType protocol;
@@ -1072,6 +1081,9 @@ bool ParseCandidate(const std::string& message, Candidate* candidate,
first_line, fields[++current_position], &port, error)) {
return false;
}
+ if (!IsValidPort(port)) {
+ return ParseFailed(first_line, "Invalid port number.", error);
+ }
related_address.SetPort(port);
++current_position;
}
« no previous file with comments | « webrtc/base/socketaddress.h ('k') | webrtc/pc/webrtcsdp_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698