302 Commits

Author SHA1 Message Date
Nick Mathewson
e49e289129 Update copyright notices to 2012 2012-02-10 17:29:53 -05:00
Catalin Patulea
790f6b3b10 Force strict validation of HTTP version in response.
This sometimes accepted invalid versions like 'ICY' (n = 0, major = undefined, sometimes > 1).
2012-01-20 11:37:38 -05:00
Arno Bakker
da70fa705b Backport evhttp_connection_get_bufferevent to Libevent 2.0
Backport by Arno Bakker; original implementation in 8d3a8500f4
2011-12-14 16:17:19 -05:00
Nick Mathewson
3c824bd334 Update copyright dates to 2011. 2011-10-24 13:18:09 -04:00
Nick Mathewson
3203f88c5f Use the correct printf args when formatting size_t
Based on a patch from Mansour Moufid
2011-06-08 17:37:45 -04:00
Mansour Moufid
446cc7a0a1 Check if the evhttp_new_object' function in http.c' returns NULL. 2011-06-08 16:46:21 -04:00
Nick Mathewson
203ba2742f Fix a couple of signed/unsigned warnings in http.c 2011-05-27 15:08:25 -04:00
Nick Mathewson
dbb3c65288 Fix compilation. 2011-05-26 17:43:17 -04:00
Mark Ellzey
1814ae9677 updated EV_S(s)IZE definitions 2011-05-26 17:33:18 -04:00
Mark Ellzey
84560fc4dc Added overflow checks in evhttp_read_body and evhttp_get_body 2011-05-26 17:33:18 -04:00
Mark Ellzey
a27927229f Added several checks for under/overflow conditions in evhttp_handle_chunked_read 2011-05-26 17:33:18 -04:00
Mansour Moufid
06c51cdf93 Prevent size_t overflow in evhttp_htmlescape.
Modified the `html_replace' function so that it returns the length of
the replacement string instead of the string itself. This is used to
easily check for overflows of the `new_size' variable in the first for
loop of the `evhttp_htmlescape' function, and thus potential out of
bounds writes in the second for loop (if an overflow occurs in
new_size, then new_size < old_size). Also check that new_size + 1
doesn't overflow in mm_malloc(new_size + 1).

Removed the `scratch_space' variable from the `evhttp_htmlescape'
function since it wasn't actually used; also removed the `buf'
variable from the `evhttp_htmlescape' function since it was only used
by `scratch_space'.
2011-05-23 18:01:24 -04:00
Kevin Ko
0848814ac4 Fix failing assertion introducd in commit 0d6622e
Patch in question:
 - Fix the case when failed evhttp_make_request() leaved request in the queue.
 - http://levent.git.sourceforge.net/git/gitweb.cgi?p=levent/libevent;a=commit;h=0d6622e

The above patch introduces a failing assertion in
evhttp_connection_fail().  This happens because the patch defers the
assignment of the outstanding request to the evcon->requests list,
while evhttp_connection_fail() assumes that the request lies in the
list.

One scenario in which this can happen is when the request list is
empty and a connection is made to an unreachable host.  The assertion
will then fail after bufferevent_socket_connect() errors out (with
ENETUNREACH in my case).
2011-05-20 23:23:44 -04:00
Nick Mathewson
e49e64e774 Fix clang warning when resetting connection
This was a regression on 2.0.10-stable: clang was warning about
values that were unused (because event_debug wasn't using them unless
USE_DEBUG was defined).  Found by Sebastian Hahn.
2011-04-26 23:42:01 -04:00
Sebastian Hahn
12311ff46e Add a forgotten NULL check to evhttp_parse_headers
Issue detected by the clang static analyzer
2011-04-23 02:04:58 +02:00
Tomash Brechko
0d6622e26a Fix the case when failed evhttp_make_request() leaved request in the queue. 2011-04-04 14:45:53 -04:00
Tomash Brechko
218cf19743 Fix subtle recursion in evhttp_connection_cb_cleanup(). 2011-04-04 14:44:34 -04:00
Tomash Brechko
272823f8b0 Reset outgoing connection when read data in idle state.
Imagine server side is buggy and miscalculates Content-Length: in the
reply.  Data arriving in idle state shouldn't make us crash, instead we
can just reset the connection.
2011-04-04 14:41:45 -04:00
Nick Mathewson
c8baac9023 Followup for Tomash Brechko's http patch
This patch makes bufferevent_disable_hard() non-public, and
adds a comment about what it's for and why it's used.
2011-03-07 21:58:16 -05:00
Tomash Brechko
5dc566284d Workaround libevent bug
https://sourceforge.net/tracker/index.php?func=detail&aid=3078187&group_id=50884&atid=461324

