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

Unified Diff: webkit/plugins/ppapi/ppb_websocket_impl.cc

Issue 8839003: WebSocket Pepper API: validate redundant protocols in Connect() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase for dcommit Created 9 years 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 | « ppapi/tests/test_websocket.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webkit/plugins/ppapi/ppb_websocket_impl.cc
diff --git a/webkit/plugins/ppapi/ppb_websocket_impl.cc b/webkit/plugins/ppapi/ppb_websocket_impl.cc
index f460aea11cd33f2eba2b9a4119aa929730330830..48bc1f56580a883572947b659e5b2d5f67e5657d 100644
--- a/webkit/plugins/ppapi/ppb_websocket_impl.cc
+++ b/webkit/plugins/ppapi/ppb_websocket_impl.cc
@@ -4,6 +4,7 @@
#include "webkit/plugins/ppapi/ppb_websocket_impl.h"
+#include <set>
#include <string>
#include "base/basictypes.h"
@@ -144,16 +145,25 @@ int32_t PPB_WebSocket_Impl::Connect(PP_Var url,
WebURL web_url(gurl);
// Validate protocols and convert it to WebString.
- // TODO(toyoshim): Detect duplicated protocols as error.
std::string protocol_string;
+ std::set<std::string> protocol_set;
for (uint32_t i = 0; i < protocol_count; i++) {
// TODO(toyoshim): Similar function exist in WebKit::WebSocket.
// We must rearrange them into WebKit::WebChannel and share its protocol
// related implementation via WebKit API.
scoped_refptr<StringVar> string_var;
string_var = StringVar::FromPPVar(protocols[i]);
+
+ // Check duplicated protocol entries.
+ if (protocol_set.find(string_var->value()) != protocol_set.end())
+ return PP_ERROR_BADARGUMENT;
+ protocol_set.insert(string_var->value());
+
+ // Check invalid and empty entries.
if (!string_var || !string_var->value().length())
return PP_ERROR_BADARGUMENT;
+
+ // Check containing characters.
for (std::string::const_iterator it = string_var->value().begin();
it != string_var->value().end();
++it) {
@@ -172,6 +182,7 @@ int32_t PPB_WebSocket_Impl::Connect(PP_Var url,
character == '{' || character == '}')
return PP_ERROR_BADARGUMENT;
}
+ // Join protocols with the comma separator.
if (i != 0)
protocol_string.append(",");
protocol_string.append(string_var->value());
« no previous file with comments | « ppapi/tests/test_websocket.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698