/src/openssl111/crypto/asn1/a_dup.c
| Line | Count | Source (jump to first uncovered line) | 
| 1 |  | /* | 
| 2 |  |  * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. | 
| 3 |  |  * | 
| 4 |  |  * Licensed under the OpenSSL license (the "License").  You may not use | 
| 5 |  |  * this file except in compliance with the License.  You can obtain a copy | 
| 6 |  |  * in the file LICENSE in the source distribution or at | 
| 7 |  |  * https://www.openssl.org/source/license.html | 
| 8 |  |  */ | 
| 9 |  |  | 
| 10 |  | #include <stdio.h> | 
| 11 |  | #include "internal/cryptlib.h" | 
| 12 |  | #include <openssl/asn1.h> | 
| 13 |  |  | 
| 14 |  | #ifndef NO_OLD_ASN1 | 
| 15 |  |  | 
| 16 |  | void *ASN1_dup(i2d_of_void *i2d, d2i_of_void *d2i, void *x) | 
| 17 | 0 | { | 
| 18 | 0 |     unsigned char *b, *p; | 
| 19 | 0 |     const unsigned char *p2; | 
| 20 | 0 |     int i; | 
| 21 | 0 |     char *ret; | 
| 22 |  | 
 | 
| 23 | 0 |     if (x == NULL) | 
| 24 | 0 |         return NULL; | 
| 25 |  |  | 
| 26 | 0 |     i = i2d(x, NULL); | 
| 27 | 0 |     b = OPENSSL_malloc(i + 10); | 
| 28 | 0 |     if (b == NULL) { | 
| 29 | 0 |         ASN1err(ASN1_F_ASN1_DUP, ERR_R_MALLOC_FAILURE); | 
| 30 | 0 |         return NULL; | 
| 31 | 0 |     } | 
| 32 | 0 |     p = b; | 
| 33 | 0 |     i = i2d(x, &p); | 
| 34 | 0 |     p2 = b; | 
| 35 | 0 |     ret = d2i(NULL, &p2, i); | 
| 36 | 0 |     OPENSSL_free(b); | 
| 37 | 0 |     return ret; | 
| 38 | 0 | } | 
| 39 |  |  | 
| 40 |  | #endif | 
| 41 |  |  | 
| 42 |  | /* | 
| 43 |  |  * ASN1_ITEM version of dup: this follows the model above except we don't | 
| 44 |  |  * need to allocate the buffer. At some point this could be rewritten to | 
| 45 |  |  * directly dup the underlying structure instead of doing and encode and | 
| 46 |  |  * decode. | 
| 47 |  |  */ | 
| 48 |  |  | 
| 49 |  | void *ASN1_item_dup(const ASN1_ITEM *it, void *x) | 
| 50 | 4.41k | { | 
| 51 | 4.41k |     unsigned char *b = NULL; | 
| 52 | 4.41k |     const unsigned char *p; | 
| 53 | 4.41k |     long i; | 
| 54 | 4.41k |     void *ret; | 
| 55 |  |  | 
| 56 | 4.41k |     if (x == NULL) | 
| 57 | 0 |         return NULL; | 
| 58 |  |  | 
| 59 | 4.41k |     i = ASN1_item_i2d(x, &b, it); | 
| 60 | 4.41k |     if (b == NULL) { | 
| 61 | 0 |         ASN1err(ASN1_F_ASN1_ITEM_DUP, ERR_R_MALLOC_FAILURE); | 
| 62 | 0 |         return NULL; | 
| 63 | 0 |     } | 
| 64 | 4.41k |     p = b; | 
| 65 | 4.41k |     ret = ASN1_item_d2i(NULL, &p, i, it); | 
| 66 | 4.41k |     OPENSSL_free(b); | 
| 67 | 4.41k |     return ret; | 
| 68 | 4.41k | } |