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

Unified Diff: net/base/ip_address.cc

Issue 1816903002: Fix ParseCIDRBlock() to no longer accept invalid inputs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: added a TODO Created 4 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
« no previous file with comments | « no previous file | net/base/ip_address_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/base/ip_address.cc
diff --git a/net/base/ip_address.cc b/net/base/ip_address.cc
index 42071e010e358be1b30e46431574de9e5dd116f2..7ae68bf44a951587c5776d966945419306595ffa 100644
--- a/net/base/ip_address.cc
+++ b/net/base/ip_address.cc
@@ -158,9 +158,15 @@ bool ParseCIDRBlock(const std::string& cidr_literal,
if (!ip_address->AssignFromIPLiteral(parts[0]))
return false;
+ // TODO(martijnc): Find a more general solution for the overly permissive
+ // base::StringToInt() parsing. https://crbug.com/596523.
+ const base::StringPiece& prefix_length = parts[1];
+ if (prefix_length.starts_with("+"))
+ return false;
+
// Parse the prefix length.
int number_of_bits = -1;
- if (!base::StringToInt(parts[1], &number_of_bits))
+ if (!base::StringToInt(prefix_length, &number_of_bits))
return false;
// Make sure the prefix length is in a valid range.
« no previous file with comments | « no previous file | net/base/ip_address_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698