]> granicus.if.org Git - libevent/log
libevent
8 years agoautotools/win32: fix searching ssl library
Azat Khuzhin [Mon, 8 Aug 2016 15:10:56 +0000 (18:10 +0300)]
autotools/win32: fix searching ssl library

8 years agoappveyor/autotools: link with openssl by passing LDFLAGS/CFLAGS
Azat Khuzhin [Mon, 8 Aug 2016 14:25:11 +0000 (17:25 +0300)]
appveyor/autotools: link with openssl by passing LDFLAGS/CFLAGS

This never works, hence green tests in production. and now it works:
https://ci.appveyor.com/project/azat/libevent/build/2.1.5.100/job/eib4xqfb7d3ruo16
(look by /"evthread_win32.c")

8 years agoappveyor: image already had openssl installed
Azat Khuzhin [Mon, 8 Aug 2016 12:34:57 +0000 (15:34 +0300)]
appveyor: image already had openssl installed

Fixes messages like "Version mismatch for openssl: compiled with 1000201f but
running with 1000208f" [1].

According to next link:
  http://help.appveyor.com/discussions/questions/1132-openssl-installation-issues
Refs: appveyor/ci#576
[1]: https://ci.appveyor.com/project/azat/libevent/build/2.1.5.95/job/dcy9cfoj3rfo4gdh

8 years agocmake/win32: do not compile regress_thread on -DEVENT__DISABLE_THREAD_SUPPORT=ON
Azat Khuzhin [Mon, 8 Aug 2016 12:50:46 +0000 (15:50 +0300)]
cmake/win32: do not compile regress_thread on -DEVENT__DISABLE_THREAD_SUPPORT=ON

8 years agocmake/win32: do not compile evthread_win32 on -DEVENT__DISABLE_THREAD_SUPPORT=ON
Azat Khuzhin [Mon, 8 Aug 2016 12:45:29 +0000 (15:45 +0300)]
cmake/win32: do not compile evthread_win32 on -DEVENT__DISABLE_THREAD_SUPPORT=ON

There is duplicated "evthread_win32.c" appending to ${SRC_CORE} list, leave
only one that under if EVENT__DISABLE_THREAD_SUPPORT

Fixes: https://ci.appveyor.com/project/azat/libevent/build/2.1.5.96/job/44q3rgifasny7gek
8 years agoappveyor: check -DUNICODE -D_UNICODE according to ReleaseChecklist (cmake only)
Azat Khuzhin [Sun, 7 Aug 2016 20:51:21 +0000 (23:51 +0300)]
appveyor: check -DUNICODE -D_UNICODE according to ReleaseChecklist (cmake only)

Link: https://github.com/libevent/libevent/wiki/ReleaseChecklist
8 years agocmake: fix -DEVENT__ENABLE_VERBOSE_DEBUG (typo on -DUSE_DEBUG)
Azat Khuzhin [Sun, 7 Aug 2016 20:46:26 +0000 (23:46 +0300)]
cmake: fix -DEVENT__ENABLE_VERBOSE_DEBUG (typo on -DUSE_DEBUG)

Fixes: 8b228e27f57300be61b57a41a2ec8666b726dc34 ("Lot's of cmake updates")
8 years agotest: fix building with --disable-thread-support under win32
Azat Khuzhin [Sun, 7 Aug 2016 20:14:01 +0000 (23:14 +0300)]
test: fix building with --disable-thread-support under win32

8 years agocmake: do not use stderr for notifications/version-info
Azat Khuzhin [Sun, 7 Aug 2016 20:07:44 +0000 (23:07 +0300)]
cmake: do not use stderr for notifications/version-info

For all except "STATUS" message() will write to stderr, and this also includes
case when you does not have <mode> at all. Plus for every message in stderr
powershell generates exception and make appveyor fails.

Fixes: https://ci.appveyor.com/project/azat/libevent/build/2.1.5.85/job/i10k7m0t80330mtr
8 years agoautoconf: fix --disable-thread-support build under win32
Azat Khuzhin [Sun, 7 Aug 2016 19:19:39 +0000 (22:19 +0300)]
autoconf: fix --disable-thread-support build under win32

Fixes: https://ci.appveyor.com/project/azat/libevent/build/job/gvud4tcqsd5bnarl
Fixes: https://ci.appveyor.com/project/azat/libevent/build/2.1.6.80/job/5frnb1c3n4quxxqy
Fixes: https://ci.appveyor.com/project/azat/libevent/build/2.1.6.80/job/3wdahbrew7setmoa
8 years agoappveyor: ignore failure of mingw-get
Azat Khuzhin [Sun, 7 Aug 2016 18:30:04 +0000 (21:30 +0300)]
appveyor: ignore failure of mingw-get

Since according to doc [1], appveyour will fail the build on every powershell's
exception:
  "PowerShell script is considered successful if it finishes without exception."

[1]: https://www.appveyor.com/docs/build-configuration#powershell

8 years agoappveyor: drop shallow_clone, since we use tags for detecting version in cmake
Azat Khuzhin [Sun, 7 Aug 2016 17:52:41 +0000 (20:52 +0300)]
appveyor: drop shallow_clone, since we use tags for detecting version in cmake

8 years agoappveyor: support cmake & autotools using build matrix (like travis-ci has)
Azat Khuzhin [Sun, 19 Jun 2016 11:15:41 +0000 (14:15 +0300)]
appveyor: support cmake & autotools using build matrix (like travis-ci has)

This will allow us to avoid possible compilation regressions, and also some
failures in different environments (for example because of different
sizeof(size_t)).

