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

Unified Diff: chrome/browser/extensions/api/mdns/mdns_api.cc

Issue 1040773002: Limit number of service instances passed to onServiceList listeners. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add new mdns.getMaxServiceInstancesPerEvent() function and update unit tests Created 5 years, 9 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
Index: chrome/browser/extensions/api/mdns/mdns_api.cc
diff --git a/chrome/browser/extensions/api/mdns/mdns_api.cc b/chrome/browser/extensions/api/mdns/mdns_api.cc
index 2a7c41d210931d1540e61b8cb89fe402a203e1e8..7111a6207eedd64a65b80859816fc6567e8763f2 100644
--- a/chrome/browser/extensions/api/mdns/mdns_api.cc
+++ b/chrome/browser/extensions/api/mdns/mdns_api.cc
@@ -22,6 +22,10 @@ const char kCastServiceType[] = "_googlecast._tcp.local";
const char kPrivetServiceType[] = "_privet._tcp.local";
const char kTestServiceType[] = "_testing._tcp.local";
+// Maximum number of services that may be included in an onServiceList event
+// as arguments.
+const uint8 kMaxServicesPerOnServiceListEvent = 64;
+
bool IsServiceTypeWhitelisted(const std::string& service_type) {
return service_type == kCastServiceType ||
service_type == kPrivetServiceType ||
@@ -140,6 +144,13 @@ void MDnsAPI::OnDnsSdEvent(const std::string& service_type,
std::vector<linked_ptr<mdns::MDnsService> > args;
for (DnsSdRegistry::DnsSdServiceList::const_iterator it = services.begin();
it != services.end(); ++it) {
+ if (args.size() == kMaxServicesPerOnServiceListEvent) {
+ VLOG(logging::LOG_WARNING)
+ << "Truncating service instances reported in onServiceList event to "
+ << "max: "
+ << kMaxServicesPerOnServiceListEvent;
+ break;
+ }
linked_ptr<mdns::MDnsService> mdns_service =
make_linked_ptr(new mdns::MDnsService);
mdns_service->service_name = (*it).service_name;
@@ -162,4 +173,10 @@ void MDnsAPI::OnDnsSdEvent(const std::string& service_type,
extensions::EventRouter::Get(browser_context_)->BroadcastEvent(event.Pass());
}
+ExtensionFunction::ResponseAction
+MdnsGetMaxServiceInstancesPerEventFunction::Run() {
+ return RespondNow(OneArgument(new base::FundamentalValue(
+ kMaxServicesPerOnServiceListEvent)));
+}
+
} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698