diff options
author | Emilia Kasper <emilia@openssl.org> | 2015-09-01 18:19:14 +0200 |
---|---|---|
committer | Emilia Kasper <emilia@openssl.org> | 2015-09-09 12:47:05 +0200 |
commit | 6d41fc80e6152a6bf9d062b2a8e835a388ed0062 (patch) | |
tree | cc392b5acae15a064d074c2cdef7838bb2f37139 /test/packettest.c | |
parent | d728f0f5f28c9c5347ac371373e3cd4cb350760f (diff) | |
download | openssl-6d41fc80e6152a6bf9d062b2a8e835a388ed0062.tar.gz |
PACKET: add PACKET_memdup and PACKET_strndup
Use each once in s3_srvr.c to show how they work.
Also fix a bug introduced in c3fc7eeab884b6876a1b4006163f190d325aa047
and made apparent by this change:
ssl3_get_next_proto wasn't updating next_proto_negotiated_len
Reviewed-by: Matt Caswell <matt@openssl.org>
Diffstat (limited to 'test/packettest.c')
-rw-r--r-- | test/packettest.c | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/test/packettest.c b/test/packettest.c index b3f7bbb19e..23b60857f1 100644 --- a/test/packettest.c +++ b/test/packettest.c @@ -230,6 +230,57 @@ static int test_PACKET_copy_bytes(PACKET *pkt, size_t start) return 1; } +static int test_PACKET_memdup(PACKET *pkt, size_t start) +{ + unsigned char *data = NULL; + size_t len; + if ( !PACKET_goto_bookmark(pkt, start) + || !PACKET_memdup(pkt, &data, &len) + || len != BUF_LEN + || memcmp(data, PACKET_data(pkt), len) + || !PACKET_forward(pkt, 10) + || !PACKET_memdup(pkt, &data, &len) + || len != BUF_LEN - 10 + || memcmp(data, PACKET_data(pkt), len) + || !PACKET_back(pkt, 1) + || !PACKET_memdup(pkt, &data, &len) + || len != BUF_LEN - 9 + || memcmp(data, PACKET_data(pkt), len)) { + fprintf(stderr, "test_PACKET_memdup() failed\n"); + OPENSSL_free(data); + return 0; + } + + OPENSSL_free(data); + return 1; +} + +static int test_PACKET_strndup() +{ + char buf[10], buf2[10]; + memset(buf, 'x', 10); + memset(buf2, 'y', 10); + buf2[5] = '\0'; + char *data = NULL; + PACKET pkt; + + if ( !PACKET_buf_init(&pkt, (unsigned char*)buf, 10) + || !PACKET_strndup(&pkt, &data) + || strlen(data) != 10 + || strncmp(data, buf, 10) + || !PACKET_buf_init(&pkt, (unsigned char*)buf2, 10) + || !PACKET_strndup(&pkt, &data) + || strlen(data) != 5 + || strcmp(data, buf2)) { + fprintf(stderr, "test_PACKET_strndup failed\n"); + OPENSSL_free(data); + return 0; + } + + OPENSSL_free(data); + return 1; +} + static int test_PACKET_move_funcs(PACKET *pkt, size_t start) { unsigned char *byte; @@ -388,6 +439,8 @@ int main(int argc, char **argv) || !test_PACKET_get_sub_packet(&pkt, start) || !test_PACKET_get_bytes(&pkt, start) || !test_PACKET_copy_bytes(&pkt, start) + || !test_PACKET_memdup(&pkt, start) + || !test_PACKET_strndup() || !test_PACKET_move_funcs(&pkt, start) || !test_PACKET_get_length_prefixed_1() || !test_PACKET_get_length_prefixed_2() |