From f1886c45ee8253653eef1b3dc18b3aed953df0b0 Mon Sep 17 00:00:00 2001 From: Graham Leggett Date: Fri, 30 Aug 2024 15:07:05 +0000 Subject: [PATCH] apr_buffer: Advance buffer during apr_buffer_pstrncat(). git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1920293 13f79535-47bb-0310-9956-ffa450edef68 --- buffer/apr_buffer.c | 1 + test/abts_tests.h | 2 +- test/testbuffer.c | 14 ++++++++------ 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/buffer/apr_buffer.c b/buffer/apr_buffer.c index 073bac0cb9..4efd1ef75d 100644 --- a/buffer/apr_buffer.c +++ b/buffer/apr_buffer.c @@ -394,6 +394,7 @@ APR_DECLARE(char *) apr_buffer_pstrncat(apr_pool_t *p, const apr_buffer_t *buf, else { if (APR_BUFFER_PLAIN == flags) { memcpy(dst, src->d.mem, src->size); + dst += src->size; } else if (APR_BUFFER_BASE64 == flags) { apr_size_t b64len; diff --git a/test/abts_tests.h b/test/abts_tests.h index 7dbd9aeac2..0437aa4ff6 100644 --- a/test/abts_tests.h +++ b/test/abts_tests.h @@ -74,6 +74,7 @@ const struct testlist { {testuri}, {testuuid}, {testbuckets}, + {testbuffer}, {testpass}, {testbase64}, {testmd4}, @@ -94,7 +95,6 @@ const struct testlist { {testsiphash}, {testjson}, {testjose}, - {testbuffer}, {testldap} }; diff --git a/test/testbuffer.c b/test/testbuffer.c index 1453ae5ea8..fd4d7edc32 100644 --- a/test/testbuffer.c +++ b/test/testbuffer.c @@ -167,7 +167,7 @@ static void test_buffers(abts_case *tc, void *data) apr_pool_t *pool; apr_array_header_t *vals; - apr_buffer_t src[2]; + apr_buffer_t src[4]; apr_buffer_t *dst; char *str; @@ -180,11 +180,13 @@ static void test_buffers(abts_case *tc, void *data) /* populate our source buffers */ apr_buffer_mem_set(&src[0], test_memory, sizeof(test_memory)); apr_buffer_str_set(&src[1], test_string, strlen(test_string)); + apr_buffer_mem_set(&src[2], test_memory, sizeof(test_memory)); + apr_buffer_str_set(&src[3], test_string, strlen(test_string)); /* duplicate the source buffers, allocating memory from a pool */ - vals = apr_array_make(pool, 2, sizeof(apr_buffer_t)); - apr_buffer_arraydup((apr_buffer_t **)(&vals->elts), src, test_buffers_palloc, pool, 2); - vals->nelts = 2; + vals = apr_array_make(pool, 4, sizeof(apr_buffer_t)); + apr_buffer_arraydup((apr_buffer_t **)(&vals->elts), src, test_buffers_palloc, pool, 4); + vals->nelts = 4; dst = apr_array_pop(vals); @@ -201,10 +203,10 @@ static void test_buffers(abts_case *tc, void *data) ABTS_ASSERT(tc, "buffer copy fail", !apr_buffer_cmp(dst, &src[1])); - str = apr_buffer_pstrncat(pool, &src[0], 2, "; ", APR_BUFFER_BASE64, &len); + str = apr_buffer_pstrncat(pool, &src[0], 4, "; ", APR_BUFFER_BASE64, &len); ABTS_ASSERT(tc, "buffer strcat fail", - !strcmp(str, "AQIDBA==; Hello")); + !strcmp(str, "AQIDBA==; Hello; AQIDBA==; Hello")); apr_pool_destroy(pool); }