We found this in #40076, after we started using buf_move_all() in
more places. Fixes bug #40076; bugfix on 0.3.3.1-alpha. As far as
I know, the crash only affects master, but I think this warrants a
backport, "just in case".
--- /dev/null
+ o Minor bugfixes (correctness, buffers):
+ - Fix a correctness bug that could cause an assertion failure if we ever
+ tried using the buf_move_all() function with an empty input.
+ As far as we know, no released versions of Tor do this.
+ Fixes bug 40076; bugfix on 0.3.3.1-alpha.
tor_assert(buf_out);
if (!buf_in)
return;
+ if (buf_datalen(buf_in) == 0)
+ return;
if (BUG(buf_out->datalen >= INT_MAX || buf_in->datalen >= INT_MAX))
return;
if (BUG(buf_out->datalen >= INT_MAX - buf_in->datalen))
buf_t *output = buf_new();
char *s = NULL;
-#if 0
/* Move from empty buffer to nonempty buffer. (This is a regression test for
* #40076) */
buf_add(output, "abc", 3);
/* Move from empty to empty. */
output = buf_new();
input = buf_new();
-#endif
buf_move_all(output, input);
buf_assert_ok(input);
buf_assert_ok(output);