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
This commit is contained in:
Azat Khuzhin 2016-06-26 01:57:45 +03:00
commit 70040c0989
2 changed files with 19 additions and 2 deletions

View File

@ -1982,8 +1982,7 @@ evbuffer_expand_singlechain(struct evbuffer *buf, size_t datlen)
/* Would expanding this chunk be affordable and worthwhile? */
if (CHAIN_SPACE_LEN(chain) < chain->buffer_len / 8 ||
chain->off > MAX_TO_COPY_IN_EXPAND ||
(datlen < EVBUFFER_CHAIN_MAX &&
EVBUFFER_CHAIN_MAX - datlen >= chain->off)) {
datlen >= (EVBUFFER_CHAIN_MAX - chain->off)) {
/* It's not worth resizing this chain. Can the next one be
* used? */
if (chain->next && CHAIN_SPACE_LEN(chain->next) >= datlen) {

View File

@ -708,6 +708,23 @@ end:
evbuffer_free(buf);
}
static void
test_evbuffer_expand_overflow(void *ptr)
{
struct evbuffer *buf;
buf = evbuffer_new();
evbuffer_add(buf, "1", 1);
evbuffer_expand(buf, EVBUFFER_CHAIN_MAX);
evbuffer_validate(buf);
evbuffer_expand(buf, EV_SIZE_MAX);
evbuffer_validate(buf);
end:
evbuffer_free(buf);
}
static void
test_evbuffer_add1(void *ptr)
{
@ -2494,6 +2511,7 @@ struct testcase_t evbuffer_testcases[] = {
{ "reserve_many2", test_evbuffer_reserve_many, 0, &nil_setup, (void*)"add" },
{ "reserve_many3", test_evbuffer_reserve_many, 0, &nil_setup, (void*)"fill" },
{ "expand", test_evbuffer_expand, 0, NULL, NULL },
{ "expand_overflow", test_evbuffer_expand_overflow, 0, NULL, NULL },
{ "add1", test_evbuffer_add1, 0, NULL, NULL },
{ "add2", test_evbuffer_add2, 0, NULL, NULL },
{ "reference", test_evbuffer_reference, 0, NULL, NULL },