/src/boringssl/crypto/bytestring/asn1_compat.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* Copyright (c) 2016, Google Inc. |
2 | | * |
3 | | * Permission to use, copy, modify, and/or distribute this software for any |
4 | | * purpose with or without fee is hereby granted, provided that the above |
5 | | * copyright notice and this permission notice appear in all copies. |
6 | | * |
7 | | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
8 | | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
9 | | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
10 | | * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
11 | | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION |
12 | | * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
13 | | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ |
14 | | |
15 | | |
16 | | #include <openssl/bytestring.h> |
17 | | |
18 | | #include <assert.h> |
19 | | #include <limits.h> |
20 | | #include <string.h> |
21 | | |
22 | | #include <openssl/mem.h> |
23 | | |
24 | | #include "internal.h" |
25 | | #include "../internal.h" |
26 | | |
27 | | |
28 | 122 | int CBB_finish_i2d(CBB *cbb, uint8_t **outp) { |
29 | 122 | assert(!cbb->is_child); |
30 | 122 | assert(cbb->u.base.can_resize); |
31 | | |
32 | 122 | uint8_t *der; |
33 | 122 | size_t der_len; |
34 | 122 | if (!CBB_finish(cbb, &der, &der_len)) { |
35 | 0 | CBB_cleanup(cbb); |
36 | 0 | return -1; |
37 | 0 | } |
38 | 122 | if (der_len > INT_MAX) { |
39 | 0 | OPENSSL_free(der); |
40 | 0 | return -1; |
41 | 0 | } |
42 | 122 | if (outp != NULL) { |
43 | 122 | if (*outp == NULL) { |
44 | 122 | *outp = der; |
45 | 122 | der = NULL; |
46 | 122 | } else { |
47 | 0 | OPENSSL_memcpy(*outp, der, der_len); |
48 | 0 | *outp += der_len; |
49 | 0 | } |
50 | 122 | } |
51 | 122 | OPENSSL_free(der); |
52 | 122 | return (int)der_len; |
53 | 122 | } |