From 9586a1cbb00d84d2c913d6719aa0ba614dbc1d7a Mon Sep 17 00:00:00 2001 From: Niels Provos Date: Sun, 1 Jun 2008 16:21:24 +0000 Subject: [PATCH] fix an evbuffer corruption when adding an empty evbuffer; from Scott Lamb svn:r845 --- buffer.c | 3 +++ test/regress.c | 3 +++ 2 files changed, 6 insertions(+) diff --git a/buffer.c b/buffer.c index 76397048..bb3c44d1 100644 --- a/buffer.c +++ b/buffer.c @@ -196,6 +196,9 @@ evbuffer_add_buffer(struct evbuffer *outbuf, struct evbuffer *inbuf) size_t out_total_len = outbuf->total_len; size_t in_total_len = inbuf->total_len; + if (in_total_len == 0) + return (0); + if (out_total_len == 0) { COPY_CHAIN(outbuf, inbuf); } else { diff --git a/test/regress.c b/test/regress.c index a6ca9b4d..063fb1b9 100644 --- a/test/regress.c +++ b/test/regress.c @@ -985,6 +985,9 @@ test_evbuffer(void) memcmp((char*)EVBUFFER_DATA(evb), "hello/1", 1) != 0) goto out; + evbuffer_add_buffer(evb, evb_two); + evbuffer_validate(evb); + evbuffer_drain(evb, strlen("hello/")); evbuffer_validate(evb); if (EVBUFFER_LENGTH(evb) != 1 ||