New issue
Advanced search Search tips

Issue 596523 link

Starred by 3 users

Issue metadata

Status: Available
Owner: ----
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: ----
Pri: 3
Type: Task


Sign in to add a comment

Investigate and correct overly permissive parsing in //net due to base::StringToInt()

Project Member Reported by eroman@chromium.org, Mar 21 2016

Issue description

base::StringToInt() is being used in places that expect decimal number strings.

These callers typically want to recognize strings like "345" and "-891".

The problem is StringToInt() accepts other strings like "+34".

Depending on the context, accepting numbers with a leading plus is unexpected and wrong.

This is particularly a problem for protocol parsing code in //net where strictness is important for adhering to standards, so the added convenience in what StringToInt() accepts is not desirable.

A recent example of this is  issue 596258 . But I have also seen this come up in HTTP header parsing reviews for instance (i.e. parsing the HTTP version number).

The default of StringToInt() is not great for //net code, and may be contributing bugs elsewhere. Doing a quick grep through //net shows there are other callers using it which may be problematic.

Possible remedies are:

  (a) Make the policy of permitting a leading + an explicit parameter to base::StringToInt(), to make it obvious to future callers.
  (b) Introduce a //net specific wrapper that does stricter parsing
  (c) Fix each callsite on a one-off basis
 

Comment 1 by eroman@chromium.org, Mar 21 2016

Components: Internals>Network

Comment 2 by eroman@chromium.org, Mar 21 2016

Blockedon: 596258

Comment 3 by eroman@chromium.org, Mar 21 2016

This applies to all of the string-to-int functions. For instance:

  * StringToInt()
  * StringToUint()
  * StringToInt64()
  * StringToUint64()
  * StringToSizeT()

Comment 4 by eroman@chromium.org, Mar 21 2016

Blockedon: 596570

Comment 5 by eroman@chromium.org, Mar 21 2016

Blocking: -596552

Comment 6 by eroman@chromium.org, Mar 21 2016

Blockedon: 596552

Comment 7 by eroman@chromium.org, Mar 21 2016

Having reviewed a number of the current bugs, my proposal is to create helper functions in //net/base for doing simple decimal number parsing.

As the majority of callers are wanting to just parse:
  1*DIGIT

(Don't even need negatives, even though using an "int").

I think the versions in base:: are subtle, but there are enough callers throughout the rest of the codebase that introducing a required parameter at this point will be a big undertaking.

There are also callers (like in WebSockets) that avoid this pitfall of StringToInt() by creating their own wrappers. All of that code could similarly be switched to the generic wrapper.
I agree with your assessment, though you might want to loop in base/ owners for their take. It's possible this is causing subtle bugs elsewhere.

Comment 9 by eroman@chromium.org, Mar 21 2016

Cc: thakis@chromium.org
+thakis for feedback on comment #7 from the perspective of a //base owner.

An alternative to //net specific helpers would be to add a required parameter in //base to help catch this problem elsewhere in the codebase.

Not having reviewed all the other callers of base::StringToInt(), my concern would be most callsites outside of //net don't care about strictness and just want to parse a number (for which this new API would just be kludgy).
Owner: eroman@chromium.org
Status: Assigned (was: Untriaged)
I will proceed with a //net specific solution.

Based on that experience, we can consider generalizing to //base as a follow-up.
Project Member

Comment 12 by bugdroid1@chromium.org, Mar 23 2016

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/1f90fcb579588d6491f04ffc586ba2bf5b2a1653

commit 1f90fcb579588d6491f04ffc586ba2bf5b2a1653
Author: eroman <eroman@chromium.org>
Date: Wed Mar 23 22:28:55 2016

Don't allow negative date components in ParseCertificateDate(), or ones starting with a plus.

BUG=596523,  596544 

Review URL: https://codereview.chromium.org/1832583002

Cr-Commit-Position: refs/heads/master@{#382949}

[modify] https://crrev.com/1f90fcb579588d6491f04ffc586ba2bf5b2a1653/net/cert/x509_cert_types.cc
[modify] https://crrev.com/1f90fcb579588d6491f04ffc586ba2bf5b2a1653/net/cert/x509_cert_types_unittest.cc

Project Member

Comment 13 by bugdroid1@chromium.org, Mar 24 2016

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/55fa65c5ce1c15d8a492d6876b2324fd576a83a4

commit 55fa65c5ce1c15d8a492d6876b2324fd576a83a4
Author: eroman <eroman@chromium.org>
Date: Thu Mar 24 18:57:49 2016

Don't allow a leading plus in ports for proxy bypass rules.

For instance will reject the rule "*.org:+443" whereas before it would be accepted.

BUG=596523,  596570 

Review URL: https://codereview.chromium.org/1831653002

Cr-Commit-Position: refs/heads/master@{#383111}

[modify] https://crrev.com/55fa65c5ce1c15d8a492d6876b2324fd576a83a4/net/proxy/proxy_bypass_rules.cc
[modify] https://crrev.com/55fa65c5ce1c15d8a492d6876b2324fd576a83a4/net/proxy/proxy_bypass_rules_unittest.cc

Owner: ----
Status: Available (was: Assigned)
Labels: -Type-Bug Network-Triaged Type-Task

Sign in to add a comment