| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/bio/bio_meth.c |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /* | - | ||||||||||||
| 2 | * Copyright 2016-2018 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 "bio_lcl.h" | - | ||||||||||||
| 11 | #include "internal/thread_once.h" | - | ||||||||||||
| 12 | - | |||||||||||||
| 13 | CRYPTO_RWLOCK *bio_type_lock = NULL; | - | ||||||||||||
| 14 | static CRYPTO_ONCE bio_type_init = CRYPTO_ONCE_STATIC_INIT; | - | ||||||||||||
| 15 | - | |||||||||||||
| 16 | DEFINE_RUN_ONCE_STATIC(do_bio_type_init) never executed: end of block | 0 | ||||||||||||
| 17 | { | - | ||||||||||||
| 18 | bio_type_lock = CRYPTO_THREAD_lock_new(); | - | ||||||||||||
| 19 | return bio_type_lock != NULL; never executed: return bio_type_lock != ((void *)0) ; | 0 | ||||||||||||
| 20 | } | - | ||||||||||||
| 21 | - | |||||||||||||
| 22 | int BIO_get_new_index(void) | - | ||||||||||||
| 23 | { | - | ||||||||||||
| 24 | static CRYPTO_REF_COUNT bio_count = BIO_TYPE_START; | - | ||||||||||||
| 25 | int newval; | - | ||||||||||||
| 26 | - | |||||||||||||
| 27 | if (!RUN_ONCE(&bio_type_init, do_bio_type_init)) {
| 0 | ||||||||||||
| 28 | BIOerr(BIO_F_BIO_GET_NEW_INDEX, ERR_R_MALLOC_FAILURE); | - | ||||||||||||
| 29 | return -1; never executed: return -1; | 0 | ||||||||||||
| 30 | } | - | ||||||||||||
| 31 | if (!CRYPTO_UP_REF(&bio_count, &newval, bio_type_lock))
| 0 | ||||||||||||
| 32 | return -1; never executed: return -1; | 0 | ||||||||||||
| 33 | return newval; never executed: return newval; | 0 | ||||||||||||
| 34 | } | - | ||||||||||||
| 35 | - | |||||||||||||
| 36 | BIO_METHOD *BIO_meth_new(int type, const char *name) | - | ||||||||||||
| 37 | { | - | ||||||||||||
| 38 | BIO_METHOD *biom = OPENSSL_zalloc(sizeof(BIO_METHOD)); | - | ||||||||||||
| 39 | - | |||||||||||||
| 40 | if (biom == NULL
| 0-1502 | ||||||||||||
| 41 | || (biom->name = OPENSSL_strdup(name)) == NULL) {
| 0-1502 | ||||||||||||
| 42 | OPENSSL_free(biom); | - | ||||||||||||
| 43 | BIOerr(BIO_F_BIO_METH_NEW, ERR_R_MALLOC_FAILURE); | - | ||||||||||||
| 44 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||
| 45 | } | - | ||||||||||||
| 46 | biom->type = type; | - | ||||||||||||
| 47 | return biom; executed 1502 times by 12 tests: return biom;Executed by:
| 1502 | ||||||||||||
| 48 | } | - | ||||||||||||
| 49 | - | |||||||||||||
| 50 | void BIO_meth_free(BIO_METHOD *biom) | - | ||||||||||||
| 51 | { | - | ||||||||||||
| 52 | if (biom != NULL) {
| 450-1346 | ||||||||||||
| 53 | OPENSSL_free(biom->name); | - | ||||||||||||
| 54 | OPENSSL_free(biom); | - | ||||||||||||
| 55 | } executed 1346 times by 1 test: end of blockExecuted by:
| 1346 | ||||||||||||
| 56 | } executed 1796 times by 1 test: end of blockExecuted by:
| 1796 | ||||||||||||
| 57 | - | |||||||||||||
| 58 | int (*BIO_meth_get_write(const BIO_METHOD *biom)) (BIO *, const char *, int) | - | ||||||||||||
| 59 | { | - | ||||||||||||
| 60 | return biom->bwrite_old; never executed: return biom->bwrite_old; | 0 | ||||||||||||
| 61 | } | - | ||||||||||||
| 62 | - | |||||||||||||
| 63 | int (*BIO_meth_get_write_ex(const BIO_METHOD *biom)) (BIO *, const char *, size_t, | - | ||||||||||||
| 64 | size_t *) | - | ||||||||||||
| 65 | { | - | ||||||||||||
| 66 | return biom->bwrite; never executed: return biom->bwrite; | 0 | ||||||||||||
| 67 | } | - | ||||||||||||
| 68 | - | |||||||||||||
| 69 | /* Conversion for old style bwrite to new style */ | - | ||||||||||||
| 70 | int bwrite_conv(BIO *bio, const char *data, size_t datal, size_t *written) | - | ||||||||||||
| 71 | { | - | ||||||||||||
| 72 | int ret; | - | ||||||||||||
| 73 | - | |||||||||||||
| 74 | if (datal > INT_MAX)
| 0-13179310 | ||||||||||||
| 75 | datal = INT_MAX; never executed: datal = 0x7fffffff; | 0 | ||||||||||||
| 76 | - | |||||||||||||
| 77 | ret = bio->method->bwrite_old(bio, data, (int)datal); | - | ||||||||||||
| 78 | - | |||||||||||||
| 79 | if (ret <= 0) {
| 1064-13178246 | ||||||||||||
| 80 | *written = 0; | - | ||||||||||||
| 81 | return ret; executed 1064 times by 1 test: return ret;Executed by:
| 1064 | ||||||||||||
| 82 | } | - | ||||||||||||
| 83 | - | |||||||||||||
| 84 | *written = (size_t)ret; | - | ||||||||||||
| 85 | - | |||||||||||||
| 86 | return 1; executed 13178246 times by 12 tests: return 1;Executed by:
| 13178246 | ||||||||||||
| 87 | } | - | ||||||||||||
| 88 | - | |||||||||||||
| 89 | int BIO_meth_set_write(BIO_METHOD *biom, | - | ||||||||||||
| 90 | int (*bwrite) (BIO *, const char *, int)) | - | ||||||||||||
| 91 | { | - | ||||||||||||
| 92 | biom->bwrite_old = bwrite; | - | ||||||||||||
| 93 | biom->bwrite = bwrite_conv; | - | ||||||||||||
| 94 | return 1; executed 7 times by 1 test: return 1;Executed by:
| 7 | ||||||||||||
| 95 | } | - | ||||||||||||
| 96 | - | |||||||||||||
| 97 | int BIO_meth_set_write_ex(BIO_METHOD *biom, | - | ||||||||||||
| 98 | int (*bwrite) (BIO *, const char *, size_t, size_t *)) | - | ||||||||||||
| 99 | { | - | ||||||||||||
| 100 | biom->bwrite_old = NULL; | - | ||||||||||||
| 101 | biom->bwrite = bwrite; | - | ||||||||||||
| 102 | return 1; executed 1495 times by 12 tests: return 1;Executed by:
| 1495 | ||||||||||||
| 103 | } | - | ||||||||||||
| 104 | - | |||||||||||||
| 105 | int (*BIO_meth_get_read(const BIO_METHOD *biom)) (BIO *, char *, int) | - | ||||||||||||
| 106 | { | - | ||||||||||||
| 107 | return biom->bread_old; never executed: return biom->bread_old; | 0 | ||||||||||||
| 108 | } | - | ||||||||||||
| 109 | - | |||||||||||||
| 110 | int (*BIO_meth_get_read_ex(const BIO_METHOD *biom)) (BIO *, char *, size_t, size_t *) | - | ||||||||||||
| 111 | { | - | ||||||||||||
| 112 | return biom->bread; never executed: return biom->bread; | 0 | ||||||||||||
| 113 | } | - | ||||||||||||
| 114 | - | |||||||||||||
| 115 | /* Conversion for old style bread to new style */ | - | ||||||||||||
| 116 | int bread_conv(BIO *bio, char *data, size_t datal, size_t *readbytes) | - | ||||||||||||
| 117 | { | - | ||||||||||||
| 118 | int ret; | - | ||||||||||||
| 119 | - | |||||||||||||
| 120 | if (datal > INT_MAX)
| 0-1082919 | ||||||||||||
| 121 | datal = INT_MAX; never executed: datal = 0x7fffffff; | 0 | ||||||||||||
| 122 | - | |||||||||||||
| 123 | ret = bio->method->bread_old(bio, data, (int)datal); | - | ||||||||||||
| 124 | - | |||||||||||||
| 125 | if (ret <= 0) {
| 104291-978628 | ||||||||||||
| 126 | *readbytes = 0; | - | ||||||||||||
| 127 | return ret; executed 104291 times by 1 test: return ret;Executed by:
| 104291 | ||||||||||||
| 128 | } | - | ||||||||||||
| 129 | - | |||||||||||||
| 130 | *readbytes = (size_t)ret; | - | ||||||||||||
| 131 | - | |||||||||||||
| 132 | return 1; executed 978628 times by 1 test: return 1;Executed by:
| 978628 | ||||||||||||
| 133 | } | - | ||||||||||||
| 134 | - | |||||||||||||
| 135 | int BIO_meth_set_read(BIO_METHOD *biom, | - | ||||||||||||
| 136 | int (*bread) (BIO *, char *, int)) | - | ||||||||||||
| 137 | { | - | ||||||||||||
| 138 | biom->bread_old = bread; | - | ||||||||||||
| 139 | biom->bread = bread_conv; | - | ||||||||||||
| 140 | return 1; executed 7 times by 1 test: return 1;Executed by:
| 7 | ||||||||||||
| 141 | } | - | ||||||||||||
| 142 | - | |||||||||||||
| 143 | int BIO_meth_set_read_ex(BIO_METHOD *biom, | - | ||||||||||||
| 144 | int (*bread) (BIO *, char *, size_t, size_t *)) | - | ||||||||||||
| 145 | { | - | ||||||||||||
| 146 | biom->bread_old = NULL; | - | ||||||||||||
| 147 | biom->bread = bread; | - | ||||||||||||
| 148 | return 1; executed 1495 times by 12 tests: return 1;Executed by:
| 1495 | ||||||||||||
| 149 | } | - | ||||||||||||
| 150 | - | |||||||||||||
| 151 | int (*BIO_meth_get_puts(const BIO_METHOD *biom)) (BIO *, const char *) | - | ||||||||||||
| 152 | { | - | ||||||||||||
| 153 | return biom->bputs; never executed: return biom->bputs; | 0 | ||||||||||||
| 154 | } | - | ||||||||||||
| 155 | - | |||||||||||||
| 156 | int BIO_meth_set_puts(BIO_METHOD *biom, | - | ||||||||||||
| 157 | int (*bputs) (BIO *, const char *)) | - | ||||||||||||
| 158 | { | - | ||||||||||||
| 159 | biom->bputs = bputs; | - | ||||||||||||
| 160 | return 1; executed 1502 times by 12 tests: return 1;Executed by:
| 1502 | ||||||||||||
| 161 | } | - | ||||||||||||
| 162 | - | |||||||||||||
| 163 | int (*BIO_meth_get_gets(const BIO_METHOD *biom)) (BIO *, char *, int) | - | ||||||||||||
| 164 | { | - | ||||||||||||
| 165 | return biom->bgets; never executed: return biom->bgets; | 0 | ||||||||||||
| 166 | } | - | ||||||||||||
| 167 | - | |||||||||||||
| 168 | int BIO_meth_set_gets(BIO_METHOD *biom, | - | ||||||||||||
| 169 | int (*bgets) (BIO *, char *, int)) | - | ||||||||||||
| 170 | { | - | ||||||||||||
| 171 | biom->bgets = bgets; | - | ||||||||||||
| 172 | return 1; executed 1502 times by 12 tests: return 1;Executed by:
| 1502 | ||||||||||||
| 173 | } | - | ||||||||||||
| 174 | - | |||||||||||||
| 175 | long (*BIO_meth_get_ctrl(const BIO_METHOD *biom)) (BIO *, int, long, void *) | - | ||||||||||||
| 176 | { | - | ||||||||||||
| 177 | return biom->ctrl; never executed: return biom->ctrl; | 0 | ||||||||||||
| 178 | } | - | ||||||||||||
| 179 | - | |||||||||||||
| 180 | int BIO_meth_set_ctrl(BIO_METHOD *biom, | - | ||||||||||||
| 181 | long (*ctrl) (BIO *, int, long, void *)) | - | ||||||||||||
| 182 | { | - | ||||||||||||
| 183 | biom->ctrl = ctrl; | - | ||||||||||||
| 184 | return 1; executed 1502 times by 12 tests: return 1;Executed by:
| 1502 | ||||||||||||
| 185 | } | - | ||||||||||||
| 186 | - | |||||||||||||
| 187 | int (*BIO_meth_get_create(const BIO_METHOD *biom)) (BIO *) | - | ||||||||||||
| 188 | { | - | ||||||||||||
| 189 | return biom->create; never executed: return biom->create; | 0 | ||||||||||||
| 190 | } | - | ||||||||||||
| 191 | - | |||||||||||||
| 192 | int BIO_meth_set_create(BIO_METHOD *biom, int (*create) (BIO *)) | - | ||||||||||||
| 193 | { | - | ||||||||||||
| 194 | biom->create = create; | - | ||||||||||||
| 195 | return 1; executed 1502 times by 12 tests: return 1;Executed by:
| 1502 | ||||||||||||
| 196 | } | - | ||||||||||||
| 197 | - | |||||||||||||
| 198 | int (*BIO_meth_get_destroy(const BIO_METHOD *biom)) (BIO *) | - | ||||||||||||
| 199 | { | - | ||||||||||||
| 200 | return biom->destroy; never executed: return biom->destroy; | 0 | ||||||||||||
| 201 | } | - | ||||||||||||
| 202 | - | |||||||||||||
| 203 | int BIO_meth_set_destroy(BIO_METHOD *biom, int (*destroy) (BIO *)) | - | ||||||||||||
| 204 | { | - | ||||||||||||
| 205 | biom->destroy = destroy; | - | ||||||||||||
| 206 | return 1; executed 1502 times by 12 tests: return 1;Executed by:
| 1502 | ||||||||||||
| 207 | } | - | ||||||||||||
| 208 | - | |||||||||||||
| 209 | long (*BIO_meth_get_callback_ctrl(const BIO_METHOD *biom)) (BIO *, int, BIO_info_cb *) | - | ||||||||||||
| 210 | { | - | ||||||||||||
| 211 | return biom->callback_ctrl; never executed: return biom->callback_ctrl; | 0 | ||||||||||||
| 212 | } | - | ||||||||||||
| 213 | - | |||||||||||||
| 214 | int BIO_meth_set_callback_ctrl(BIO_METHOD *biom, | - | ||||||||||||
| 215 | long (*callback_ctrl) (BIO *, int, | - | ||||||||||||
| 216 | BIO_info_cb *)) | - | ||||||||||||
| 217 | { | - | ||||||||||||
| 218 | biom->callback_ctrl = callback_ctrl; | - | ||||||||||||
| 219 | return 1; executed 1495 times by 12 tests: return 1;Executed by:
| 1495 | ||||||||||||
| 220 | } | - | ||||||||||||
| Source code | Switch to Preprocessed file |