Bug 176357 - Missing break in URLParser
Summary: Missing break in URLParser
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore Misc. (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Tomas Popela
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2017-09-05 03:01 PDT by Tomas Popela
Modified: 2017-09-27 12:37 PDT (History)
5 users (show)

See Also:


Attachments
Patch (1.38 KB, patch)
2017-09-05 03:04 PDT, Tomas Popela
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Tomas Popela 2017-09-05 03:01:21 PDT
Found by Coverity scan:

1. webkitgtk-2.16.6/Source/WebCore/platform/URLParser.cpp:1233: value_overwrite: Overwriting previous write to "state" with value "void WebCore::URLParser::parse(unsigned short const *, unsigned int, WebCore::URL const &, WebCore::TextEncoding const &)::State::Scheme (instance 69995)".
2. webkitgtk-2.16.6/Source/WebCore/platform/URLParser.cpp:1230: assigned_value: Assigning value "void WebCore::URLParser::parse(unsigned short const *, unsigned int, WebCore::URL const &, WebCore::TextEncoding const &)::State::NoScheme (instance 69996)" to "state" here, but that stored value is overwritten before it can be used.
#  1228|                   if (c.atEnd()) {
#  1229|                       m_asciiBuffer.clear();
#  1230|->                     state = State::NoScheme;
#  1231|                       c = beginAfterControlAndSpace;
#  1232|                   }
Comment 1 Tomas Popela 2017-09-05 03:04:10 PDT
Created attachment 319889 [details]
Patch
Comment 2 Alexey Proskuryakov 2017-09-05 19:49:16 PDT
Comment on attachment 319889 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=319889&action=review

> Source/WebCore/ChangeLog:9
> +        Add a missing break so the currently set state is not overwritten
> +        after the block. Found by Coverity scan.

Does this change observable behavior? If so, please add a test.
Comment 3 Darin Adler 2017-09-05 20:56:46 PDT
Comment on attachment 319889 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=319889&action=review

>> Source/WebCore/ChangeLog:9
>> +        after the block. Found by Coverity scan.
> 
> Does this change observable behavior? If so, please add a test.

Yes, it’s a great catch, but we do want a regression test to show what we were doing wrong!
Comment 4 Tomas Popela 2017-09-06 05:46:41 PDT
(In reply to Darin Adler from comment #3)
> Comment on attachment 319889 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=319889&action=review
> 
> >> Source/WebCore/ChangeLog:9
> >> +        after the block. Found by Coverity scan.
> > 
> > Does this change observable behavior? If so, please add a test.
> 
> Yes, it’s a great catch, but we do want a regression test to show what we
> were doing wrong!

I don't think we need test case if I got the context right:

From looking at the code the sequence to get to the part where the 'break' is missing we have to process the input that contains one character. We will start with state SchemeStart (log this state), process the character (that has to be ASCII lowercase alpha) and append to the buffer. Now we will move to the next character and as there is none (c.atEnd() is true) we will move to the branch with missing 'break'. The state is set to NoScheme, the input restarted, buffer cleared and the state is again changed, but to Scheme (due to missing 'break'). We continue in the loop (!c.atEnd()), now with the Scheme state. The state is logged and the first condition for Scheme case is isValidSchemeCharacter(). We know that the input contains ASCII lowercase alpha and that means that it is also a valid scheme character. The character is appended to the buffer and we move to the next character in the input, but as there is none then the state is set to NoScheme, the input restarted, buffer cleared. We again continue in the loop, now with the state NoScheme. So we got to the same point where we would end with the 'break' added in this patch. So the main difference is that without the 'break' there is an extra log message mentioning Scheme state. I should note that the url parser debugging is disabled by default, so in the default configuration there is no difference while running URLParser with or without this patch.
Comment 5 Darin Adler 2017-09-06 09:08:55 PDT
Comment on attachment 319889 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=319889&action=review

>>>> Source/WebCore/ChangeLog:9
>>>> +        after the block. Found by Coverity scan.
>>> 
>>> Does this change observable behavior? If so, please add a test.
>> 
>> Yes, it’s a great catch, but we do want a regression test to show what we were doing wrong!
> 
> I don't think we need test case if I got the context right:
> 
> From looking at the code the sequence to get to the part where the 'break' is missing we have to process the input that contains one character. We will start with state SchemeStart (log this state), process the character (that has to be ASCII lowercase alpha) and append to the buffer. Now we will move to the next character and as there is none (c.atEnd() is true) we will move to the branch with missing 'break'. The state is set to NoScheme, the input restarted, buffer cleared and the state is again changed, but to Scheme (due to missing 'break'). We continue in the loop (!c.atEnd()), now with the Scheme state. The state is logged and the first condition for Scheme case is isValidSchemeCharacter(). We know that the input contains ASCII lowercase alpha and that means that it is also a valid scheme character. The character is appended to the buffer and we move to the next character in the input, but as there is none then the state is set to NoScheme, the input restarted, buffer cleared. We again continue in the loop, now with the state NoScheme. So we got to the same point where we would end with the 'break' added in this patch. So the main difference is that without the 'break' there is an extra log message mentioning Scheme state. I should note that the url parser debugging is disabled by default, so in the default configuration there is no difference while running URLParser with or without this patch.

Yes, makes sense. This mistake did not result in incorrect behavior, just a *tiny* bit less efficient.
Comment 6 WebKit Commit Bot 2017-09-06 09:38:00 PDT
Comment on attachment 319889 [details]
Patch

Clearing flags on attachment: 319889

Committed r221677: <http://trac.webkit.org/changeset/221677>
Comment 7 WebKit Commit Bot 2017-09-06 09:38:02 PDT
All reviewed patches have been landed.  Closing bug.
Comment 8 Radar WebKit Bug Importer 2017-09-27 12:37:23 PDT
<rdar://problem/34693623>