diff options
author | Nick Mathewson <nickm@torproject.org> | 2018-09-21 09:40:16 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2018-09-21 09:40:16 -0400 |
commit | 0e4c42a912d020888e811b748925362e1b3dc67b (patch) | |
tree | 90a9e0e682a06bdf1af1ea9b0940dd81e20786e2 /src/test/test_helpers.c | |
parent | a1b0283040723474377a5746dbd01782a9b7eaa7 (diff) | |
parent | 03ef4ec466fd7f1de097a7b0244ca5bc8cc32b18 (diff) | |
download | tor-0e4c42a912d020888e811b748925362e1b3dc67b.tar.gz tor-0e4c42a912d020888e811b748925362e1b3dc67b.zip |
Merge remote-tracking branch 'ahf-github/asn/bugs4700_2'
Diffstat (limited to 'src/test/test_helpers.c')
-rw-r--r-- | src/test/test_helpers.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/test/test_helpers.c b/src/test/test_helpers.c index 0a2da100ba..6ac73bff5c 100644 --- a/src/test/test_helpers.c +++ b/src/test/test_helpers.c @@ -125,6 +125,25 @@ connection_write_to_buf_mock(const char *string, size_t len, buf_add(conn->outbuf, string, len); } +char * +buf_get_contents(buf_t *buf, size_t *sz_out) +{ + tor_assert(buf); + tor_assert(sz_out); + + char *out; + *sz_out = buf_datalen(buf); + if (*sz_out >= ULONG_MAX) + return NULL; /* C'mon, really? */ + out = tor_malloc(*sz_out + 1); + if (buf_get_bytes(buf, out, (unsigned long)*sz_out) != 0) { + tor_free(out); + return NULL; + } + out[*sz_out] = '\0'; /* Hopefully gratuitous. */ + return out; +} + /* Set up a fake origin circuit with the specified number of cells, * Return a pointer to the newly-created dummy circuit */ circuit_t * |