From 6cb2edf4ea3adf0dfef7b7a700b0ccce2ab6e718 Mon Sep 17 00:00:00 2001 From: doug Date: Tue, 23 Jun 2015 05:58:28 +0000 Subject: [PATCH] Change CBS_dup() to also sync the offset. Previously, CBS_dup() had its own offset. However, it is more consistent to copy everything. ok miod@ jsing@ --- lib/libssl/bs_cbs.c | 3 +- lib/libssl/src/ssl/bs_cbs.c | 3 +- .../lib/libssl/bytestring/bytestringtest.c | 38 ++++++++++++++++++- 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/lib/libssl/bs_cbs.c b/lib/libssl/bs_cbs.c index ea31cfc5300..d45353a8902 100644 --- a/lib/libssl/bs_cbs.c +++ b/lib/libssl/bs_cbs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bs_cbs.c,v 1.15 2015/06/20 01:21:51 doug Exp $ */ +/* $OpenBSD: bs_cbs.c,v 1.16 2015/06/23 05:58:28 doug Exp $ */ /* * Copyright (c) 2014, Google Inc. * @@ -36,6 +36,7 @@ void CBS_dup(const CBS *cbs, CBS *out) { CBS_init(out, CBS_data(cbs), CBS_len(cbs)); + out->initial_len = cbs->initial_len; } static int diff --git a/lib/libssl/src/ssl/bs_cbs.c b/lib/libssl/src/ssl/bs_cbs.c index ea31cfc5300..d45353a8902 100644 --- a/lib/libssl/src/ssl/bs_cbs.c +++ b/lib/libssl/src/ssl/bs_cbs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bs_cbs.c,v 1.15 2015/06/20 01:21:51 doug Exp $ */ +/* $OpenBSD: bs_cbs.c,v 1.16 2015/06/23 05:58:28 doug Exp $ */ /* * Copyright (c) 2014, Google Inc. * @@ -36,6 +36,7 @@ void CBS_dup(const CBS *cbs, CBS *out) { CBS_init(out, CBS_data(cbs), CBS_len(cbs)); + out->initial_len = cbs->initial_len; } static int diff --git a/regress/lib/libssl/bytestring/bytestringtest.c b/regress/lib/libssl/bytestring/bytestringtest.c index d989868c852..3275e6f2c72 100644 --- a/regress/lib/libssl/bytestring/bytestringtest.c +++ b/regress/lib/libssl/bytestring/bytestringtest.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bytestringtest.c,v 1.7 2015/06/23 01:20:24 doug Exp $ */ +/* $OpenBSD: bytestringtest.c,v 1.8 2015/06/23 05:58:28 doug Exp $ */ /* * Copyright (c) 2014, Google Inc. * @@ -751,6 +751,41 @@ err: return ret; } +static int +test_cbs_dup(void) +{ + CBS data, check; + static const uint8_t input[] = {'f', 'o', 'o', 'b', 'a', 'r'}; + + CBS_init(&data, input, sizeof(input)); + CHECK(CBS_len(&data) == 6); + CBS_dup(&data, &check); + CHECK(CBS_len(&check) == 6); + CHECK(CBS_data(&data) == CBS_data(&check)); + CHECK(CBS_skip(&data, 1)); + CHECK(CBS_len(&data) == 5); + CHECK(CBS_len(&check) == 6); + CHECK(CBS_data(&data) == CBS_data(&check) + 1); + CHECK(CBS_skip(&check, 1)); + CHECK(CBS_len(&data) == 5); + CHECK(CBS_len(&check) == 5); + CHECK(CBS_data(&data) == CBS_data(&check)); + CHECK(CBS_offset(&data) == 1); + CHECK(CBS_offset(&check) == 1); + + CBS_init(&data, input, sizeof(input)); + CHECK(CBS_skip(&data, 5)); + CBS_dup(&data, &check); + CHECK(CBS_len(&data) == 1); + CHECK(CBS_len(&check) == 1); + CHECK(CBS_data(&data) == input + 5); + CHECK(CBS_data(&data) == CBS_data(&check)); + CHECK(CBS_offset(&data) == 5); + CHECK(CBS_offset(&check) == 5); + + return 1; +} + int main(void) { @@ -772,6 +807,7 @@ main(void) failed |= !test_get_optional_asn1_bool(); failed |= !test_offset(); failed |= !test_write_bytes(); + failed |= !test_cbs_dup(); if (!failed) printf("PASS\n"); -- 2.20.1