The problem is that bufferevent_disable() doesn't disable EV_WRITE
when 'connecting' flag is set.  However from evhttp_connection_reset()
we want to disable EV_WRITE for sure (we are closing the socket next).
So we add bufferevent_disable_hard(), which acts like
bufferevent_disable(), but resets 'connecting' flag before the call to
the actual handler.

TODO: bufferevent_disable_hard() shouldn't be public, remove it from
event2/bufferevent.h.
2011-03-07 21:41:45 -05:00
Nick Mathewson
5dc200b7c8 Merge branch '20_uri_nonconformant' into patches-2.0 2011-02-22 18:53:55 -05:00
Harlan Stenn
10c834c4df Include arpa/inet.h as needed on HPUX 2011-02-22 00:24:36 -05:00
Nick Mathewson
63a715e125 Correctly detect and stop non-chunked http requests when the body is too long
Based on analysis and code from Bas Verhoeven and from
Constantine Verutin.
2011-02-21 23:25:13 -05:00
Nick Mathewson
95060b54fe Make URI parser able to tolerate nonconformant URIs.
If the EVHTTP_URI_NONCONFORMANT flag is passed in (which it is when
parsing URIs we get over the wire), then we relax our checks a lot.
Specifically, we do nothing to check for correct characters in the
path, query, and fragment parts of such a URI.

