buffer_list_aggregate_separator() would merge buffer_list entries until it
had exceeded the provided max_len, instead of stopping *before* exceeding
the max value.
Signed-off-by: Steffan Karger <steffan.karger@fox-it.com>
Acked-by: Antonio Quartulli <antonio@openvpn.net>
Message-Id: <
1514541191-19471-1-git-send-email-steffan.karger@fox-it.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg16104.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit
fb6138dd32cf01922d7ef670d502148596511268)
}
void
-buffer_list_aggregate_separator(struct buffer_list *bl, const size_t max, const char *sep)
+buffer_list_aggregate_separator(struct buffer_list *bl, const size_t max_len,
+ const char *sep)
{
int sep_len = strlen(sep);
struct buffer_entry *more = bl->head;
size_t size = 0;
int count = 0;
- for (count = 0; more && size <= max; ++count)
+ for (count = 0; more; ++count)
{
- size += BLEN(&more->buf) + sep_len;
+ size_t extra_len = BLEN(&more->buf) + sep_len;
+ if (size + extra_len > max_len)
+ {
+ break;
+ }
+
+ size += extra_len;
more = more->next;
}
void buffer_list_aggregate(struct buffer_list *bl, const size_t max);
-void buffer_list_aggregate_separator(struct buffer_list *bl, const size_t max, const char *sep);
+void buffer_list_aggregate_separator(struct buffer_list *bl,
+ const size_t max_len, const char *sep);
struct buffer_list *buffer_list_file(const char *fn, int max_line_len);
test_buffer_list_aggregate_separator_two(void **state)
{
struct test_buffer_list_aggregate_ctx *ctx = *state;
+ const char *expected = teststr1 testsep teststr2 testsep;
- /* Aggregate the first two elements */
- /* FIXME this exceeds the supplied max */
- buffer_list_aggregate_separator(ctx->one_two_three, 4, testsep);
+ /* Aggregate the first two elements
+ * (add 1 to max_len to test if "three" is not sneaked in too)
+ */
+ buffer_list_aggregate_separator(ctx->one_two_three, strlen(expected) + 1,
+ testsep);
assert_int_equal(ctx->one_two_three->size, 2);
struct buffer *buf = buffer_list_peek(ctx->one_two_three);
- assert_buf_equals_str(buf, teststr1 testsep teststr2 testsep);
+ assert_buf_equals_str(buf, expected);
}
static void