| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/asn1/f_string.c |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /* | - | ||||||||||||
| 2 | * Copyright 1995-2017 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/ctype.h" | - | ||||||||||||
| 12 | #include "internal/cryptlib.h" | - | ||||||||||||
| 13 | #include <openssl/buffer.h> | - | ||||||||||||
| 14 | #include <openssl/asn1.h> | - | ||||||||||||
| 15 | - | |||||||||||||
| 16 | int i2a_ASN1_STRING(BIO *bp, const ASN1_STRING *a, int type) | - | ||||||||||||
| 17 | { | - | ||||||||||||
| 18 | int i, n = 0; | - | ||||||||||||
| 19 | static const char *h = "0123456789ABCDEF"; | - | ||||||||||||
| 20 | char buf[2]; | - | ||||||||||||
| 21 | - | |||||||||||||
| 22 | if (a == NULL)
| 0-982 | ||||||||||||
| 23 | return 0; never executed: return 0; | 0 | ||||||||||||
| 24 | - | |||||||||||||
| 25 | if (a->length == 0) {
| 468-514 | ||||||||||||
| 26 | if (BIO_write(bp, "0", 1) != 1)
| 0-514 | ||||||||||||
| 27 | goto err; never executed: goto err; | 0 | ||||||||||||
| 28 | n = 1; | - | ||||||||||||
| 29 | } else { executed 514 times by 1 test: end of blockExecuted by:
| 514 | ||||||||||||
| 30 | for (i = 0; i < a->length; i++) {
| 468-16828 | ||||||||||||
| 31 | if ((i != 0) && (i % 35 == 0)) {
| 393-16360 | ||||||||||||
| 32 | if (BIO_write(bp, "\\\n", 2) != 2)
| 0-393 | ||||||||||||
| 33 | goto err; never executed: goto err; | 0 | ||||||||||||
| 34 | n += 2; | - | ||||||||||||
| 35 | } executed 393 times by 1 test: end of blockExecuted by:
| 393 | ||||||||||||
| 36 | buf[0] = h[((unsigned char)a->data[i] >> 4) & 0x0f]; | - | ||||||||||||
| 37 | buf[1] = h[((unsigned char)a->data[i]) & 0x0f]; | - | ||||||||||||
| 38 | if (BIO_write(bp, buf, 2) != 2)
| 0-16828 | ||||||||||||
| 39 | goto err; never executed: goto err; | 0 | ||||||||||||
| 40 | n += 2; | - | ||||||||||||
| 41 | } executed 16828 times by 1 test: end of blockExecuted by:
| 16828 | ||||||||||||
| 42 | } executed 468 times by 1 test: end of blockExecuted by:
| 468 | ||||||||||||
| 43 | return n; executed 982 times by 1 test: return n;Executed by:
| 982 | ||||||||||||
| 44 | err: | - | ||||||||||||
| 45 | return -1; never executed: return -1; | 0 | ||||||||||||
| 46 | } | - | ||||||||||||
| 47 | - | |||||||||||||
| 48 | int a2i_ASN1_STRING(BIO *bp, ASN1_STRING *bs, char *buf, int size) | - | ||||||||||||
| 49 | { | - | ||||||||||||
| 50 | int i, j, k, m, n, again, bufsize; | - | ||||||||||||
| 51 | unsigned char *s = NULL, *sp; | - | ||||||||||||
| 52 | unsigned char *bufp; | - | ||||||||||||
| 53 | int num = 0, slen = 0, first = 1; | - | ||||||||||||
| 54 | - | |||||||||||||
| 55 | bufsize = BIO_gets(bp, buf, size); | - | ||||||||||||
| 56 | for (;;) { | - | ||||||||||||
| 57 | if (bufsize < 1) {
| 0 | ||||||||||||
| 58 | if (first)
| 0 | ||||||||||||
| 59 | break; never executed: break; | 0 | ||||||||||||
| 60 | else | - | ||||||||||||
| 61 | goto err; never executed: goto err; | 0 | ||||||||||||
| 62 | } | - | ||||||||||||
| 63 | first = 0; | - | ||||||||||||
| 64 | - | |||||||||||||
| 65 | i = bufsize; | - | ||||||||||||
| 66 | if (buf[i - 1] == '\n')
| 0 | ||||||||||||
| 67 | buf[--i] = '\0'; never executed: buf[--i] = '\0'; | 0 | ||||||||||||
| 68 | if (i == 0)
| 0 | ||||||||||||
| 69 | goto err; never executed: goto err; | 0 | ||||||||||||
| 70 | if (buf[i - 1] == '\r')
| 0 | ||||||||||||
| 71 | buf[--i] = '\0'; never executed: buf[--i] = '\0'; | 0 | ||||||||||||
| 72 | if (i == 0)
| 0 | ||||||||||||
| 73 | goto err; never executed: goto err; | 0 | ||||||||||||
| 74 | again = (buf[i - 1] == '\\'); | - | ||||||||||||
| 75 | - | |||||||||||||
| 76 | for (j = i - 1; j > 0; j--) {
| 0 | ||||||||||||
| 77 | if (!ossl_isxdigit(buf[j])) {
| 0 | ||||||||||||
| 78 | i = j; | - | ||||||||||||
| 79 | break; never executed: break; | 0 | ||||||||||||
| 80 | } | - | ||||||||||||
| 81 | } never executed: end of block | 0 | ||||||||||||
| 82 | buf[i] = '\0'; | - | ||||||||||||
| 83 | /* | - | ||||||||||||
| 84 | * We have now cleared all the crap off the end of the line | - | ||||||||||||
| 85 | */ | - | ||||||||||||
| 86 | if (i < 2)
| 0 | ||||||||||||
| 87 | goto err; never executed: goto err; | 0 | ||||||||||||
| 88 | - | |||||||||||||
| 89 | bufp = (unsigned char *)buf; | - | ||||||||||||
| 90 | - | |||||||||||||
| 91 | k = 0; | - | ||||||||||||
| 92 | i -= again; | - | ||||||||||||
| 93 | if (i % 2 != 0) {
| 0 | ||||||||||||
| 94 | ASN1err(ASN1_F_A2I_ASN1_STRING, ASN1_R_ODD_NUMBER_OF_CHARS); | - | ||||||||||||
| 95 | OPENSSL_free(s); | - | ||||||||||||
| 96 | return 0; never executed: return 0; | 0 | ||||||||||||
| 97 | } | - | ||||||||||||
| 98 | i /= 2; | - | ||||||||||||
| 99 | if (num + i > slen) {
| 0 | ||||||||||||
| 100 | sp = OPENSSL_realloc(s, (unsigned int)num + i * 2); | - | ||||||||||||
| 101 | if (sp == NULL) {
| 0 | ||||||||||||
| 102 | ASN1err(ASN1_F_A2I_ASN1_STRING, ERR_R_MALLOC_FAILURE); | - | ||||||||||||
| 103 | OPENSSL_free(s); | - | ||||||||||||
| 104 | return 0; never executed: return 0; | 0 | ||||||||||||
| 105 | } | - | ||||||||||||
| 106 | s = sp; | - | ||||||||||||
| 107 | slen = num + i * 2; | - | ||||||||||||
| 108 | } never executed: end of block | 0 | ||||||||||||
| 109 | for (j = 0; j < i; j++, k += 2) {
| 0 | ||||||||||||
| 110 | for (n = 0; n < 2; n++) {
| 0 | ||||||||||||
| 111 | m = OPENSSL_hexchar2int(bufp[k + n]); | - | ||||||||||||
| 112 | if (m < 0) {
| 0 | ||||||||||||
| 113 | ASN1err(ASN1_F_A2I_ASN1_STRING, | - | ||||||||||||
| 114 | ASN1_R_NON_HEX_CHARACTERS); | - | ||||||||||||
| 115 | OPENSSL_free(s); | - | ||||||||||||
| 116 | return 0; never executed: return 0; | 0 | ||||||||||||
| 117 | } | - | ||||||||||||
| 118 | s[num + j] <<= 4; | - | ||||||||||||
| 119 | s[num + j] |= m; | - | ||||||||||||
| 120 | } never executed: end of block | 0 | ||||||||||||
| 121 | } never executed: end of block | 0 | ||||||||||||
| 122 | num += i; | - | ||||||||||||
| 123 | if (again)
| 0 | ||||||||||||
| 124 | bufsize = BIO_gets(bp, buf, size); never executed: bufsize = BIO_gets(bp, buf, size); | 0 | ||||||||||||
| 125 | else | - | ||||||||||||
| 126 | break; never executed: break; | 0 | ||||||||||||
| 127 | } | - | ||||||||||||
| 128 | bs->length = num; | - | ||||||||||||
| 129 | bs->data = s; | - | ||||||||||||
| 130 | return 1; never executed: return 1; | 0 | ||||||||||||
| 131 | - | |||||||||||||
| 132 | err: | - | ||||||||||||
| 133 | ASN1err(ASN1_F_A2I_ASN1_STRING, ASN1_R_SHORT_LINE); | - | ||||||||||||
| 134 | OPENSSL_free(s); | - | ||||||||||||
| 135 | return 0; never executed: return 0; | 0 | ||||||||||||
| 136 | } | - | ||||||||||||
| Source code | Switch to Preprocessed file |