Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update from mochi repo #15

Merged
merged 128 commits into from
Jul 24, 2014
Merged

update from mochi repo #15

merged 128 commits into from
Jul 24, 2014

Conversation

vinoski
Copy link
Contributor

@vinoski vinoski commented Jul 11, 2014

update basho fork from main mochiweb repo

etrepum and others added 30 commits November 2, 2011 14:30
Quoted attributes are allowed to contain newlines.
Fix for parsing unescaped < characters.
Fix for problem with to_html rendering faulty html with singleton tags.
http://tools.ietf.org/html/rfc2616#section-14.35.1

  If the last-byte-pos value is absent, or if
  the value is greater than or equal to the current
  length of the entity-body, last-byte-pos is taken
  to be equal to one less than the current length of
  the entity-body in bytes.

Specifically, the 'greater than equal to' case.
Fix a case in handling range headers
There were two issues:

- file:pread() returns eof in the case when the length of the
  read is 0 bytes, for any offset.  This causes badarg exceptions
  later in iolist_size when the 'eof' atom is encountered instead
  of a binary

- The range-length computation is off by 1 for 0-length ranges:
  {Skip, Skip + Length - 1, PartialBody} would result in e.g.
  {0, -1, eof}. {0, -1} is invalid HTTP according to

  http://tools.ietf.org/html/rfc2616#section-14.16

     A byte-content-range-spec with a byte-range-resp-spec whose
     last-byte-pos value is less than its first-byte-pos value,
     or whose instance-length value is less than or equal to its
     last-byte-pos value, is invalid.

This patch fixes both issues.
The source is still unclear but R15B02 now will return and emsgsize error
if the received packet is larger than the recvbuf.  This can be tested with
the following (sorry I don't know how to integrate this sort of test into
mochiweb's tests).

-module(mochi_test).

-export([start/0,
         handle_http/1,
         test/1]).

start() ->
  application:start (inets),
  mochiweb_http:start([{port, 5678}, {loop, fun(Req) -> handle_http(Req) end}]).

handle_http(Req) ->
  Req:respond({ 200,
                [ {"Content-Type", "text/html"} ],
                [ "<html><body>Hello</body></html>" ]
              }).

test (Len) ->
  httpc:request (get, {"http://127.0.0.1:5678/",
                 [{"X-Random", [$a || _ <- lists:seq(1,Len)]}]}, [], []).

Once compiled you can run this with

erl -pa ebin -boot start_sasl

Then run with

mochi_test:start().
mochi_test:test(10000).

The result is different with R14B04 and R15B02.  With R15B02 there was
a crash in the mochiweb_acceptor.  This patch deals with that crash.
On Windows, it is possible to access arbitrary files by crafting
a GET with unescaped \, like GET /..\..\..\..\..\windows\win.ini

http://www.couchbase.com/issues/browse/MB-7390
On Windows, it is possible to access arbitrary files by crafting
a GET with unescaped \, like GET /..\..\..\..\..\windows\win.ini

Please also see ouchbase.com/issues/browse/MB-7390
Pull request for issue 92: Do not allow backslashes in path (windows security).
Fix for mochiweb_acceptor crash under R15B02
etrepum and others added 22 commits December 26, 2013 13:06
* With Erlang R16B03 running on FreeBSD/amd64 10.0-PRERELEASE
  (base/stable/10 r260159),
  the following tests will not finish
  within the default eunit timeout of 5 seconds
  (See `lib/eunit/src/eunit_internal.hrl` (of R16B03))
  so cases modified to extend timeout to 60 seconds (`LARGE_TIMEOUT`):

        % note well the underscore at the end of function names
        single_100k_http_POST_test_()
        single_100k_https_POST_test_()
        multiple_100k_http_POST_test_()
        multiple_100k_https_POST_test_()

  See also <mochi/mochiweb@02066a5>
While investigating basho/webmachine#186 it was noted that a small but
non-zero percentage of clients embed whitespace in Range headers. It
appears this is valid:

From http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html

    byte-range-set  = 1#( byte-range-spec | suffix-byte-range-spec )

From http://www.w3.org/Protocols/rfc2616/rfc2616-sec2.html#sec2

    #rule
    ...separated by one or more commas (",") and OPTIONAL linear
    white space (LWS)...
    ...null elements are allowed, but do not contribute to the count
    of elements present. That is, "(element), , (element) " is permitted,
    but counts as only two elements...
max limits the sum of active connections and listeners.
The implementation assumes that max is greater than acceptor_pool_size,
and always maintains the acceptor_pool at acceptor_pool_size as long
as the max is not exceeded.

If max is less than acceptor_pool_size, acceptor_pool_size is the
effective max.
If we added a new socket in the recycle_acceptor, we should not decrement the
number of active sockets.
implementation of max, the number of connections is now limited with a default of 2048
* rebar prepare-deps is equivalent to rebar -r get-deps compile
* Only rebar *-deps and rebar compile are recursive by default.
  Therefore, we don't need to pass skip_deps=true.
Makefile: adapt rebar calls to new behavior
@vinoski
Copy link
Contributor Author

vinoski commented Jul 11, 2014

There are travis failures due to crypto compatibility issues for older Erlang releases. Fixing.

The crypto compatibility changes in mochiweb_session.erl and
mochiweb_websocket.erl are necessary for older releases of Erlang not
supported in the primary mochiweb repo.
@seancribbs
Copy link

👍 Looks fine, passes all tests on multiple Erlangs.

vinoski added a commit that referenced this pull request Jul 24, 2014
@vinoski vinoski merged commit bff08e8 into master Jul 24, 2014
@vinoski vinoski deleted the vinoski/mochiweb-update branch July 24, 2014 17:14
@shino shino mentioned this pull request Jan 16, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.