For example we can avoid next issues:
- #361
- #314
- #311
(And I'm pretty sure that this is not complete list)

And of course it reduce job for maintainers.
But it also have one downside, appveyor doesn't have such concurrency like
travis-ci, so it can take a while to finish the whole build, but we can resolve
this later, or reduce build matrix to only one for autotools and one for cmake.

Fixes: #364
8 years agoIgnore `make dist` generated files
Azat Khuzhin [Mon, 8 Aug 2016 15:15:41 +0000 (18:15 +0300)]
Ignore `make dist` generated files

8 years agoCheck for Mac OS X 10.4 kqueue bug properly
Mark Mentovai [Fri, 8 Jul 2016 13:43:39 +0000 (09:43 -0400)]
Check for Mac OS X 10.4 kqueue bug properly

EV_ERROR is a bit in struct kevent::flags. Other bits may be set too.

Actually we have osx builds on travis-ci, but it uses osx 10.9.5, and we don't
have warnings there, since I guess that there is no OR'ing with previous flag
in case of error, while in 10.12 there is OR.

Fixes: #377
Fixes: #376
Link: https://crbug.com/626534
Link: https://travis-ci.org/libevent/libevent/jobs/141033429
8 years agobuffer: don't mix code and declarations
Azat Khuzhin [Thu, 7 Jul 2016 10:15:41 +0000 (13:15 +0300)]
buffer: don't mix code and declarations

8 years agoFix memory leak in signal-test.c
basavesh.as [Wed, 29 Jun 2016 09:41:50 +0000 (15:11 +0530)]
Fix memory leak in signal-test.c

8 years ago[#372] check for errno.h
Mark Ellzey [Tue, 28 Jun 2016 17:37:24 +0000 (10:37 -0700)]
[#372] check for errno.h

8 years agoMerge pull request #367 from neerajbadlani/master
Mark Ellzey [Sun, 26 Jun 2016 18:15:58 +0000 (11:15 -0700)]
Merge pull request #367 from neerajbadlani/master

Update gitignore file to ignore cscope gen'ed files

8 years agobuffer: Merge branch '340-dig-v2'
Azat Khuzhin [Sat, 25 Jun 2016 22:57:45 +0000 (01:57 +0300)]
buffer: Merge branch '340-dig-v2'

All details in this two patches (it's titles), and shortlog is below.

* 340-dig-v2:
  buffer: fix overflow check in evbuffer_expand_singlechain()
  test/buffer: cover evbuffer_expand() for overflow

8 years agobuffer: fix overflow check in evbuffer_expand_singlechain()
Azat Khuzhin [Tue, 21 Jun 2016 16:49:57 +0000 (19:49 +0300)]
buffer: fix overflow check in evbuffer_expand_singlechain()

Refs: #306
Fixes: #340
Fixes: 20d6d4458bee5d88bda1511c225c25b2d3198d6c
8 years agotest/buffer: cover evbuffer_expand() for overflow
Azat Khuzhin [Wed, 22 Jun 2016 12:48:51 +0000 (15:48 +0300)]
test/buffer: cover evbuffer_expand() for overflow

Refs: #306
Refs: #340

8 years ago[Issue #313] set method to ASCII "NULL" if evhttp_method() returns NULL
Mark Ellzey [Sat, 25 Jun 2016 01:07:39 +0000 (18:07 -0700)]
[Issue #313] set method to ASCII "NULL" if evhttp_method() returns NULL

8 years agoUpdate gitignore file to ignore cscope gen'ed files
Neeraj Badlani [Thu, 23 Jun 2016 04:15:53 +0000 (21:15 -0700)]
Update gitignore file to ignore cscope gen'ed files

8 years agobuffer: Merge branch 'evbuffer-empty-chains-fixes-v4'
Azat Khuzhin [Sun, 19 Jun 2016 10:24:18 +0000 (13:24 +0300)]
buffer: Merge branch 'evbuffer-empty-chains-fixes-v4'

This fixes bug with empty-chains and
evbuffer_add_buffer()/evbuffer_remove_buffer().

* evbuffer-empty-chains-fixes-v4:
  buffer: evbuffer_add_buffer(): clean empty chains from destination buffer
  test/buffer: evbuffer_add_buffer() with empty chains
  test/buffer: evbuffer_remove_buffer() with empty chains (prepend)
  test/buffer: evbuffer_remove_buffer() with empty chains (evbuffer_add_buffer())

Reported-by: Eduardo Panisset <eduardo@anchorfree.com>
8 years agobufferevent_filter: Merge branch 'be-filter-data-stuck'
Azat Khuzhin [Sun, 19 Jun 2016 10:21:15 +0000 (13:21 +0300)]
bufferevent_filter: Merge branch 'be-filter-data-stuck'

Fixes data stuck in filters with active watermarks.

* be-filter-data-stuck:
  test/be_filter: creating test case for data stuck with active watermarks
  be_filter: avoid data stuck under active watermarks

8 years agotest/be_filter: creating test case for data stuck with active watermarks
Eduardo Panisset [Sun, 19 Jun 2016 09:09:50 +0000 (02:09 -0700)]
test/be_filter: creating test case for data stuck with active watermarks

v2: fix whitespaces
    s/int/size_t/
    use tt_int_op()
    s/malloc/calloc (to avoid possible false-positive)

8 years agobe_filter: avoid data stuck under active watermarks
Eduardo Panisset [Fri, 17 Jun 2016 17:46:32 +0000 (10:46 -0700)]
be_filter: avoid data stuck under active watermarks

Suppose we have bufferevent filter attached to bufferevent socket.
Read high watermark for bufferevent filter is configured to 4096 bytes.
Socket receives 4343 bytes. Due to watermark, 4096 bytes are transferred
from socket input buffer to filter input buffer and 247 bytes are left
in bufferevent socket.
Suppose that no more data is received through socket.

At this point 247 bytes will sit forever in input buffer of bufferevent
socket.
The patch attached solves this issue registering read callback to
filter's input buffer if it reaches its read high water mark and data
was left in corresponding underlying's input buffer.

This read callback calls filter process input function as soon as filter
input buffer falls below its read high watermark and there still is data
left in underlying input buffer. Callback is deregistered as soon as
filter input buffer falls below its read high watermark.

8 years agoFix bufferevent_pair to properly set BEV_EVENT_{READING,WRITING} on flush.
David Paschich [Sun, 22 May 2016 04:05:11 +0000 (21:05 -0700)]
Fix bufferevent_pair to properly set BEV_EVENT_{READING,WRITING} on flush.

Here's some fun. From `bufferevent.h`:
  ```
  #define BEV_EVENT_READING 0x01 /**< error encountered while reading */
  #define BEV_EVENT_WRITING 0x02 /**< error encountered while writing */
  ```

And from `event.h`:
  ```
  /** Wait for a socket or FD to become readable */
  #define EV_READ 0x02
  /** Wait for a socket or FD to become writeable */
  #define EV_WRITE 0x04
  ```

Library users have to be very careful to get this right; it turns out, the
library itself got this wrong in the `bufferevent_pair` code. It appears that
in most of the code, only `BEV_EVENT_FINISHED` will indicate whether it's read
or write; on error or timeout, it appears that "both" is assumed and not set in
the callback. I read through all the other places where `BEV_EVENT_FINISHED` is
passed to an event callback; it appears that the pair code is the only spot
that got it wrong.

azat: add TT_FORK to avoid breaking clean env, and rebase commit message
(copied from #359)
Fixes: #359
8 years agobuffer: evbuffer_add_buffer(): clean empty chains from destination buffer
Azat Khuzhin [Tue, 7 Jun 2016 15:31:48 +0000 (18:31 +0300)]
buffer: evbuffer_add_buffer(): clean empty chains from destination buffer

@EMPanisset reported a problem (#358) with evbuffer_remove_buffer(), but
actually I think that the problem is in evbuffer_add_buffer() which introduces
this empty chain, all other callers (except evbuffer_prepend_buffer(), but it
doesn't have this problem though) should be safe.

And FWIW the only API that allows empty chains is evbuffer_add_reference(), and
we can add check there to avoid such issues, but for now I leaved this without
fixing, since I think that evbuffer_add_reference() with empty chains can be
used as a barrier (but this can be tricky).

Fixes: regress evbuffer/remove_buffer_with_empty2
v2: introduce/fixes evbuffer/add_buffer_with_empty

8 years agotest/buffer: evbuffer_add_buffer() with empty chains
Azat Khuzhin [Fri, 17 Jun 2016 12:54:53 +0000 (15:54 +0300)]
test/buffer: evbuffer_add_buffer() with empty chains

Reported-by: @EMPanisset
Link: https://github.com/libevent/libevent/issues/358#issuecomment-225345697
8 years agotest/buffer: evbuffer_remove_buffer() with empty chains (prepend)
Azat Khuzhin [Wed, 8 Jun 2016 10:41:30 +0000 (13:41 +0300)]
test/buffer: evbuffer_remove_buffer() with empty chains (prepend)

Using:
- evbuffer_add()
- evbuffer_prepend_buffer()
- evbuffer_add_reference()
- evbuffer_remove_buffer()

8 years agotest/buffer: evbuffer_remove_buffer() with empty chains (evbuffer_add_buffer())
Azat Khuzhin [Tue, 7 Jun 2016 11:56:32 +0000 (14:56 +0300)]
test/buffer: evbuffer_remove_buffer() with empty chains (evbuffer_add_buffer())

Using:
- evbuffer_add()
- evbuffer_add_buffer() -- the one that has problem
- evbuffer_add_reference() -- the only one that allows empty chains to be added
- evbuffer_remove_buffer()

8 years agotest/http: avoid using conditionals with omitted operands (fixes VS2015)
Azat Khuzhin [Fri, 17 Jun 2016 13:14:02 +0000 (16:14 +0300)]
test/http: avoid using conditionals with omitted operands (fixes VS2015)

But we need to add VS2015 build on appveyor.

Fixes: #361
Reported-by: @nntrab
8 years agotest/http: don't mix declarations and code (fixes -Wdeclaration-after-statement)
Azat Khuzhin [Fri, 17 Jun 2016 13:07:15 +0000 (16:07 +0300)]
test/http: don't mix declarations and code (fixes -Wdeclaration-after-statement)

8 years agotest/buffer: fix leak in test_evbuffer_prepend()
Azat Khuzhin [Fri, 17 Jun 2016 12:54:31 +0000 (15:54 +0300)]
test/buffer: fix leak in test_evbuffer_prepend()

8 years agotest/buffer: avoid errors with --no-fork (reinitialize static vars)
Azat Khuzhin [Fri, 17 Jun 2016 12:43:26 +0000 (15:43 +0300)]
test/buffer: avoid errors with --no-fork (reinitialize static vars)

8 years agoFor non GCC/clang on OSX the -Wno-deprecated-declarations may not be valid
Rainer Keller [Mon, 30 May 2016 14:53:41 +0000 (16:53 +0200)]
For non GCC/clang on OSX the -Wno-deprecated-declarations may not be valid

Closes: nmathewson/Libevent#129
8 years agoMerge branch 'travis-ci-os-matrix-v2'
Azat Khuzhin [Wed, 11 May 2016 21:40:25 +0000 (00:40 +0300)]
Merge branch 'travis-ci-os-matrix-v2'

This increases libevent coverage to:
- os:osx

- cmake -DEVENT__DISABLE_MM_REPLACEMENT=ON
- cmake -DEVENT__ENABLE_VERBOSE_DEBUG=ON
- configure --disable-openssl
- configure --disable-thread-support
- configure --disable-malloc-replacement

- fix travis-ci builds under automake >1.11

Possible failures after this patch set (not always, IOW in some builds this
issues aren't real issues):
- some failures but mostly because of timing issues, must be fixed separately.
- https://travis-ci.org/azat/libevent/jobs/129430229 # on brew update
- https://travis-ci.org/azat/libevent/jobs/129430221 # some locking issues

* travis-ci-os-matrix-v2:
  automake: define serial-tests only if automake have this option
  test/automake: don't use paralell test harness (since automake 1.12)
  travis-ci/osx: relink gcc/g++ instead of clang
  travis-ci: enable multi-os mode (osx, linux)
  travis-ci: increase matrix (--disable-foo)
  travis-ci: adjust alignment

Fixes: #356
Travis-CI: https://travis-ci.org/azat/libevent/builds/129430181

8 years agoautomake: define serial-tests only if automake have this option
Azat Khuzhin [Wed, 11 May 2016 13:02:02 +0000 (16:02 +0300)]
automake: define serial-tests only if automake have this option

P.S. I did try a lot of other ways, but seems that this is the only one that
will work.

Fixes: automake 1.11
Travis-CI: https://travis-ci.org/azat/libevent/jobs/129398265

8 years agotest/automake: don't use paralell test harness (since automake 1.12)
Azat Khuzhin [Wed, 11 May 2016 07:18:25 +0000 (10:18 +0300)]
test/automake: don't use paralell test harness (since automake 1.12)

Starting from automake 1.2 there is parallel test harness, that redirects all
output to some log, which serial-test doesn't do.
So in case of new runner we can get no output for 10 minutes, for example on my
desktop:
  $ time make verify VERBOSE=1
  PASS: test/test-script.sh
  ============================================================================
  Testsuite summary for libevent 2.1.5-beta
  ============================================================================
  # TOTAL: 1
  # PASS:  1
  # SKIP:  0
  # XFAIL: 0
  # FAIL:  0
  # XPASS: 0
  # ERROR: 0
  ============================================================================

  real    25m31.735s
  user    0m13.753s
  sys     0m7.648s

And this means that this will fail on travis-ci, since it has timeout for 10
minutes. Sure we can use `travis wait 60` instead, but I think that it is
better to fix this by writing result to output, instead of hacking around, so
let's use serial-tests instead of parallel always.
And now it works on travis-ci under linux because it has automake 1.11 while
osx has at least 1.12.

Links:
https://docs.travis-ci.com/user/common-build-problems/
https://www.gnu.org/software/automake/manual/html_node/Serial-Test-Harness.html#Serial-Test-Harness
https://www.gnu.org/software/automake/manual/html_node/Parallel-Test-Harness.html

CI:
https://travis-ci.org/azat/libevent/jobs/129171497 # ok on linux
https://travis-ci.org/azat/libevent/jobs/129171532 # no output for 10 min on osx

8 years agotravis-ci/osx: relink gcc/g++ instead of clang
Azat Khuzhin [Tue, 10 May 2016 07:25:05 +0000 (10:25 +0300)]
travis-ci/osx: relink gcc/g++ instead of clang

Since by default osx replaces /usr/bin/gcc with it's apple clang, while we have
gcc in our build matrix, so use real gcc.

8 years agotravis-ci: enable multi-os mode (osx, linux)
Azat Khuzhin [Mon, 9 May 2016 15:14:31 +0000 (18:14 +0300)]
travis-ci: enable multi-os mode (osx, linux)

- use addons.apt.packages instead of `apt-get install`
- add `brew update`/`brew install ...`

Link: https://docs.travis-ci.com/user/installing-dependencies/
Link: https://docs.travis-ci.com/user/multi-os/
8 years agotravis-ci: increase matrix (--disable-foo)
Azat Khuzhin [Mon, 9 May 2016 15:48:56 +0000 (18:48 +0300)]
travis-ci: increase matrix (--disable-foo)

Use --disable-foo from
https://github.com/libevent/libevent/wiki/ReleaseChecklist

8 years agotravis-ci: adjust alignment
Azat Khuzhin [Mon, 9 May 2016 15:54:41 +0000 (18:54 +0300)]
travis-ci: adjust alignment

8 years agobe_openssl: clear all pending errors before SSL_*() calls
Azat Khuzhin [Mon, 2 May 2016 12:21:50 +0000 (15:21 +0300)]
be_openssl: clear all pending errors before SSL_*() calls

Refs: #350
Reported-by: @CapSel
8 years agoIgnore all pkgconfig generated stuff
Azat Khuzhin [Wed, 20 Apr 2016 23:16:21 +0000 (02:16 +0300)]
Ignore all pkgconfig generated stuff

In the referenced commit new *.pc added, and I think it is better to ignore
them all.

Refs: b8d7c6211a965c19c7c5de414135ff13b5fa2476 ("libevent_core and
libevent_extra also deserve a pkgconfig file")

8 years agotest/buffer: cover n_add_for_cb when evbuffer_prepend() need to allocate buffer
Azat Khuzhin [Wed, 20 Apr 2016 22:47:29 +0000 (01:47 +0300)]
test/buffer: cover n_add_for_cb when evbuffer_prepend() need to allocate buffer

Regression-for: 0abd0393eaf029e1ead8a09b479ea6830f7152ee ("Fix n_add_for_cb in
evbuffer_prepend() in case of new buffer required")

8 years agotest/tinytest_macros: add new one tt_nstr_op()
Azat Khuzhin [Wed, 20 Apr 2016 23:11:26 +0000 (02:11 +0300)]
test/tinytest_macros: add new one tt_nstr_op()

8 years agoFix n_add_for_cb in evbuffer_prepend() in case of new buffer required
Azat Khuzhin [Wed, 20 Apr 2016 22:58:58 +0000 (01:58 +0300)]
Fix n_add_for_cb in evbuffer_prepend() in case of new buffer required

Signed-off-by: @luoming1224
Fixes: #349
8 years agolibevent_core and libevent_extra also deserve a pkgconfig file
Jan Heylen [Wed, 20 Apr 2016 05:31:25 +0000 (07:31 +0200)]
libevent_core and libevent_extra also deserve a pkgconfig file

8 years agoMerge branch 'be-filter-outputcb-disable-during-execution'
Azat Khuzhin [Mon, 18 Apr 2016 10:39:54 +0000 (13:39 +0300)]
Merge branch 'be-filter-outputcb-disable-during-execution'

* be-filter-outputcb-disable-during-execution:
  test/bufferevent: check that output_filter disabled during processing output
  be_filter: actually disable output_filter during processing output

8 years agotest/bufferevent: check that output_filter disabled during processing output
Azat Khuzhin [Mon, 18 Apr 2016 09:50:24 +0000 (12:50 +0300)]
test/bufferevent: check that output_filter disabled during processing output

Regression-for: c031215d532c97f1d82efd672ecd622d31d3342d ("be_filter: actually
disable output_filter during processing output")

8 years agobe_filter: actually disable output_filter during processing output
Simon Perreault [Sun, 28 Feb 2016 21:49:15 +0000 (16:49 -0500)]
be_filter: actually disable output_filter during processing output

IOW: Make the code do what the comment says it should do.

8 years agolistener: unlock lev on error in listener_read_cb()
Azat Khuzhin [Thu, 31 Mar 2016 17:45:47 +0000 (20:45 +0300)]
listener: unlock lev on error in listener_read_cb()

Without this patch:
  $ regress --no-fork +listener/error_unlock
  listener/error_unlock: [warn] Error from accept() call: Too many open files
  [err] ../evthread.c:220: Assertion lock->count == 0 failed in ../evthread.c
  Aborted (core dumped)

Fixes: #341
Fixes: listener/error_unlock
8 years agotest/listener: regression for missing unlock in listener_read_cb()
Azat Khuzhin [Thu, 31 Mar 2016 17:50:12 +0000 (20:50 +0300)]
test/listener: regression for missing unlock in listener_read_cb()

P.S. it triggers even without pthread, but this makes checks more strict.

Refs: #341

8 years agoMerge remote-tracking branch 'origin/pr/339'
Azat Khuzhin [Tue, 29 Mar 2016 16:20:30 +0000 (19:20 +0300)]
Merge remote-tracking branch 'origin/pr/339'

* origin/pr/339:
  evbuffer_add: Use last_with_datap if set, not last.
  test/regress: add tests for evbuffer_add() breakage on empty last chain

Fixes: #335
8 years agoevbuffer_add: Use last_with_datap if set, not last.
Marcus Sundberg [Sat, 26 Mar 2016 19:11:43 +0000 (20:11 +0100)]
evbuffer_add: Use last_with_datap if set, not last.

evbuffer_add() would always put data in the last chain, even if there
was available space in a previous chain, and in doing so it also
failed to update last_with_datap, causing subsequent calls to other
functions that do look at last_with_datap to add data in the middle
of the evbuffer instead of at the end.

Fixes the evbuffer_add() part of issue #335, and the evbuffer/add2 and
evbuffer/add3 tests, and also prevents wasting space available in the
chain pointed to by last_with_datap.

8 years agotest/regress: add tests for evbuffer_add() breakage on empty last chain
Marcus Sundberg [Sat, 26 Mar 2016 13:14:44 +0000 (14:14 +0100)]
test/regress: add tests for evbuffer_add() breakage on empty last chain

The evbuffer/add* tests currenly break on 2.0.21, 2.0.22 and 2.1 HEAD
due to issue #335. The evbuffer/reference2 test breaks on 2.0.21 and
2.0.22 due to commit b18c04dd not being applied.

8 years agotest/http: fix running some tests sequential (with --no-fork)
Azat Khuzhin [Fri, 25 Mar 2016 08:22:43 +0000 (11:22 +0300)]
test/http: fix running some tests sequential (with --no-fork)

After this patch
$ regress --no-fork +http/..

Passed without failures.

8 years agotest/http: localize evhttp server structure
Azat Khuzhin [Fri, 25 Mar 2016 08:04:51 +0000 (11:04 +0300)]
test/http: localize evhttp server structure

8 years agoevhttp_have_expect(): fix -Wlogical-not-parentheses
Azat Khuzhin [Fri, 25 Mar 2016 07:21:48 +0000 (10:21 +0300)]
evhttp_have_expect(): fix -Wlogical-not-parentheses

../http.c:589:6: warning: logical not is only applied to the left hand side of this comparison [-Wlogical-not-parentheses]
        if (!req->kind == EVHTTP_REQUEST || !REQ_VERSION_ATLEAST(req, 1, 1))
                        ^          ~~

8 years agoevdns: fix searching empty hostnames
Azat Khuzhin [Thu, 24 Mar 2016 21:33:47 +0000 (00:33 +0300)]
evdns: fix searching empty hostnames

From #332:
  Here follows a bug report by **Guido Vranken** via the _Tor bug bounty program_. Please credit Guido accordingly.

  ## Bug report

  The DNS code of Libevent contains this rather obvious OOB read:

  ```c
  static char *
  search_make_new(const struct search_state *const state, int n, const char *const base_name) {
      const size_t base_len = strlen(base_name);
      const char need_to_append_dot = base_name[base_len - 1] == '.' ? 0 : 1;
  ```

  If the length of ```base_name``` is 0, then line 3125 reads 1 byte before the buffer. This will trigger a crash on ASAN-protected builds.

  To reproduce:

  Build libevent with ASAN:
  ```
  $ CFLAGS='-fomit-frame-pointer -fsanitize=address' ./configure && make -j4
  ```
  Put the attached ```resolv.conf``` and ```poc.c``` in the source directory and then do:

  ```
  $ gcc -fsanitize=address -fomit-frame-pointer poc.c .libs/libevent.a
  $ ./a.out
  =================================================================
  ==22201== ERROR: AddressSanitizer: heap-buffer-overflow on address 0x60060000efdf at pc 0x4429da bp 0x7ffe1ed47300 sp 0x7ffe1ed472f8
  READ of size 1 at 0x60060000efdf thread T0
  ```

P.S. we can add a check earlier, but since this is very uncommon, I didn't add it.

Fixes: #332
8 years agotest/dns: regression for empty hostname
Azat Khuzhin [Thu, 24 Mar 2016 21:21:06 +0000 (00:21 +0300)]
test/dns: regression for empty hostname

Refs: #332

8 years agotest/http: fix SERVER_TIMEOUT tests under win32
Azat Khuzhin [Thu, 24 Mar 2016 17:29:25 +0000 (20:29 +0300)]
test/http: fix SERVER_TIMEOUT tests under win32

Seems that the hack with filling BACKLOG didn't work on win32, and hence we
stuck in write() waiting, not in connect()

And:
$ time regress http/cancel_server_timeout
- on linux: 10secs
- on win32: 2-5secs

I tried to debug this but you can't sniff TCP packages (wireshark/rawpcap) on
localhost in windows xp (according to [RAWPCAP] and my testing).

RAWPCAP: http://www.netresec.com/?page=RawCap

8 years agotest/http: add a helper for creating timedout/failed request
Azat Khuzhin [Thu, 24 Mar 2016 17:26:50 +0000 (20:26 +0300)]
test/http: add a helper for creating timedout/failed request

8 years agotest/http: adopt for C90 (mixed code and declarations)
Azat Khuzhin [Thu, 24 Mar 2016 11:11:10 +0000 (14:11 +0300)]
test/http: adopt for C90 (mixed code and declarations)

8 years agoevdns: avoid double-free in evdns_base_free() for probing requests
Azat Khuzhin [Thu, 24 Mar 2016 09:49:47 +0000 (12:49 +0300)]
evdns: avoid double-free in evdns_base_free() for probing requests

http/cancel_by_host_no_ns:
    OK ../test/regress_http.c:1384: assert(regress_dnsserver(data->base, &portnum, search_table))
    OK ../test/regress_http.c:1387: assert(dns_base)
    OK ../test/regress_http.c:1423: assert(evcon)
         OK ../test/regress_http.c:1444: assert(evhttp_make_request(evcon, req, EVHTTP_REQ_GET, "/delay") != -1): 0 vs -1
         OK ../test/regress_http.c:1455: assert(test_ok == 2): 2 vs 2
         OK ../test/regress_http.c:1480: assert(evhttp_make_request(evcon, req, EVHTTP_REQ_GET, "/test") != -1): 0 vs -1[msg] Nameserver 127.0.0.1:55948 has failed: request timed out.
[msg] All nameservers have failed

    OK ../test/regress_http.c:1274: assert(!req)
         OK ../test/regress_http.c:1505: assert(evhttp_make_request(evcon, req, EVHTTP_REQ_GET, "/test") != -1): 0 vs -1
    OK ../test/regress_http.c:1274: assert(!req)==19199== Invalid read of size 8
==19199==    at 0x4CC285: evdns_cancel_request (evdns.c:2849)
==19199==    by 0x4CEDB2: evdns_nameserver_free (evdns.c:4018)
==19199==    by 0x4CEF5B: evdns_base_free_and_unlock (evdns.c:4052)
==19199==    by 0x4CF13B: evdns_base_free (evdns.c:4088)
==19199==    by 0x4617A3: http_cancel_test (regress_http.c:1518)
==19199==    by 0x490A78: testcase_run_bare_ (tinytest.c:105)
==19199==    by 0x490D5A: testcase_run_one (tinytest.c:252)
==19199==    by 0x491699: tinytest_main (tinytest.c:434)
==19199==    by 0x47E0E0: main (regress_main.c:461)
==19199==  Address 0x61e56d0 is 0 bytes inside a block of size 48 free'd
==19199==    at 0x4C2AE6B: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==19199==    by 0x4AAFFF: event_mm_free_ (event.c:3516)
==19199==    by 0x4C5ADD: request_finished (evdns.c:693)
==19199==    by 0x4CEE95: evdns_base_free_and_unlock (evdns.c:4040)
==19199==    by 0x4CF13B: evdns_base_free (evdns.c:4088)
==19199==    by 0x4617A3: http_cancel_test (regress_http.c:1518)
==19199==    by 0x490A78: testcase_run_bare_ (tinytest.c:105)
==19199==    by 0x490D5A: testcase_run_one (tinytest.c:252)
==19199==    by 0x491699: tinytest_main (tinytest.c:434)
==19199==    by 0x47E0E0: main (regress_main.c:461)
==19199==  Block was alloc'd at
==19199==    at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==19199==    by 0x4AAEB2: event_mm_calloc_ (event.c:3459)
==19199==    by 0x4CAAA2: nameserver_send_probe (evdns.c:2327)
==19199==    by 0x4C50FF: nameserver_prod_callback (evdns.c:494)
==19199==    by 0x4A564C: event_process_active_single_queue (event.c:1646)
==19199==    by 0x4A5B95: event_process_active (event.c:1738)
==19199==    by 0x4A6296: event_base_loop (event.c:1961)
==19199==    by 0x4A5C1D: event_base_dispatch (event.c:1772)
==19199==    by 0x46172C: http_cancel_test (regress_http.c:1507)
==19199==    by 0x490A78: testcase_run_bare_ (tinytest.c:105)
==19199==    by 0x490D5A: testcase_run_one (tinytest.c:252)
==19199==    by 0x491699: tinytest_main (tinytest.c:434)
==19199==

8 years agoMerge branch 'bufev-cancellations-v5'
Azat Khuzhin [Thu, 24 Mar 2016 11:05:28 +0000 (14:05 +0300)]
Merge branch 'bufev-cancellations-v5'

This patch set fixes bufferevent via http request cancellations (connect() and
dns-request), it survives tests and cancel.. with --no-fork, so this must be ok
(though I have one patch for dns layer pending).
But I'm not sure about cancel.. unit tests on win32, will fix disable them
later if they will differs (plus maybe we must make them skip-by-default?).

Fixes: #333
* bufev-cancellations-v5:
  http: set fd to -1 unconditioally, to avoid leaking of DNS requests
  test/http: cover NS timed out during request cancellations separatelly
  http: avoid leaking of fd in evhttp_connection_free()
  http: get fd from be layer during connection reset
  be_sock: cancel in-progress dns requests
  evdns: export cancel via callbacks in util (like async lib core/extra issues)
  test/http: request cancellation with resolving/{conn,write}-timeouts in progress

8 years agohttp: set fd to -1 unconditioally, to avoid leaking of DNS requests
Azat Khuzhin [Thu, 24 Mar 2016 10:38:05 +0000 (13:38 +0300)]
http: set fd to -1 unconditioally, to avoid leaking of DNS requests

Otherwise:
http/cancel_by_host_ns_timeout_inactive_server: [msg] Nameserver 127.0.0.1:37035 has failed: request timed out.
[msg] All nameservers have failed
OK
1 tests ok.  (0 skipped)
==26211==
==26211== FILE DESCRIPTORS: 3 open at exit.
==26211== Open file descriptor 2: /dev/pts/47
==26211==    <inherited from parent>
==26211==
==26211== Open file descriptor 1: /dev/pts/47
==26211==    <inherited from parent>
==26211==
==26211== Open file descriptor 0: /dev/pts/47
==26211==    <inherited from parent>
==26211==
==26211==
==26211== HEAP SUMMARY:
==26211==     in use at exit: 1,112 bytes in 5 blocks
==26211==   total heap usage: 149 allocs, 144 frees, 18,826 bytes allocated
==26211==
==26211== 40 bytes in 1 blocks are indirectly lost in loss record 1 of 5
==26211==    at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==26211==    by 0x4AAEB2: event_mm_calloc_ (event.c:3459)
==26211==    by 0x498F5B: evbuffer_add_cb (buffer.c:3309)
==26211==    by 0x4A0EF5: bufferevent_socket_new (bufferevent_sock.c:366)
==26211==    by 0x4BFADF: evhttp_connection_base_bufferevent_new (http.c:2375)
==26211==    by 0x4BFC8F: evhttp_connection_base_new (http.c:2427)
==26211==    by 0x460DAA: http_cancel_test (regress_http.c:1417)
==26211==    by 0x490A78: testcase_run_bare_ (tinytest.c:105)
==26211==    by 0x490D5A: testcase_run_one (tinytest.c:252)
==26211==    by 0x491699: tinytest_main (tinytest.c:434)
==26211==    by 0x47E0E0: main (regress_main.c:461)
==26211==
==26211== 136 bytes in 1 blocks are indirectly lost in loss record 2 of 5
==26211==    at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==26211==    by 0x4AAEB2: event_mm_calloc_ (event.c:3459)
==26211==    by 0x491FF0: evbuffer_new (buffer.c:365)
==26211==    by 0x49A1BE: bufferevent_init_common_ (bufferevent.c:300)
==26211==    by 0x4A0E44: bufferevent_socket_new (bufferevent_sock.c:353)
==26211==    by 0x4BFADF: evhttp_connection_base_bufferevent_new (http.c:2375)
==26211==    by 0x4BFC8F: evhttp_connection_base_new (http.c:2427)
==26211==    by 0x460DAA: http_cancel_test (regress_http.c:1417)
==26211==    by 0x490A78: testcase_run_bare_ (tinytest.c:105)
==26211==    by 0x490D5A: testcase_run_one (tinytest.c:252)
==26211==    by 0x491699: tinytest_main (tinytest.c:434)
==26211==    by 0x47E0E0: main (regress_main.c:461)
==26211==
==26211== 136 bytes in 1 blocks are indirectly lost in loss record 3 of 5
==26211==    at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==26211==    by 0x4AAEB2: event_mm_calloc_ (event.c:3459)
==26211==    by 0x491FF0: evbuffer_new (buffer.c:365)
==26211==    by 0x49A1FB: bufferevent_init_common_ (bufferevent.c:305)
==26211==    by 0x4A0E44: bufferevent_socket_new (bufferevent_sock.c:353)
==26211==    by 0x4BFADF: evhttp_connection_base_bufferevent_new (http.c:2375)
==26211==    by 0x4BFC8F: evhttp_connection_base_new (http.c:2427)
==26211==    by 0x460DAA: http_cancel_test (regress_http.c:1417)
==26211==    by 0x490A78: testcase_run_bare_ (tinytest.c:105)
==26211==    by 0x490D5A: testcase_run_one (tinytest.c:252)
==26211==    by 0x491699: tinytest_main (tinytest.c:434)
==26211==    by 0x47E0E0: main (regress_main.c:461)
==26211==
==26211== 536 bytes in 1 blocks are indirectly lost in loss record 4 of 5
==26211==    at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==26211==    by 0x4AAEB2: event_mm_calloc_ (event.c:3459)
==26211==    by 0x4A0E15: bufferevent_socket_new (bufferevent_sock.c:350)
==26211==    by 0x4BFADF: evhttp_connection_base_bufferevent_new (http.c:2375)
==26211==    by 0x4BFC8F: evhttp_connection_base_new (http.c:2427)
==26211==    by 0x460DAA: http_cancel_test (regress_http.c:1417)
==26211==    by 0x490A78: testcase_run_bare_ (tinytest.c:105)
==26211==    by 0x490D5A: testcase_run_one (tinytest.c:252)
==26211==    by 0x491699: tinytest_main (tinytest.c:434)
==26211==    by 0x47E0E0: main (regress_main.c:461)
==26211==
==26211== 1,112 (264 direct, 848 indirect) bytes in 1 blocks are definitely lost in loss record 5 of 5
==26211==    at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==26211==    by 0x4AAEB2: event_mm_calloc_ (event.c:3459)
==26211==    by 0x4D0564: evdns_getaddrinfo (evdns.c:4685)
==26211==    by 0x4B13BA: evutil_getaddrinfo_async_ (evutil.c:1575)
==26211==    by 0x4A139E: bufferevent_socket_connect_hostname (bufferevent_sock.c:524)
==26211==    by 0x4C02DB: evhttp_connection_connect_ (http.c:2588)
==26211==    by 0x4C04DD: evhttp_make_request (http.c:2643)
==26211==    by 0x4615FF: http_cancel_test (regress_http.c:1504)
==26211==    by 0x490A78: testcase_run_bare_ (tinytest.c:105)
==26211==    by 0x490D5A: testcase_run_one (tinytest.c:252)
==26211==    by 0x491699: tinytest_main (tinytest.c:434)
==26211==    by 0x47E0E0: main (regress_main.c:461)
==26211==
==26211== LEAK SUMMARY:
==26211==    definitely lost: 264 bytes in 1 blocks
==26211==    indirectly lost: 848 bytes in 4 blocks
==26211==      possibly lost: 0 bytes in 0 blocks
==26211==    still reachable: 0 bytes in 0 blocks
==26211==         suppressed: 0 bytes in 0 blocks

8 years agotest/http: cover NS timed out during request cancellations separatelly
Azat Khuzhin [Thu, 24 Mar 2016 07:27:24 +0000 (10:27 +0300)]
test/http: cover NS timed out during request cancellations separatelly

8 years agohttp: avoid leaking of fd in evhttp_connection_free()
Azat Khuzhin [Tue, 22 Mar 2016 20:36:19 +0000 (23:36 +0300)]
http: avoid leaking of fd in evhttp_connection_free()

Since we do close fd there if we don't have BEV_OPT_CLOSE_ON_FREE, and
evcon->fd can be incorrect (non -1), so just get it from the underlying
bufferevent to fix this.

And after this patch the following tests report 0 instead of 2307 fd leaks:
$ valgrind --leak-check=full --show-reachable=yes --track-fds=yes --error-exitcode=1 regress --no-fork http/cancel..
==11299== FILE DESCRIPTORS: 3 open at exit.

And this is stdin/stderr/stdout.

8 years agohttp: get fd from be layer during connection reset
Azat Khuzhin [Tue, 22 Mar 2016 16:29:50 +0000 (19:29 +0300)]
http: get fd from be layer during connection reset

Since it can be non -1, and we must close it, otherwise we will have problems.

And after this patch the following tests report fd 2307 instead of 2309 fd leaks:
$ valgrind --leak-check=full --show-reachable=yes --track-fds=yes --error-exitcode=1 regress --no-fork http/cancel..
==10853== FILE DESCRIPTORS: 2307 open at exit.

8 years agobe_sock: cancel in-progress dns requests
Azat Khuzhin [Mon, 21 Mar 2016 14:09:17 +0000 (17:09 +0300)]
be_sock: cancel in-progress dns requests

Before this patch we didn't have such functionality and this can cause some
issues when we are cancelling HTTP request while after this we will get a
response/timeout from the NS and in this case error_cb will be called and can
damage newly started HTTP request.
We could also have problems with connect, but we don't have them since we
closes the fd in HTTP layer.

This is not so good that this is done in be_sock, but it is internal, so we can
change without pain. Plus I don't like that callback-via-evutil, but since we
have event_extra we need do like that.

And after this patch the following tests doesn't report leaks:
$ valgrind --leak-check=full --show-reachable=yes --track-fds=yes --error-exitcode=1 regress --no-fork http/cancel..
...
==10469== FILE DESCRIPTORS: 2309 open at exit.
...
==10469== HEAP SUMMARY:
==10469==     in use at exit: 0 bytes in 0 blocks
==10469==   total heap usage: 33,846 allocs, 33,846 frees, 4,617,651 bytes allocated
==10469==
==10469== All heap blocks were freed -- no leaks are possible

v2: do under lock
v3: reset dns request
v4: ignore EVUTIL_EAI_CANCEL in regular callback

8 years agoevdns: export cancel via callbacks in util (like async lib core/extra issues)
Azat Khuzhin [Mon, 21 Mar 2016 14:08:34 +0000 (17:08 +0300)]
evdns: export cancel via callbacks in util (like async lib core/extra issues)

8 years agotest/http: request cancellation with resolving/{conn,write}-timeouts in progress
Azat Khuzhin [Sat, 12 Mar 2016 15:50:41 +0000 (18:50 +0300)]
test/http: request cancellation with resolving/{conn,write}-timeouts in progress

This patch adds 8 new tests:
- http/cancel
- http/cancel_by_host
- http/cancel_by_host_no_ns
- http/cancel_by_host_inactive_server
- http/cancel_inactive_server
- http/cancel_by_host_no_ns_inactive_server
- http/cancel_by_host_server_timeout
- http/cancel_server_timeout
- http/cancel_by_host_no_ns_server_timeout

This patches not 100% for http layer, but more for be_sock, but it was simpler
to add them here, plus it also shows some bugs with fd leaking in http layer.

Right now we have next picture (we can also play with timeouts/attempts for
evdns to make tests fail, IOW to track the failures even without valgrind):
$ valgrind --leak-check=full --show-reachable=yes --track-fds=yes --error-exitcode=1 regress --no-fork http/cancel..
http/cancel: OK
http/cancel_by_host: OK
http/cancel_by_host_no_ns: [msg] Nameserver 127.0.0.1:42489 has failed: request timed out.
[msg] All nameservers have failed
OK
http/cancel_by_host_inactive_server: OK
http/cancel_inactive_server: OK
http/cancel_by_host_no_ns_inactive_server: [msg] Nameserver 127.0.0.1:51370 has failed: request timed out.
[msg] All nameservers have failed
OK
http/cancel_by_host_server_timeout: OK
http/cancel_server_timeout: OK
http/cancel_by_host_no_ns_server_timeout: [msg] Nameserver 127.0.0.1:45054 has failed: request timed out.
[msg] All nameservers have failed
OK
9 tests ok.  (0 skipped)
==3202==
==3202== FILE DESCRIPTORS: 2309 open at exit.
...
==8403== HEAP SUMMARY:
==8403==     in use at exit: 1,104 bytes in 5 blocks
==8403==   total heap usage: 10,916 allocs, 10,911 frees, 1,458,818 bytes allocated
==8403==
==8403== 40 bytes in 1 blocks are indirectly lost in loss record 1 of 5
==8403==    at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403==    by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403==    by 0x498E48: evbuffer_add_cb (buffer.c:3309)
==8403==    by 0x4A0DE2: bufferevent_socket_new (bufferevent_sock.c:366)
==8403==    by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403==    by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403==    by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403==    by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403==    by 0x490C47: testcase_run_one (tinytest.c:252)
==8403==    by 0x491586: tinytest_main (tinytest.c:434)
==8403==    by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 136 bytes in 1 blocks are indirectly lost in loss record 2 of 5
==8403==    at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403==    by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403==    by 0x491EDD: evbuffer_new (buffer.c:365)
==8403==    by 0x49A0AB: bufferevent_init_common_ (bufferevent.c:300)
==8403==    by 0x4A0D31: bufferevent_socket_new (bufferevent_sock.c:353)
==8403==    by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403==    by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403==    by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403==    by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403==    by 0x490C47: testcase_run_one (tinytest.c:252)
==8403==    by 0x491586: tinytest_main (tinytest.c:434)
==8403==    by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 136 bytes in 1 blocks are indirectly lost in loss record 3 of 5
==8403==    at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403==    by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403==    by 0x491EDD: evbuffer_new (buffer.c:365)
==8403==    by 0x49A0E8: bufferevent_init_common_ (bufferevent.c:305)
==8403==    by 0x4A0D31: bufferevent_socket_new (bufferevent_sock.c:353)
==8403==    by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403==    by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403==    by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403==    by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403==    by 0x490C47: testcase_run_one (tinytest.c:252)
==8403==    by 0x491586: tinytest_main (tinytest.c:434)
==8403==    by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 528 bytes in 1 blocks are indirectly lost in loss record 4 of 5
==8403==    at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403==    by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403==    by 0x4A0D02: bufferevent_socket_new (bufferevent_sock.c:350)
==8403==    by 0x4BF8BA: evhttp_connection_base_bufferevent_new (http.c:2369)
==8403==    by 0x4BFA6A: evhttp_connection_base_new (http.c:2421)
==8403==    by 0x460CFC: http_cancel_test (regress_http.c:1413)
==8403==    by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403==    by 0x490C47: testcase_run_one (tinytest.c:252)
==8403==    by 0x491586: tinytest_main (tinytest.c:434)
==8403==    by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== 1,104 (264 direct, 840 indirect) bytes in 1 blocks are definitely lost in loss record 5 of 5
==8403==    at 0x4C2BBD5: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8403==    by 0x4AAD2D: event_mm_calloc_ (event.c:3459)
==8403==    by 0x4D0326: evdns_getaddrinfo (evdns.c:4682)
==8403==    by 0x4B1213: evutil_getaddrinfo_async_ (evutil.c:1568)
==8403==    by 0x4A1255: bufferevent_socket_connect_hostname (bufferevent_sock.c:517)
==8403==    by 0x4C00B6: evhttp_connection_connect_ (http.c:2582)
==8403==    by 0x4C02B8: evhttp_make_request (http.c:2637)
==8403==    by 0x4614EC: http_cancel_test (regress_http.c:1496)
==8403==    by 0x490965: testcase_run_bare_ (tinytest.c:105)
==8403==    by 0x490C47: testcase_run_one (tinytest.c:252)
==8403==    by 0x491586: tinytest_main (tinytest.c:434)
==8403==    by 0x47DFCD: main (regress_main.c:461)
==8403==
==8403== LEAK SUMMARY:
==8403==    definitely lost: 264 bytes in 1 blocks
==8403==    indirectly lost: 840 bytes in 4 blocks
==8403==      possibly lost: 0 bytes in 0 blocks
==8403==    still reachable: 0 bytes in 0 blocks
==8403==         suppressed: 0 bytes in 0 blocks

8 years agobe_sock: evutil_getaddrinfo_async_() always return 0
Azat Khuzhin [Mon, 21 Mar 2016 13:55:59 +0000 (16:55 +0300)]
be_sock: evutil_getaddrinfo_async_() always return 0

8 years agotest/http: exit from the loop in the errorcb to wait cancellation
Azat Khuzhin [Sun, 13 Mar 2016 10:05:25 +0000 (13:05 +0300)]
test/http: exit from the loop in the errorcb to wait cancellation

This will make cancellation tests more graceful, that said that error_cb can
not be called sometimes if you will break the loop in cancel.

Plus drop that define for function generations, since function body changed,
and it is not generic anymore, plus that macro didn't used by anyone else.

8 years agoregress_clean_dnsserver(): reset global port vars
Azat Khuzhin [Tue, 22 Mar 2016 20:10:19 +0000 (23:10 +0300)]
regress_clean_dnsserver(): reset global port vars

This will fix some test chains with --no-fork.

8 years agohttp: make fallback for EVHTTP_CON_READ_ON_WRITE_ERROR more cleaner
Azat Khuzhin [Fri, 11 Mar 2016 17:17:51 +0000 (20:17 +0300)]
http: make fallback for EVHTTP_CON_READ_ON_WRITE_ERROR more cleaner

8 years agohttp: fix EVHTTP_CON_READ_ON_WRITE_ERROR when it doesn't supported by OS
Azat Khuzhin [Fri, 11 Mar 2016 16:58:05 +0000 (19:58 +0300)]
http: fix EVHTTP_CON_READ_ON_WRITE_ERROR when it doesn't supported by OS

For example win32 doesn't accept such things (maybe via overloaded IO, I'm not
sure), also I looked into curl and seems that the behaviour is the same (IOW
like with EVHTTP_CON_READ_ON_WRITE_ERROR on linux/win32).

Fixes: https://ci.appveyor.com/project/nmathewson/libevent/build/2.1.5.216#L499 (win32)
Fixes: 680742e1665b85487f10c0ef3df021e3b8e98634 ("http: read server response
even after server closed the connection")
v2: v0 was just removing that flag, i.e. make it deprecated and set_flags() will return -1

8 years agotest/http: read_on_write_error: fix it for win32
Azat Khuzhin [Fri, 11 Mar 2016 17:06:11 +0000 (20:06 +0300)]
test/http: read_on_write_error: fix it for win32

Fixes: https://ci.appveyor.com/project/nmathewson/libevent/build/2.1.5.216#L499 (win32)
8 years agohttp: do not do function calls under EVUTIL_ASSERT() to fix NDEBUG builds
Azat Khuzhin [Fri, 11 Mar 2016 16:52:32 +0000 (19:52 +0300)]
http: do not do function calls under EVUTIL_ASSERT() to fix NDEBUG builds

Fixes: 2185e639210f072f37e9d19aff7dba382db84529 ("http: assert's that
evbuffer_drain() success on connection reset")
Fixes: http/data_length_constraints
  FAIL ../test/regress_http.c:3775: assert(evhttp_request_get_response_code(req) == HTTP_ENTITYTOOLARGE): 501 vs 413

8 years agoMerge branch 'http-client-fix-expect-100-continue-v6'
Azat Khuzhin [Fri, 11 Mar 2016 17:59:36 +0000 (20:59 +0300)]
Merge branch 'http-client-fix-expect-100-continue-v6'

This patch set fixes and covers http client and "Expect: 100-continue"
functionality (plus increase coverage under some related options, to avoid
further regressions).

* http-client-fix-expect-100-continue-v6:
  http: fix leaking of response_code_line
  http: fix "Expect: 100-continue" client side
  test/http: separate coverage for EVHTTP_CON_READ_ON_WRITE_ERROR
  test/http: cover "Expect: 100-continue" client-server interaction
  test/http: *lingering tests shouldn't have "Expect: 100-continue"

8 years agohttp: fix leaking of response_code_line
Azat Khuzhin [Fri, 11 Mar 2016 17:40:52 +0000 (20:40 +0300)]
http: fix leaking of response_code_line

Since now evhttp_parse_response_line() can be called twice because after
"HTTP/1.1 100 Continue" we can have "HTTP/1.1 200"

==29162== 9 bytes in 1 blocks are definitely lost in loss record 1 of 1
==29162==    at 0x4C29C0F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==29162==    by 0x5CBF0A9: strdup (in /lib/x86_64-linux-gnu/libc-2.21.so)
==29162==    by 0x4AA3AC: event_mm_strdup_ (event.c:3493)
==29162==    by 0x4BD843: evhttp_parse_response_line (http.c:1680)
==29162==    by 0x4BE333: evhttp_parse_firstline_ (http.c:2013)
==29162==    by 0x4BEA4F: evhttp_read_firstline (http.c:2243)
==29162==    by 0x4BC5F8: evhttp_read_cb (http.c:1136)
==29162==    by 0x4993F1: bufferevent_run_readcb_ (bufferevent.c:233)
==29162==    by 0x49FBC0: bufferevent_trigger_nolock_ (bufferevent-internal.h:392)
==29162==    by 0x49FF10: bufferevent_readcb (bufferevent_sock.c:208)
==29162==    by 0x4A474A: event_persist_closure (event.c:1580)
==29162==    by 0x4A49F5: event_process_active_single_queue (event.c:1639)

Fixes: 0b46b39e95ad77951176f09782138305ba34edf3 ("http: fix "Expect:
100-continue" client side")

8 years agohttp: fix "Expect: 100-continue" client side
Azat Khuzhin [Fri, 11 Mar 2016 10:08:28 +0000 (13:08 +0300)]
http: fix "Expect: 100-continue" client side

Instead of sending data always at the beginning of the request wait until the
server will respond with "HTTP/1.1 100 Continue".
Before this patch server do send "HTTP/1.1 100 Continue" but client always send
post data even without waiting server response.

P.S. this patch also touches some not 100% related tab-align issues.

Covered-by: http/data_length_constraints
Covered-by: http/read_on_write_error
8 years agotest/http: separate coverage for EVHTTP_CON_READ_ON_WRITE_ERROR
Azat Khuzhin [Fri, 11 Mar 2016 16:25:11 +0000 (19:25 +0300)]
test/http: separate coverage for EVHTTP_CON_READ_ON_WRITE_ERROR

8 years agotest/http: cover "Expect: 100-continue" client-server interaction
Azat Khuzhin [Fri, 11 Mar 2016 11:23:03 +0000 (14:23 +0300)]
test/http: cover "Expect: 100-continue" client-server interaction

8 years agotest/http: *lingering tests shouldn't have "Expect: 100-continue"
Azat Khuzhin [Fri, 11 Mar 2016 13:18:48 +0000 (16:18 +0300)]
test/http: *lingering tests shouldn't have "Expect: 100-continue"

8 years agobe_sock: unfreeze buffers on fd changing
Azat Khuzhin [Fri, 11 Mar 2016 10:55:41 +0000 (13:55 +0300)]
be_sock: unfreeze buffers on fd changing

Only bufferevent_sock have evbuffer_freeze()/evbuffer_unfreeze() & ctrl ops, so
we don't need to fix other bufferevents (be_pair doesn't have ctrl op).

Found during draining buffers in http layer, and hence 501-not-implemented
error in regress http/.. (with some custom hacking).

8 years agohttp: assert's that evbuffer_drain() success on connection reset
Azat Khuzhin [Fri, 11 Mar 2016 11:02:13 +0000 (14:02 +0300)]
http: assert's that evbuffer_drain() success on connection reset

Since otherwise we can have nasty bugs with part of previous *request* in
current *request* and hence some parsing errors.

And now we have failures:
  http/non_lingering_close: [forking] [err] ../http.c:1326: Assertion !evbuffer_drain(tmp, -1) failed in ../http.c

8 years agotest: use EVUTIL_SHUT_WR
Azat Khuzhin [Thu, 10 Mar 2016 22:27:52 +0000 (01:27 +0300)]
test: use EVUTIL_SHUT_WR

8 years agoIgnore verify_tests.bat (win32 version)
Azat Khuzhin [Thu, 10 Mar 2016 20:51:15 +0000 (23:51 +0300)]
Ignore verify_tests.bat (win32 version)

8 years agotest/http: avoid huge stack allocations to fix win32 builds
Azat Khuzhin [Thu, 10 Mar 2016 15:40:34 +0000 (18:40 +0300)]
test/http: avoid huge stack allocations to fix win32 builds

Since according to [DOC] default stack size is 1MB, so let's use dynamic
allocations instead of changing defaults.

DOC: https://msdn.microsoft.com/en-us/library/8cxs58a6.aspx
Not-fixes: http/data_length_constraints
Fixes: http/lingering_close
Fixes: http/non_lingering_close
Fixes: https://ci.appveyor.com/project/nmathewson/libevent/build/2.1.5.213
8 years agocmake: require 3.1 only for win32 to make it work under ubunty precise
Azat Khuzhin [Wed, 9 Mar 2016 22:50:12 +0000 (01:50 +0300)]
cmake: require 3.1 only for win32 to make it work under ubunty precise

Also I [TRIED] wily but ubuntu can't upgrade transparently.

TRIED: https://travis-ci.org/azat/libevent/jobs/114924723
Fixes: https://travis-ci.org/libevent/libevent/jobs/114917275
8 years agocmake: require at least 3.1 for target_sources()
Azat Khuzhin [Wed, 9 Mar 2016 22:07:54 +0000 (01:07 +0300)]
cmake: require at least 3.1 for target_sources()

8 years agocmake: fix adding of compiler flags, and now it will
Azat Khuzhin [Wed, 9 Mar 2016 21:33:04 +0000 (00:33 +0300)]
cmake: fix adding of compiler flags, and now it will

- add_compiler_flags() must accept array IOW just ARGN will be enoough
- add_compiler_flags() called with variable name instead of it's value

P.S. and fix some alignments issues
P.P.S. more cmake issues expected since now CFLAGS actually works
P.P.P.S. some issues with cmake cache is possible, so just reset it

8 years agoReplace -Wswitch-enum with -Wswitch, and add it into cmake rules too
Azat Khuzhin [Wed, 9 Mar 2016 21:25:09 +0000 (00:25 +0300)]
Replace -Wswitch-enum with -Wswitch, and add it into cmake rules too

According to https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html:
  -Wswitch-enum
  Warn whenever a switch statement has an index of enumerated type and lacks a
  case for one or more of the named codes of that enumeration. case labels
  outside the enumeration range also provoke warnings when this option is used.
  The only difference between -Wswitch and this option is that this option
  gives a warning about an omitted enumeration code even if there is a *default
  label*.

8 years agoMerge branch 'more-graceful-http-v10'/lingering close
Azat Khuzhin [Wed, 9 Mar 2016 15:55:20 +0000 (18:55 +0300)]
Merge branch 'more-graceful-http-v10'/lingering close

In short: now `evhttp_set_max_body_size()` is browser-friendly.

This patch set implements lingering close (something like nginx have), this
will make web-server more graceful for currently existing web browsers, so:
- without EVHTTP_CON_LINGERING_CLOSE/EVHTTP_SERVER_LINGERING_CLOSE
  before: it will read min(max_body_size, Content-Length)
- with EVHTTP_CON_LINGERING_CLOSE/EVHTTP_SERVER_LINGERING_CLOSE:
  it will read max(max_body_size, Content-Length), and web browsers will show
  "413 Request Entity Too Large".

Also it fixes a bug on client-side with non-lingering close web-servers
(EVHTTP_CON_READ_ON_WRITE_ERROR), found during implementing web-server
lingering close.

* more-graceful-http-v10:
  test: http/lingering_close: cover EVHTTP_SERVER_LINGERING_CLOSE
  test: http/non_lingering_close: cover ~EVHTTP_SERVER_LINGERING_CLOSE
  test: http/*: update expected HTTP codes for body exceeds `max_body_size`
  http: take EVHTTP_CON_LINGERING_CLOSE into account for "Expect: 100-Continue"
  test: http/data_length_constrains: set EVHTTP_CON_READ_ON_WRITE_ERROR
  http: lingering close (like nginx have) for entity-too-large
  http: read server response even after server closed the connection
  test: increase buffer size for http/data_length_constraints to trigger EPIPE

Fixes: #321
Covered-by: http/non_lingering_close
Covered-by: http/lingering_close
8 years agotest: http/lingering_close: cover EVHTTP_SERVER_LINGERING_CLOSE
Azat Khuzhin [Mon, 15 Feb 2016 00:21:39 +0000 (03:21 +0300)]
test: http/lingering_close: cover EVHTTP_SERVER_LINGERING_CLOSE