| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/x509/x509_obj.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/cryptlib.h" | - | ||||||||||||
| 12 | #include <openssl/objects.h> | - | ||||||||||||
| 13 | #include <openssl/x509.h> | - | ||||||||||||
| 14 | #include <openssl/buffer.h> | - | ||||||||||||
| 15 | #include "internal/x509_int.h" | - | ||||||||||||
| 16 | - | |||||||||||||
| 17 | /* | - | ||||||||||||
| 18 | * Limit to ensure we don't overflow: much greater than | - | ||||||||||||
| 19 | * anything encountered in practice. | - | ||||||||||||
| 20 | */ | - | ||||||||||||
| 21 | - | |||||||||||||
| 22 | #define NAME_ONELINE_MAX (1024 * 1024) | - | ||||||||||||
| 23 | - | |||||||||||||
| 24 | char *X509_NAME_oneline(const X509_NAME *a, char *buf, int len) | - | ||||||||||||
| 25 | { | - | ||||||||||||
| 26 | const X509_NAME_ENTRY *ne; | - | ||||||||||||
| 27 | int i; | - | ||||||||||||
| 28 | int n, lold, l, l1, l2, num, j, type; | - | ||||||||||||
| 29 | const char *s; | - | ||||||||||||
| 30 | char *p; | - | ||||||||||||
| 31 | unsigned char *q; | - | ||||||||||||
| 32 | BUF_MEM *b = NULL; | - | ||||||||||||
| 33 | static const char hex[17] = "0123456789ABCDEF"; | - | ||||||||||||
| 34 | int gs_doit[4]; | - | ||||||||||||
| 35 | char tmp_buf[80]; | - | ||||||||||||
| 36 | #ifdef CHARSET_EBCDIC | - | ||||||||||||
| 37 | unsigned char ebcdic_buf[1024]; | - | ||||||||||||
| 38 | #endif | - | ||||||||||||
| 39 | - | |||||||||||||
| 40 | if (buf == NULL) {
| 471-5798 | ||||||||||||
| 41 | if ((b = BUF_MEM_new()) == NULL)
| 0-5798 | ||||||||||||
| 42 | goto err; never executed: goto err; | 0 | ||||||||||||
| 43 | if (!BUF_MEM_grow(b, 200))
| 0-5798 | ||||||||||||
| 44 | goto err; never executed: goto err; | 0 | ||||||||||||
| 45 | b->data[0] = '\0'; | - | ||||||||||||
| 46 | len = 200; | - | ||||||||||||
| 47 | } else if (len == 0) { executed 5798 times by 1 test: end of blockExecuted by:
| 0-5798 | ||||||||||||
| 48 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||
| 49 | } | - | ||||||||||||
| 50 | if (a == NULL) {
| 0-6269 | ||||||||||||
| 51 | if (b) {
| 0 | ||||||||||||
| 52 | buf = b->data; | - | ||||||||||||
| 53 | OPENSSL_free(b); | - | ||||||||||||
| 54 | } never executed: end of block | 0 | ||||||||||||
| 55 | strncpy(buf, "NO X509_NAME", len); | - | ||||||||||||
| 56 | buf[len - 1] = '\0'; | - | ||||||||||||
| 57 | return buf; never executed: return buf; | 0 | ||||||||||||
| 58 | } | - | ||||||||||||
| 59 | - | |||||||||||||
| 60 | len--; /* space for '\0' */ | - | ||||||||||||
| 61 | l = 0; | - | ||||||||||||
| 62 | for (i = 0; i < sk_X509_NAME_ENTRY_num(a->entries); i++) {
| 6266-13855 | ||||||||||||
| 63 | ne = sk_X509_NAME_ENTRY_value(a->entries, i); | - | ||||||||||||
| 64 | n = OBJ_obj2nid(ne->object); | - | ||||||||||||
| 65 | if ((n == NID_undef) || ((s = OBJ_nid2sn(n)) == NULL)) {
| 0-8779 | ||||||||||||
| 66 | i2t_ASN1_OBJECT(tmp_buf, sizeof(tmp_buf), ne->object); | - | ||||||||||||
| 67 | s = tmp_buf; | - | ||||||||||||
| 68 | } executed 8779 times by 1 test: end of blockExecuted by:
| 8779 | ||||||||||||
| 69 | l1 = strlen(s); | - | ||||||||||||
| 70 | - | |||||||||||||
| 71 | type = ne->value->type; | - | ||||||||||||
| 72 | num = ne->value->length; | - | ||||||||||||
| 73 | if (num > NAME_ONELINE_MAX) {
| 0-13855 | ||||||||||||
| 74 | X509err(X509_F_X509_NAME_ONELINE, X509_R_NAME_TOO_LONG); | - | ||||||||||||
| 75 | goto end; never executed: goto end; | 0 | ||||||||||||
| 76 | } | - | ||||||||||||
| 77 | q = ne->value->data; | - | ||||||||||||
| 78 | #ifdef CHARSET_EBCDIC | - | ||||||||||||
| 79 | if (type == V_ASN1_GENERALSTRING || | - | ||||||||||||
| 80 | type == V_ASN1_VISIBLESTRING || | - | ||||||||||||
| 81 | type == V_ASN1_PRINTABLESTRING || | - | ||||||||||||
| 82 | type == V_ASN1_TELETEXSTRING || | - | ||||||||||||
| 83 | type == V_ASN1_IA5STRING) { | - | ||||||||||||
| 84 | if (num > (int)sizeof(ebcdic_buf)) | - | ||||||||||||
| 85 | num = sizeof(ebcdic_buf); | - | ||||||||||||
| 86 | ascii2ebcdic(ebcdic_buf, q, num); | - | ||||||||||||
| 87 | q = ebcdic_buf; | - | ||||||||||||
| 88 | } | - | ||||||||||||
| 89 | #endif | - | ||||||||||||
| 90 | - | |||||||||||||
| 91 | if ((type == V_ASN1_GENERALSTRING) && ((num % 4) == 0)) {
| 0-13855 | ||||||||||||
| 92 | gs_doit[0] = gs_doit[1] = gs_doit[2] = gs_doit[3] = 0; | - | ||||||||||||
| 93 | for (j = 0; j < num; j++)
| 0 | ||||||||||||
| 94 | if (q[j] != 0)
| 0 | ||||||||||||
| 95 | gs_doit[j & 3] = 1; never executed: gs_doit[j & 3] = 1; | 0 | ||||||||||||
| 96 | - | |||||||||||||
| 97 | if (gs_doit[0] | gs_doit[1] | gs_doit[2])
| 0 | ||||||||||||
| 98 | gs_doit[0] = gs_doit[1] = gs_doit[2] = gs_doit[3] = 1; never executed: gs_doit[0] = gs_doit[1] = gs_doit[2] = gs_doit[3] = 1; | 0 | ||||||||||||
| 99 | else { | - | ||||||||||||
| 100 | gs_doit[0] = gs_doit[1] = gs_doit[2] = 0; | - | ||||||||||||
| 101 | gs_doit[3] = 1; | - | ||||||||||||
| 102 | } never executed: end of block | 0 | ||||||||||||
| 103 | } else | - | ||||||||||||
| 104 | gs_doit[0] = gs_doit[1] = gs_doit[2] = gs_doit[3] = 1; executed 13855 times by 1 test: gs_doit[0] = gs_doit[1] = gs_doit[2] = gs_doit[3] = 1;Executed by:
| 13855 | ||||||||||||
| 105 | - | |||||||||||||
| 106 | for (l2 = j = 0; j < num; j++) {
| 13855-81218 | ||||||||||||
| 107 | if (!gs_doit[j & 3])
| 0-81218 | ||||||||||||
| 108 | continue; never executed: continue; | 0 | ||||||||||||
| 109 | l2++; | - | ||||||||||||
| 110 | #ifndef CHARSET_EBCDIC | - | ||||||||||||
| 111 | if ((q[j] < ' ') || (q[j] > '~'))
| 8900-72318 | ||||||||||||
| 112 | l2 += 3; executed 22185 times by 1 test: l2 += 3;Executed by:
| 22185 | ||||||||||||
| 113 | #else | - | ||||||||||||
| 114 | if ((os_toascii[q[j]] < os_toascii[' ']) || | - | ||||||||||||
| 115 | (os_toascii[q[j]] > os_toascii['~'])) | - | ||||||||||||
| 116 | l2 += 3; | - | ||||||||||||
| 117 | #endif | - | ||||||||||||
| 118 | } executed 81218 times by 1 test: end of blockExecuted by:
| 81218 | ||||||||||||
| 119 | - | |||||||||||||
| 120 | lold = l; | - | ||||||||||||
| 121 | l += 1 + l1 + 1 + l2; | - | ||||||||||||
| 122 | if (l > NAME_ONELINE_MAX) {
| 0-13855 | ||||||||||||
| 123 | X509err(X509_F_X509_NAME_ONELINE, X509_R_NAME_TOO_LONG); | - | ||||||||||||
| 124 | goto end; never executed: goto end; | 0 | ||||||||||||
| 125 | } | - | ||||||||||||
| 126 | if (b != NULL) {
| 478-13377 | ||||||||||||
| 127 | if (!BUF_MEM_grow(b, l + 1))
| 0-13377 | ||||||||||||
| 128 | goto err; never executed: goto err; | 0 | ||||||||||||
| 129 | p = &(b->data[lold]); | - | ||||||||||||
| 130 | } else if (l > len) { executed 13377 times by 1 test: end of blockExecuted by:
| 3-13377 | ||||||||||||
| 131 | break; executed 3 times by 1 test: break;Executed by:
| 3 | ||||||||||||
| 132 | } else | - | ||||||||||||
| 133 | p = &(buf[lold]); executed 475 times by 1 test: p = &(buf[lold]);Executed by:
| 475 | ||||||||||||
| 134 | *(p++) = '/'; | - | ||||||||||||
| 135 | memcpy(p, s, (unsigned int)l1); | - | ||||||||||||
| 136 | p += l1; | - | ||||||||||||
| 137 | *(p++) = '='; | - | ||||||||||||
| 138 | - | |||||||||||||
| 139 | #ifndef CHARSET_EBCDIC /* q was assigned above already. */ | - | ||||||||||||
| 140 | q = ne->value->data; | - | ||||||||||||
| 141 | #endif | - | ||||||||||||
| 142 | - | |||||||||||||
| 143 | for (j = 0; j < num; j++) {
| 13852-81106 | ||||||||||||
| 144 | if (!gs_doit[j & 3])
| 0-81106 | ||||||||||||
| 145 | continue; never executed: continue; | 0 | ||||||||||||
| 146 | #ifndef CHARSET_EBCDIC | - | ||||||||||||
| 147 | n = q[j]; | - | ||||||||||||
| 148 | if ((n < ' ') || (n > '~')) {
| 8855-72251 | ||||||||||||
| 149 | *(p++) = '\\'; | - | ||||||||||||
| 150 | *(p++) = 'x'; | - | ||||||||||||
| 151 | *(p++) = hex[(n >> 4) & 0x0f]; | - | ||||||||||||
| 152 | *(p++) = hex[n & 0x0f]; | - | ||||||||||||
| 153 | } else executed 22129 times by 1 test: end of blockExecuted by:
| 22129 | ||||||||||||
| 154 | *(p++) = n; executed 58977 times by 1 test: *(p++) = n;Executed by:
| 58977 | ||||||||||||
| 155 | #else | - | ||||||||||||
| 156 | n = os_toascii[q[j]]; | - | ||||||||||||
| 157 | if ((n < os_toascii[' ']) || (n > os_toascii['~'])) { | - | ||||||||||||
| 158 | *(p++) = '\\'; | - | ||||||||||||
| 159 | *(p++) = 'x'; | - | ||||||||||||
| 160 | *(p++) = hex[(n >> 4) & 0x0f]; | - | ||||||||||||
| 161 | *(p++) = hex[n & 0x0f]; | - | ||||||||||||
| 162 | } else | - | ||||||||||||
| 163 | *(p++) = q[j]; | - | ||||||||||||
| 164 | #endif | - | ||||||||||||
| 165 | } | - | ||||||||||||
| 166 | *p = '\0'; | - | ||||||||||||
| 167 | } executed 13852 times by 1 test: end of blockExecuted by:
| 13852 | ||||||||||||
| 168 | if (b != NULL) {
| 471-5798 | ||||||||||||
| 169 | p = b->data; | - | ||||||||||||
| 170 | OPENSSL_free(b); | - | ||||||||||||
| 171 | } else executed 5798 times by 1 test: end of blockExecuted by:
| 5798 | ||||||||||||
| 172 | p = buf; executed 471 times by 1 test: p = buf;Executed by:
| 471 | ||||||||||||
| 173 | if (i == 0)
| 2027-4242 | ||||||||||||
| 174 | *p = '\0'; executed 4242 times by 1 test: *p = '\0';Executed by:
| 4242 | ||||||||||||
| 175 | return p; executed 6269 times by 1 test: return p;Executed by:
| 6269 | ||||||||||||
| 176 | err: | - | ||||||||||||
| 177 | X509err(X509_F_X509_NAME_ONELINE, ERR_R_MALLOC_FAILURE); | - | ||||||||||||
| 178 | end: code before this statement never executed: end: | 0 | ||||||||||||
| 179 | BUF_MEM_free(b); | - | ||||||||||||
| 180 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||
| 181 | } | - | ||||||||||||
| Source code | Switch to Preprocessed file |