We could do much more here: we could relax our hostname requirements,
deal with spaces differently/better, trap some errors but not others,
etc.  But this should solve the worst user-agent compatibility issues
for now; the other issues can wait for a later release.
2011-02-13 00:41:22 -05:00
Jardel Weyrich
3f8d22a123 Use event_err() only if the failure is truly unrecoverable. 2011-01-07 13:03:32 -05:00
Jardel Weyrich
666b096691 Detect and handle more allocation failures. 2011-01-07 13:03:31 -05:00
Nick Mathewson
bb0d2b4e85 Consistentize tabs 2010-12-09 11:47:54 -05:00
Nick Mathewson
22f4af6580 Remove end-of-line whitespace 2010-12-09 11:43:12 -05:00
Nick Mathewson
7011f9ec1f Fix a signed/unsigned comparison in the last commit 2010-12-07 11:45:14 -05:00
Constantine Verutin
d23839fc6e Reject overlong http requests early when Expect:100-continue is set 2010-12-07 11:43:52 -05:00
Nick Mathewson
04861d5e62 Correctly detect timeouts during http connects 2010-11-30 00:05:54 -05:00
Nick Mathewson
0faaa39592 Try to fix an assertion failure related to close detection
f700566c removed a line from evhttp_connection_stop_detectclose that
cleared the EVHTTP_CON_CLOSEDETECT flag.  I think this was an
accident, and suspect that it may be the cause of bug 3069555.
2010-11-29 22:44:18 -05:00
Christopher Davis
fa9305f8f5 Preliminary support for Continue expectation in evhttp. 2010-11-29 18:25:04 -08:00
Nick Mathewson
a12839b083 Merge remote branch 'chrisd/http_fixes2' 2010-11-29 14:25:33 -05:00
Christopher Davis
aab8c38b76 Add evhttp server alias interface, correct flagging of proxy requests.
evhttp needs to be mindful of all hostnames and addresses that clients
use to contact the main server and vhosts to know the difference between
proxy requests and non-proxy requests.
2010-11-26 03:58:28 -08:00
Nick Mathewson
ec5c5aec6d Handle evhttp PUT/POST requests with an empty body
When we call evhttp_get_bodylen() [when transfer-encoding isn't set],
having req->ntoread == -1 means that we have no content-length.  But a
request with no content-length has no body!  We were treating the
absent content-length as meaning "read till closed", which only holds
for replies, not requests.

This patch also allows PATCH requests to have a body.
2010-11-23 20:31:28 -05:00
Nick Mathewson
8faf223ac5 Fix a memory leak in evhttp_uri_free. 2010-11-17 00:09:10 -05:00
Nick Mathewson
5c8a59e886 Merge remote branches 'github/20_evdns_cancel_segfault_v2', 'github/20_http_close_detect', 'github/20_http_versions', 'github/20_more_http_methods', 'github/20_shutdown_iocp_listener' and 'github/20_win64_fixes' 2010-11-09 10:19:05 -05:00
Nick Mathewson
a38140be18 Refactor http version parsing into a single function
Based on a suggestion by Chris Davis to make
evhttp_parse_response_line tolerate odd versions too.
2010-11-09 10:14:32 -05:00
Nick Mathewson
05124879d3 Never call evhttp_readcb while writing. 2010-11-04 14:05:08 -04:00
Felix Nawothnig
c76640b5c2 Don't disable reading from the HTTP connection after sending the request to be notified of connection-close in time 2010-11-04 14:01:26 -04:00
Nick Mathewson
536311a46b evhttp: Return 501 when we get an unrecognized method, not 400. 2010-11-04 12:39:41 -04:00
Nick Mathewson
f5b391e22e Tweak interface for allowed methods 2010-11-04 11:53:36 -04:00
Felix Nawothnig
75a73414a4 Define enumerators for all HTTP methods, including PATCH from RFC5789
This patch defines enumerators for all HTTP methods that exist
(including PATCH introduced in RFC 5789).

It also makes them bit-masky (that's not a word, is it?), breaking
binary- but not source-code compatibility.

evhttp now stores a bitmask specifying for which methods requests to
dispatch and which ones to reject with "405 Method Not Allowed".

By default that's the ones we currently have (GET, POST, HEAD, PUT,
DELETE), thereby keeping functional compatibility (besides the minor
change that one of the other methods will now cause 405 instead of
400. But I believe that could even be considered a bug-fix).

evhttp is extended by evhttp_set_allowed_methods() with which the
user can change that bitmask.

no regressions here and my test-app still works. Haven't yet
actually tested any of the new methods.

What's obviously missing here is the special logic for the methods:

OPTIONS: We should be fine here - I believe our current dispatch
logic should work fine. Some convenience functions would be fine
though.

TRACE: I'm pretty certain we should never dispatch this to the
callbacks and simply implement the necessary functionality built-in.

CONNECT: Pretty straight-forward to implement (and considering the
framework in which we implement it very efficient too). Should
probably go built-in.

PATCH: Except for checking the RFC against our pre-dispatch logic
(there just might be some "MUST not have Some-Header" lurking
somewhere) there is nothing to be done here, this is completely up
to the user. Nothing to do.
2010-11-04 11:53:36 -04:00
Nick Mathewson
78762383b7 Merge branch 'http_nolegacy_v2' 2010-11-03 15:18:34 -04:00
Nick Mathewson
22e0a9b2e8 Add evhttp_response_code to remove one more reason to include http_struct.h 2010-11-03 15:12:08 -04:00
Nick Mathewson
647e094ca2 Replace exact-version checks for HTTP/1.1 with >= or < checks 2010-11-02 15:19:12 -04:00
Joachim Bauch
aa5f55face reset "chunked" flag when sending non-chunked reply 2010-11-02 13:50:57 -04:00
Nick Mathewson
74a91e5aaf fix signed/unsigned warnings in http.c 2010-11-01 14:16:39 -04:00
Nick Mathewson
545a61145c Fix even more win64 warnings: buffer, event_tagging, http, evdns, evrpc 2010-11-01 14:13:33 -04:00