| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/bio/bss_bio.c |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /* | - | ||||||||||||||||||
| 2 | * Copyright 1999-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 | /* | - | ||||||||||||||||||
| 11 | * Special method for a BIO where the other endpoint is also a BIO of this | - | ||||||||||||||||||
| 12 | * kind, handled by the same thread (i.e. the "peer" is actually ourselves, | - | ||||||||||||||||||
| 13 | * wearing a different hat). Such "BIO pairs" are mainly for using the SSL | - | ||||||||||||||||||
| 14 | * library with I/O interfaces for which no specific BIO method is available. | - | ||||||||||||||||||
| 15 | * See ssl/ssltest.c for some hints on how this can be used. | - | ||||||||||||||||||
| 16 | */ | - | ||||||||||||||||||
| 17 | - | |||||||||||||||||||
| 18 | #include "e_os.h" | - | ||||||||||||||||||
| 19 | #include <assert.h> | - | ||||||||||||||||||
| 20 | #include <limits.h> | - | ||||||||||||||||||
| 21 | #include <stdlib.h> | - | ||||||||||||||||||
| 22 | #include <string.h> | - | ||||||||||||||||||
| 23 | - | |||||||||||||||||||
| 24 | #include "bio_lcl.h" | - | ||||||||||||||||||
| 25 | #include <openssl/err.h> | - | ||||||||||||||||||
| 26 | #include <openssl/crypto.h> | - | ||||||||||||||||||
| 27 | - | |||||||||||||||||||
| 28 | static int bio_new(BIO *bio); | - | ||||||||||||||||||
| 29 | static int bio_free(BIO *bio); | - | ||||||||||||||||||
| 30 | static int bio_read(BIO *bio, char *buf, int size); | - | ||||||||||||||||||
| 31 | static int bio_write(BIO *bio, const char *buf, int num); | - | ||||||||||||||||||
| 32 | static long bio_ctrl(BIO *bio, int cmd, long num, void *ptr); | - | ||||||||||||||||||
| 33 | static int bio_puts(BIO *bio, const char *str); | - | ||||||||||||||||||
| 34 | - | |||||||||||||||||||
| 35 | static int bio_make_pair(BIO *bio1, BIO *bio2); | - | ||||||||||||||||||
| 36 | static void bio_destroy_pair(BIO *bio); | - | ||||||||||||||||||
| 37 | - | |||||||||||||||||||
| 38 | static const BIO_METHOD methods_biop = { | - | ||||||||||||||||||
| 39 | BIO_TYPE_BIO, | - | ||||||||||||||||||
| 40 | "BIO pair", | - | ||||||||||||||||||
| 41 | /* TODO: Convert to new style write function */ | - | ||||||||||||||||||
| 42 | bwrite_conv, | - | ||||||||||||||||||
| 43 | bio_write, | - | ||||||||||||||||||
| 44 | /* TODO: Convert to new style read function */ | - | ||||||||||||||||||
| 45 | bread_conv, | - | ||||||||||||||||||
| 46 | bio_read, | - | ||||||||||||||||||
| 47 | bio_puts, | - | ||||||||||||||||||
| 48 | NULL /* no bio_gets */ , | - | ||||||||||||||||||
| 49 | bio_ctrl, | - | ||||||||||||||||||
| 50 | bio_new, | - | ||||||||||||||||||
| 51 | bio_free, | - | ||||||||||||||||||
| 52 | NULL /* no bio_callback_ctrl */ | - | ||||||||||||||||||
| 53 | }; | - | ||||||||||||||||||
| 54 | - | |||||||||||||||||||
| 55 | const BIO_METHOD *BIO_s_bio(void) | - | ||||||||||||||||||
| 56 | { | - | ||||||||||||||||||
| 57 | return &methods_biop; executed 176 times by 1 test: return &methods_biop;Executed by:
| 176 | ||||||||||||||||||
| 58 | } | - | ||||||||||||||||||
| 59 | - | |||||||||||||||||||
| 60 | struct bio_bio_st { | - | ||||||||||||||||||
| 61 | BIO *peer; /* NULL if buf == NULL. If peer != NULL, then | - | ||||||||||||||||||
| 62 | * peer->ptr is also a bio_bio_st, and its | - | ||||||||||||||||||
| 63 | * "peer" member points back to us. peer != | - | ||||||||||||||||||
| 64 | * NULL iff init != 0 in the BIO. */ | - | ||||||||||||||||||
| 65 | /* This is for what we write (i.e. reading uses peer's struct): */ | - | ||||||||||||||||||
| 66 | int closed; /* valid iff peer != NULL */ | - | ||||||||||||||||||
| 67 | size_t len; /* valid iff buf != NULL; 0 if peer == NULL */ | - | ||||||||||||||||||
| 68 | size_t offset; /* valid iff buf != NULL; 0 if len == 0 */ | - | ||||||||||||||||||
| 69 | size_t size; | - | ||||||||||||||||||
| 70 | char *buf; /* "size" elements (if != NULL) */ | - | ||||||||||||||||||
| 71 | size_t request; /* valid iff peer != NULL; 0 if len != 0, | - | ||||||||||||||||||
| 72 | * otherwise set by peer to number of bytes | - | ||||||||||||||||||
| 73 | * it (unsuccessfully) tried to read, never | - | ||||||||||||||||||
| 74 | * more than buffer space (size-len) | - | ||||||||||||||||||
| 75 | * warrants. */ | - | ||||||||||||||||||
| 76 | }; | - | ||||||||||||||||||
| 77 | - | |||||||||||||||||||
| 78 | static int bio_new(BIO *bio) | - | ||||||||||||||||||
| 79 | { | - | ||||||||||||||||||
| 80 | struct bio_bio_st *b = OPENSSL_zalloc(sizeof(*b)); | - | ||||||||||||||||||
| 81 | - | |||||||||||||||||||
| 82 | if (b == NULL)
| 0-176 | ||||||||||||||||||
| 83 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 84 | - | |||||||||||||||||||
| 85 | /* enough for one TLS record (just a default) */ | - | ||||||||||||||||||
| 86 | b->size = 17 * 1024; | - | ||||||||||||||||||
| 87 | - | |||||||||||||||||||
| 88 | bio->ptr = b; | - | ||||||||||||||||||
| 89 | return 1; executed 176 times by 1 test: return 1;Executed by:
| 176 | ||||||||||||||||||
| 90 | } | - | ||||||||||||||||||
| 91 | - | |||||||||||||||||||
| 92 | static int bio_free(BIO *bio) | - | ||||||||||||||||||
| 93 | { | - | ||||||||||||||||||
| 94 | struct bio_bio_st *b; | - | ||||||||||||||||||
| 95 | - | |||||||||||||||||||
| 96 | if (bio == NULL)
| 0-176 | ||||||||||||||||||
| 97 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 98 | b = bio->ptr; | - | ||||||||||||||||||
| 99 | - | |||||||||||||||||||
| 100 | assert(b != NULL); | - | ||||||||||||||||||
| 101 | - | |||||||||||||||||||
| 102 | if (b->peer)
| 88 | ||||||||||||||||||
| 103 | bio_destroy_pair(bio); executed 88 times by 1 test: bio_destroy_pair(bio);Executed by:
| 88 | ||||||||||||||||||
| 104 | - | |||||||||||||||||||
| 105 | OPENSSL_free(b->buf); | - | ||||||||||||||||||
| 106 | OPENSSL_free(b); | - | ||||||||||||||||||
| 107 | - | |||||||||||||||||||
| 108 | return 1; executed 176 times by 1 test: return 1;Executed by:
| 176 | ||||||||||||||||||
| 109 | } | - | ||||||||||||||||||
| 110 | - | |||||||||||||||||||
| 111 | static int bio_read(BIO *bio, char *buf, int size_) | - | ||||||||||||||||||
| 112 | { | - | ||||||||||||||||||
| 113 | size_t size = size_; | - | ||||||||||||||||||
| 114 | size_t rest; | - | ||||||||||||||||||
| 115 | struct bio_bio_st *b, *peer_b; | - | ||||||||||||||||||
| 116 | - | |||||||||||||||||||
| 117 | BIO_clear_retry_flags(bio); | - | ||||||||||||||||||
| 118 | - | |||||||||||||||||||
| 119 | if (!bio->init)
| 0-6936 | ||||||||||||||||||
| 120 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 121 | - | |||||||||||||||||||
| 122 | b = bio->ptr; | - | ||||||||||||||||||
| 123 | assert(b != NULL); | - | ||||||||||||||||||
| 124 | assert(b->peer != NULL); | - | ||||||||||||||||||
| 125 | peer_b = b->peer->ptr; | - | ||||||||||||||||||
| 126 | assert(peer_b != NULL); | - | ||||||||||||||||||
| 127 | assert(peer_b->buf != NULL); | - | ||||||||||||||||||
| 128 | - | |||||||||||||||||||
| 129 | peer_b->request = 0; /* will be set in "retry_read" situation */ | - | ||||||||||||||||||
| 130 | - | |||||||||||||||||||
| 131 | if (buf == NULL || size == 0)
| 0-6936 | ||||||||||||||||||
| 132 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 133 | - | |||||||||||||||||||
| 134 | if (peer_b->len == 0) {
| 3201-3735 | ||||||||||||||||||
| 135 | if (peer_b->closed)
| 0-3735 | ||||||||||||||||||
| 136 | return 0; /* writer has closed, and no data is left */ never executed: return 0; | 0 | ||||||||||||||||||
| 137 | else { | - | ||||||||||||||||||
| 138 | BIO_set_retry_read(bio); /* buffer is empty */ | - | ||||||||||||||||||
| 139 | if (size <= peer_b->size)
| 364-3371 | ||||||||||||||||||
| 140 | peer_b->request = size; executed 3371 times by 1 test: peer_b->request = size;Executed by:
| 3371 | ||||||||||||||||||
| 141 | else | - | ||||||||||||||||||
| 142 | /* | - | ||||||||||||||||||
| 143 | * don't ask for more than the peer can deliver in one write | - | ||||||||||||||||||
| 144 | */ | - | ||||||||||||||||||
| 145 | peer_b->request = peer_b->size; executed 364 times by 1 test: peer_b->request = peer_b->size;Executed by:
| 364 | ||||||||||||||||||
| 146 | return -1; executed 3735 times by 1 test: return -1;Executed by:
| 3735 | ||||||||||||||||||
| 147 | } | - | ||||||||||||||||||
| 148 | } | - | ||||||||||||||||||
| 149 | - | |||||||||||||||||||
| 150 | /* we can read */ | - | ||||||||||||||||||
| 151 | if (peer_b->len < size)
| 858-2343 | ||||||||||||||||||
| 152 | size = peer_b->len; executed 858 times by 1 test: size = peer_b->len;Executed by:
| 858 | ||||||||||||||||||
| 153 | - | |||||||||||||||||||
| 154 | /* now read "size" bytes */ | - | ||||||||||||||||||
| 155 | - | |||||||||||||||||||
| 156 | rest = size; | - | ||||||||||||||||||
| 157 | - | |||||||||||||||||||
| 158 | assert(rest > 0); | - | ||||||||||||||||||
| 159 | do { /* one or two iterations */ | - | ||||||||||||||||||
| 160 | size_t chunk; | - | ||||||||||||||||||
| 161 | - | |||||||||||||||||||
| 162 | assert(rest <= peer_b->len); | - | ||||||||||||||||||
| 163 | if (peer_b->offset + rest <= peer_b->size)
| 78-3201 | ||||||||||||||||||
| 164 | chunk = rest; executed 3201 times by 1 test: chunk = rest;Executed by:
| 3201 | ||||||||||||||||||
| 165 | else | - | ||||||||||||||||||
| 166 | /* wrap around ring buffer */ | - | ||||||||||||||||||
| 167 | chunk = peer_b->size - peer_b->offset; executed 78 times by 1 test: chunk = peer_b->size - peer_b->offset;Executed by:
| 78 | ||||||||||||||||||
| 168 | assert(peer_b->offset + chunk <= peer_b->size); | - | ||||||||||||||||||
| 169 | - | |||||||||||||||||||
| 170 | memcpy(buf, peer_b->buf + peer_b->offset, chunk); | - | ||||||||||||||||||
| 171 | - | |||||||||||||||||||
| 172 | peer_b->len -= chunk; | - | ||||||||||||||||||
| 173 | if (peer_b->len) {
| 1583-1696 | ||||||||||||||||||
| 174 | peer_b->offset += chunk; | - | ||||||||||||||||||
| 175 | assert(peer_b->offset <= peer_b->size); | - | ||||||||||||||||||
| 176 | if (peer_b->offset == peer_b->size)
| 78-1618 | ||||||||||||||||||
| 177 | peer_b->offset = 0; executed 78 times by 1 test: peer_b->offset = 0;Executed by:
| 78 | ||||||||||||||||||
| 178 | buf += chunk; | - | ||||||||||||||||||
| 179 | } else { executed 1696 times by 1 test: end of blockExecuted by:
| 1696 | ||||||||||||||||||
| 180 | /* buffer now empty, no need to advance "buf" */ | - | ||||||||||||||||||
| 181 | assert(chunk == rest); | - | ||||||||||||||||||
| 182 | peer_b->offset = 0; | - | ||||||||||||||||||
| 183 | } executed 1583 times by 1 test: end of blockExecuted by:
| 1583 | ||||||||||||||||||
| 184 | rest -= chunk; | - | ||||||||||||||||||
| 185 | } executed 3279 times by 1 test: end of blockExecuted by:
| 3279 | ||||||||||||||||||
| 186 | while (rest);
| 78-3201 | ||||||||||||||||||
| 187 | - | |||||||||||||||||||
| 188 | return size; executed 3201 times by 1 test: return size;Executed by:
| 3201 | ||||||||||||||||||
| 189 | } | - | ||||||||||||||||||
| 190 | - | |||||||||||||||||||
| 191 | /*- | - | ||||||||||||||||||
| 192 | * non-copying interface: provide pointer to available data in buffer | - | ||||||||||||||||||
| 193 | * bio_nread0: return number of available bytes | - | ||||||||||||||||||
| 194 | * bio_nread: also advance index | - | ||||||||||||||||||
| 195 | * (example usage: bio_nread0(), read from buffer, bio_nread() | - | ||||||||||||||||||
| 196 | * or just bio_nread(), read from buffer) | - | ||||||||||||||||||
| 197 | */ | - | ||||||||||||||||||
| 198 | /* | - | ||||||||||||||||||
| 199 | * WARNING: The non-copying interface is largely untested as of yet and may | - | ||||||||||||||||||
| 200 | * contain bugs. | - | ||||||||||||||||||
| 201 | */ | - | ||||||||||||||||||
| 202 | static ossl_ssize_t bio_nread0(BIO *bio, char **buf) | - | ||||||||||||||||||
| 203 | { | - | ||||||||||||||||||
| 204 | struct bio_bio_st *b, *peer_b; | - | ||||||||||||||||||
| 205 | ossl_ssize_t num; | - | ||||||||||||||||||
| 206 | - | |||||||||||||||||||
| 207 | BIO_clear_retry_flags(bio); | - | ||||||||||||||||||
| 208 | - | |||||||||||||||||||
| 209 | if (!bio->init)
| 0-403 | ||||||||||||||||||
| 210 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 211 | - | |||||||||||||||||||
| 212 | b = bio->ptr; | - | ||||||||||||||||||
| 213 | assert(b != NULL); | - | ||||||||||||||||||
| 214 | assert(b->peer != NULL); | - | ||||||||||||||||||
| 215 | peer_b = b->peer->ptr; | - | ||||||||||||||||||
| 216 | assert(peer_b != NULL); | - | ||||||||||||||||||
| 217 | assert(peer_b->buf != NULL); | - | ||||||||||||||||||
| 218 | - | |||||||||||||||||||
| 219 | peer_b->request = 0; | - | ||||||||||||||||||
| 220 | - | |||||||||||||||||||
| 221 | if (peer_b->len == 0) {
| 0-403 | ||||||||||||||||||
| 222 | char dummy; | - | ||||||||||||||||||
| 223 | - | |||||||||||||||||||
| 224 | /* avoid code duplication -- nothing available for reading */ | - | ||||||||||||||||||
| 225 | return bio_read(bio, &dummy, 1); /* returns 0 or -1 */ never executed: return bio_read(bio, &dummy, 1); | 0 | ||||||||||||||||||
| 226 | } | - | ||||||||||||||||||
| 227 | - | |||||||||||||||||||
| 228 | num = peer_b->len; | - | ||||||||||||||||||
| 229 | if (peer_b->size < peer_b->offset + num)
| 0-403 | ||||||||||||||||||
| 230 | /* no ring buffer wrap-around for non-copying interface */ | - | ||||||||||||||||||
| 231 | num = peer_b->size - peer_b->offset; never executed: num = peer_b->size - peer_b->offset; | 0 | ||||||||||||||||||
| 232 | assert(num > 0); | - | ||||||||||||||||||
| 233 | - | |||||||||||||||||||
| 234 | if (buf != NULL)
| 0-403 | ||||||||||||||||||
| 235 | *buf = peer_b->buf + peer_b->offset; executed 403 times by 1 test: *buf = peer_b->buf + peer_b->offset;Executed by:
| 403 | ||||||||||||||||||
| 236 | return num; executed 403 times by 1 test: return num;Executed by:
| 403 | ||||||||||||||||||
| 237 | } | - | ||||||||||||||||||
| 238 | - | |||||||||||||||||||
| 239 | static ossl_ssize_t bio_nread(BIO *bio, char **buf, size_t num_) | - | ||||||||||||||||||
| 240 | { | - | ||||||||||||||||||
| 241 | struct bio_bio_st *b, *peer_b; | - | ||||||||||||||||||
| 242 | ossl_ssize_t num, available; | - | ||||||||||||||||||
| 243 | - | |||||||||||||||||||
| 244 | if (num_ > OSSL_SSIZE_MAX)
| 0-403 | ||||||||||||||||||
| 245 | num = OSSL_SSIZE_MAX; never executed: num = 0x7fffffffffffffffL; | 0 | ||||||||||||||||||
| 246 | else | - | ||||||||||||||||||
| 247 | num = (ossl_ssize_t) num_; executed 403 times by 1 test: num = (ssize_t) num_;Executed by:
| 403 | ||||||||||||||||||
| 248 | - | |||||||||||||||||||
| 249 | available = bio_nread0(bio, buf); | - | ||||||||||||||||||
| 250 | if (num > available)
| 0-403 | ||||||||||||||||||
| 251 | num = available; never executed: num = available; | 0 | ||||||||||||||||||
| 252 | if (num <= 0)
| 0-403 | ||||||||||||||||||
| 253 | return num; never executed: return num; | 0 | ||||||||||||||||||
| 254 | - | |||||||||||||||||||
| 255 | b = bio->ptr; | - | ||||||||||||||||||
| 256 | peer_b = b->peer->ptr; | - | ||||||||||||||||||
| 257 | - | |||||||||||||||||||
| 258 | peer_b->len -= num; | - | ||||||||||||||||||
| 259 | if (peer_b->len) {
| 0-403 | ||||||||||||||||||
| 260 | peer_b->offset += num; | - | ||||||||||||||||||
| 261 | assert(peer_b->offset <= peer_b->size); | - | ||||||||||||||||||
| 262 | if (peer_b->offset == peer_b->size)
| 0 | ||||||||||||||||||
| 263 | peer_b->offset = 0; never executed: peer_b->offset = 0; | 0 | ||||||||||||||||||
| 264 | } else never executed: end of block | 0 | ||||||||||||||||||
| 265 | peer_b->offset = 0; executed 403 times by 1 test: peer_b->offset = 0;Executed by:
| 403 | ||||||||||||||||||
| 266 | - | |||||||||||||||||||
| 267 | return num; executed 403 times by 1 test: return num;Executed by:
| 403 | ||||||||||||||||||
| 268 | } | - | ||||||||||||||||||
| 269 | - | |||||||||||||||||||
| 270 | static int bio_write(BIO *bio, const char *buf, int num_) | - | ||||||||||||||||||
| 271 | { | - | ||||||||||||||||||
| 272 | size_t num = num_; | - | ||||||||||||||||||
| 273 | size_t rest; | - | ||||||||||||||||||
| 274 | struct bio_bio_st *b; | - | ||||||||||||||||||
| 275 | - | |||||||||||||||||||
| 276 | BIO_clear_retry_flags(bio); | - | ||||||||||||||||||
| 277 | - | |||||||||||||||||||
| 278 | if (!bio->init || buf == NULL || num == 0)
| 0-2434 | ||||||||||||||||||
| 279 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 280 | - | |||||||||||||||||||
| 281 | b = bio->ptr; | - | ||||||||||||||||||
| 282 | assert(b != NULL); | - | ||||||||||||||||||
| 283 | assert(b->peer != NULL); | - | ||||||||||||||||||
| 284 | assert(b->buf != NULL); | - | ||||||||||||||||||
| 285 | - | |||||||||||||||||||
| 286 | b->request = 0; | - | ||||||||||||||||||
| 287 | if (b->closed) {
| 0-2434 | ||||||||||||||||||
| 288 | /* we already closed */ | - | ||||||||||||||||||
| 289 | BIOerr(BIO_F_BIO_WRITE, BIO_R_BROKEN_PIPE); | - | ||||||||||||||||||
| 290 | return -1; never executed: return -1; | 0 | ||||||||||||||||||
| 291 | } | - | ||||||||||||||||||
| 292 | - | |||||||||||||||||||
| 293 | assert(b->len <= b->size); | - | ||||||||||||||||||
| 294 | - | |||||||||||||||||||
| 295 | if (b->len == b->size) {
| 1047-1387 | ||||||||||||||||||
| 296 | BIO_set_retry_write(bio); /* buffer is full */ | - | ||||||||||||||||||
| 297 | return -1; executed 1047 times by 1 test: return -1;Executed by:
| 1047 | ||||||||||||||||||
| 298 | } | - | ||||||||||||||||||
| 299 | - | |||||||||||||||||||
| 300 | /* we can write */ | - | ||||||||||||||||||
| 301 | if (num > b->size - b->len)
| 674-713 | ||||||||||||||||||
| 302 | num = b->size - b->len; executed 713 times by 1 test: num = b->size - b->len;Executed by:
| 713 | ||||||||||||||||||
| 303 | - | |||||||||||||||||||
| 304 | /* now write "num" bytes */ | - | ||||||||||||||||||
| 305 | - | |||||||||||||||||||
| 306 | rest = num; | - | ||||||||||||||||||
| 307 | - | |||||||||||||||||||
| 308 | assert(rest > 0); | - | ||||||||||||||||||
| 309 | do { /* one or two iterations */ | - | ||||||||||||||||||
| 310 | size_t write_offset; | - | ||||||||||||||||||
| 311 | size_t chunk; | - | ||||||||||||||||||
| 312 | - | |||||||||||||||||||
| 313 | assert(b->len + rest <= b->size); | - | ||||||||||||||||||
| 314 | - | |||||||||||||||||||
| 315 | write_offset = b->offset + b->len; | - | ||||||||||||||||||
| 316 | if (write_offset >= b->size)
| 350-1064 | ||||||||||||||||||
| 317 | write_offset -= b->size; executed 350 times by 1 test: write_offset -= b->size;Executed by:
| 350 | ||||||||||||||||||
| 318 | /* b->buf[write_offset] is the first byte we can write to. */ | - | ||||||||||||||||||
| 319 | - | |||||||||||||||||||
| 320 | if (write_offset + rest <= b->size)
| 27-1387 | ||||||||||||||||||
| 321 | chunk = rest; executed 1387 times by 1 test: chunk = rest;Executed by:
| 1387 | ||||||||||||||||||
| 322 | else | - | ||||||||||||||||||
| 323 | /* wrap around ring buffer */ | - | ||||||||||||||||||
| 324 | chunk = b->size - write_offset; executed 27 times by 1 test: chunk = b->size - write_offset;Executed by:
| 27 | ||||||||||||||||||
| 325 | - | |||||||||||||||||||
| 326 | memcpy(b->buf + write_offset, buf, chunk); | - | ||||||||||||||||||
| 327 | - | |||||||||||||||||||
| 328 | b->len += chunk; | - | ||||||||||||||||||
| 329 | - | |||||||||||||||||||
| 330 | assert(b->len <= b->size); | - | ||||||||||||||||||
| 331 | - | |||||||||||||||||||
| 332 | rest -= chunk; | - | ||||||||||||||||||
| 333 | buf += chunk; | - | ||||||||||||||||||
| 334 | } executed 1414 times by 1 test: end of blockExecuted by:
| 1414 | ||||||||||||||||||
| 335 | while (rest);
| 27-1387 | ||||||||||||||||||
| 336 | - | |||||||||||||||||||
| 337 | return num; executed 1387 times by 1 test: return num;Executed by:
| 1387 | ||||||||||||||||||
| 338 | } | - | ||||||||||||||||||
| 339 | - | |||||||||||||||||||
| 340 | /*- | - | ||||||||||||||||||
| 341 | * non-copying interface: provide pointer to region to write to | - | ||||||||||||||||||
| 342 | * bio_nwrite0: check how much space is available | - | ||||||||||||||||||
| 343 | * bio_nwrite: also increase length | - | ||||||||||||||||||
| 344 | * (example usage: bio_nwrite0(), write to buffer, bio_nwrite() | - | ||||||||||||||||||
| 345 | * or just bio_nwrite(), write to buffer) | - | ||||||||||||||||||
| 346 | */ | - | ||||||||||||||||||
| 347 | static ossl_ssize_t bio_nwrite0(BIO *bio, char **buf) | - | ||||||||||||||||||
| 348 | { | - | ||||||||||||||||||
| 349 | struct bio_bio_st *b; | - | ||||||||||||||||||
| 350 | size_t num; | - | ||||||||||||||||||
| 351 | size_t write_offset; | - | ||||||||||||||||||
| 352 | - | |||||||||||||||||||
| 353 | BIO_clear_retry_flags(bio); | - | ||||||||||||||||||
| 354 | - | |||||||||||||||||||
| 355 | if (!bio->init)
| 0-2110 | ||||||||||||||||||
| 356 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 357 | - | |||||||||||||||||||
| 358 | b = bio->ptr; | - | ||||||||||||||||||
| 359 | assert(b != NULL); | - | ||||||||||||||||||
| 360 | assert(b->peer != NULL); | - | ||||||||||||||||||
| 361 | assert(b->buf != NULL); | - | ||||||||||||||||||
| 362 | - | |||||||||||||||||||
| 363 | b->request = 0; | - | ||||||||||||||||||
| 364 | if (b->closed) {
| 0-2110 | ||||||||||||||||||
| 365 | BIOerr(BIO_F_BIO_NWRITE0, BIO_R_BROKEN_PIPE); | - | ||||||||||||||||||
| 366 | return -1; never executed: return -1; | 0 | ||||||||||||||||||
| 367 | } | - | ||||||||||||||||||
| 368 | - | |||||||||||||||||||
| 369 | assert(b->len <= b->size); | - | ||||||||||||||||||
| 370 | - | |||||||||||||||||||
| 371 | if (b->len == b->size) {
| 0-2110 | ||||||||||||||||||
| 372 | BIO_set_retry_write(bio); | - | ||||||||||||||||||
| 373 | return -1; never executed: return -1; | 0 | ||||||||||||||||||
| 374 | } | - | ||||||||||||||||||
| 375 | - | |||||||||||||||||||
| 376 | num = b->size - b->len; | - | ||||||||||||||||||
| 377 | write_offset = b->offset + b->len; | - | ||||||||||||||||||
| 378 | if (write_offset >= b->size)
| 0-2110 | ||||||||||||||||||
| 379 | write_offset -= b->size; never executed: write_offset -= b->size; | 0 | ||||||||||||||||||
| 380 | if (write_offset + num > b->size)
| 0-2110 | ||||||||||||||||||
| 381 | /* | - | ||||||||||||||||||
| 382 | * no ring buffer wrap-around for non-copying interface (to fulfil | - | ||||||||||||||||||
| 383 | * the promise by BIO_ctrl_get_write_guarantee, BIO_nwrite may have | - | ||||||||||||||||||
| 384 | * to be called twice) | - | ||||||||||||||||||
| 385 | */ | - | ||||||||||||||||||
| 386 | num = b->size - write_offset; never executed: num = b->size - write_offset; | 0 | ||||||||||||||||||
| 387 | - | |||||||||||||||||||
| 388 | if (buf != NULL)
| 0-2110 | ||||||||||||||||||
| 389 | *buf = b->buf + write_offset; executed 2110 times by 1 test: *buf = b->buf + write_offset;Executed by:
| 2110 | ||||||||||||||||||
| 390 | assert(write_offset + num <= b->size); | - | ||||||||||||||||||
| 391 | - | |||||||||||||||||||
| 392 | return num; executed 2110 times by 1 test: return num;Executed by:
| 2110 | ||||||||||||||||||
| 393 | } | - | ||||||||||||||||||
| 394 | - | |||||||||||||||||||
| 395 | static ossl_ssize_t bio_nwrite(BIO *bio, char **buf, size_t num_) | - | ||||||||||||||||||
| 396 | { | - | ||||||||||||||||||
| 397 | struct bio_bio_st *b; | - | ||||||||||||||||||
| 398 | ossl_ssize_t num, space; | - | ||||||||||||||||||
| 399 | - | |||||||||||||||||||
| 400 | if (num_ > OSSL_SSIZE_MAX)
| 0-1055 | ||||||||||||||||||
| 401 | num = OSSL_SSIZE_MAX; never executed: num = 0x7fffffffffffffffL; | 0 | ||||||||||||||||||
| 402 | else | - | ||||||||||||||||||
| 403 | num = (ossl_ssize_t) num_; executed 1055 times by 1 test: num = (ssize_t) num_;Executed by:
| 1055 | ||||||||||||||||||
| 404 | - | |||||||||||||||||||
| 405 | space = bio_nwrite0(bio, buf); | - | ||||||||||||||||||
| 406 | if (num > space)
| 0-1055 | ||||||||||||||||||
| 407 | num = space; never executed: num = space; | 0 | ||||||||||||||||||
| 408 | if (num <= 0)
| 0-1055 | ||||||||||||||||||
| 409 | return num; never executed: return num; | 0 | ||||||||||||||||||
| 410 | b = bio->ptr; | - | ||||||||||||||||||
| 411 | assert(b != NULL); | - | ||||||||||||||||||
| 412 | b->len += num; | - | ||||||||||||||||||
| 413 | assert(b->len <= b->size); | - | ||||||||||||||||||
| 414 | - | |||||||||||||||||||
| 415 | return num; executed 1055 times by 1 test: return num;Executed by:
| 1055 | ||||||||||||||||||
| 416 | } | - | ||||||||||||||||||
| 417 | - | |||||||||||||||||||
| 418 | static long bio_ctrl(BIO *bio, int cmd, long num, void *ptr) | - | ||||||||||||||||||
| 419 | { | - | ||||||||||||||||||
| 420 | long ret; | - | ||||||||||||||||||
| 421 | struct bio_bio_st *b = bio->ptr; | - | ||||||||||||||||||
| 422 | - | |||||||||||||||||||
| 423 | assert(b != NULL); | - | ||||||||||||||||||
| 424 | - | |||||||||||||||||||
| 425 | switch (cmd) { | - | ||||||||||||||||||
| 426 | /* specific CTRL codes */ | - | ||||||||||||||||||
| 427 | - | |||||||||||||||||||
| 428 | case BIO_C_SET_WRITE_BUF_SIZE: executed 176 times by 1 test: case 136:Executed by:
| 176 | ||||||||||||||||||
| 429 | if (b->peer) {
| 0-176 | ||||||||||||||||||
| 430 | BIOerr(BIO_F_BIO_CTRL, BIO_R_IN_USE); | - | ||||||||||||||||||
| 431 | ret = 0; | - | ||||||||||||||||||
| 432 | } else if (num == 0) { never executed: end of block
| 0-176 | ||||||||||||||||||
| 433 | BIOerr(BIO_F_BIO_CTRL, BIO_R_INVALID_ARGUMENT); | - | ||||||||||||||||||
| 434 | ret = 0; | - | ||||||||||||||||||
| 435 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 436 | size_t new_size = num; | - | ||||||||||||||||||
| 437 | - | |||||||||||||||||||
| 438 | if (b->size != new_size) {
| 0-176 | ||||||||||||||||||
| 439 | OPENSSL_free(b->buf); | - | ||||||||||||||||||
| 440 | b->buf = NULL; | - | ||||||||||||||||||
| 441 | b->size = new_size; | - | ||||||||||||||||||
| 442 | } executed 176 times by 1 test: end of blockExecuted by:
| 176 | ||||||||||||||||||
| 443 | ret = 1; | - | ||||||||||||||||||
| 444 | } executed 176 times by 1 test: end of blockExecuted by:
| 176 | ||||||||||||||||||
| 445 | break; executed 176 times by 1 test: break;Executed by:
| 176 | ||||||||||||||||||
| 446 | - | |||||||||||||||||||
| 447 | case BIO_C_GET_WRITE_BUF_SIZE: never executed: case 137: | 0 | ||||||||||||||||||
| 448 | ret = (long)b->size; | - | ||||||||||||||||||
| 449 | break; never executed: break; | 0 | ||||||||||||||||||
| 450 | - | |||||||||||||||||||
| 451 | case BIO_C_MAKE_BIO_PAIR: executed 88 times by 1 test: case 138:Executed by:
| 88 | ||||||||||||||||||
| 452 | { | - | ||||||||||||||||||
| 453 | BIO *other_bio = ptr; | - | ||||||||||||||||||
| 454 | - | |||||||||||||||||||
| 455 | if (bio_make_pair(bio, other_bio))
| 0-88 | ||||||||||||||||||
| 456 | ret = 1; executed 88 times by 1 test: ret = 1;Executed by:
| 88 | ||||||||||||||||||
| 457 | else | - | ||||||||||||||||||
| 458 | ret = 0; never executed: ret = 0; | 0 | ||||||||||||||||||
| 459 | } | - | ||||||||||||||||||
| 460 | break; executed 88 times by 1 test: break;Executed by:
| 88 | ||||||||||||||||||
| 461 | - | |||||||||||||||||||
| 462 | case BIO_C_DESTROY_BIO_PAIR: never executed: case 139: | 0 | ||||||||||||||||||
| 463 | /* | - | ||||||||||||||||||
| 464 | * Affects both BIOs in the pair -- call just once! Or let | - | ||||||||||||||||||
| 465 | * BIO_free(bio1); BIO_free(bio2); do the job. | - | ||||||||||||||||||
| 466 | */ | - | ||||||||||||||||||
| 467 | bio_destroy_pair(bio); | - | ||||||||||||||||||
| 468 | ret = 1; | - | ||||||||||||||||||
| 469 | break; never executed: break; | 0 | ||||||||||||||||||
| 470 | - | |||||||||||||||||||
| 471 | case BIO_C_GET_WRITE_GUARANTEE: executed 1814 times by 1 test: case 140:Executed by:
| 1814 | ||||||||||||||||||
| 472 | /* | - | ||||||||||||||||||
| 473 | * How many bytes can the caller feed to the next write without | - | ||||||||||||||||||
| 474 | * having to keep any? | - | ||||||||||||||||||
| 475 | */ | - | ||||||||||||||||||
| 476 | if (b->peer == NULL || b->closed)
| 0-1814 | ||||||||||||||||||
| 477 | ret = 0; never executed: ret = 0; | 0 | ||||||||||||||||||
| 478 | else | - | ||||||||||||||||||
| 479 | ret = (long)b->size - b->len; executed 1814 times by 1 test: ret = (long)b->size - b->len;Executed by:
| 1814 | ||||||||||||||||||
| 480 | break; executed 1814 times by 1 test: break;Executed by:
| 1814 | ||||||||||||||||||
| 481 | - | |||||||||||||||||||
| 482 | case BIO_C_GET_READ_REQUEST: executed 1411 times by 1 test: case 141:Executed by:
| 1411 | ||||||||||||||||||
| 483 | /* | - | ||||||||||||||||||
| 484 | * If the peer unsuccessfully tried to read, how many bytes were | - | ||||||||||||||||||
| 485 | * requested? (As with BIO_CTRL_PENDING, that number can usually be | - | ||||||||||||||||||
| 486 | * treated as boolean.) | - | ||||||||||||||||||
| 487 | */ | - | ||||||||||||||||||
| 488 | ret = (long)b->request; | - | ||||||||||||||||||
| 489 | break; executed 1411 times by 1 test: break;Executed by:
| 1411 | ||||||||||||||||||
| 490 | - | |||||||||||||||||||
| 491 | case BIO_C_RESET_READ_REQUEST: never executed: case 147: | 0 | ||||||||||||||||||
| 492 | /* | - | ||||||||||||||||||
| 493 | * Reset request. (Can be useful after read attempts at the other | - | ||||||||||||||||||
| 494 | * side that are meant to be non-blocking, e.g. when probing SSL_read | - | ||||||||||||||||||
| 495 | * to see if any data is available.) | - | ||||||||||||||||||
| 496 | */ | - | ||||||||||||||||||
| 497 | b->request = 0; | - | ||||||||||||||||||
| 498 | ret = 1; | - | ||||||||||||||||||
| 499 | break; never executed: break; | 0 | ||||||||||||||||||
| 500 | - | |||||||||||||||||||
| 501 | case BIO_C_SHUTDOWN_WR: never executed: case 142: | 0 | ||||||||||||||||||
| 502 | /* similar to shutdown(..., SHUT_WR) */ | - | ||||||||||||||||||
| 503 | b->closed = 1; | - | ||||||||||||||||||
| 504 | ret = 1; | - | ||||||||||||||||||
| 505 | break; never executed: break; | 0 | ||||||||||||||||||
| 506 | - | |||||||||||||||||||
| 507 | case BIO_C_NREAD0: never executed: case 143: | 0 | ||||||||||||||||||
| 508 | /* prepare for non-copying read */ | - | ||||||||||||||||||
| 509 | ret = (long)bio_nread0(bio, ptr); | - | ||||||||||||||||||
| 510 | break; never executed: break; | 0 | ||||||||||||||||||
| 511 | - | |||||||||||||||||||
| 512 | case BIO_C_NREAD: executed 403 times by 1 test: case 144:Executed by:
| 403 | ||||||||||||||||||
| 513 | /* non-copying read */ | - | ||||||||||||||||||
| 514 | ret = (long)bio_nread(bio, ptr, (size_t)num); | - | ||||||||||||||||||
| 515 | break; executed 403 times by 1 test: break;Executed by:
| 403 | ||||||||||||||||||
| 516 | - | |||||||||||||||||||
| 517 | case BIO_C_NWRITE0: executed 1055 times by 1 test: case 145:Executed by:
| 1055 | ||||||||||||||||||
| 518 | /* prepare for non-copying write */ | - | ||||||||||||||||||
| 519 | ret = (long)bio_nwrite0(bio, ptr); | - | ||||||||||||||||||
| 520 | break; executed 1055 times by 1 test: break;Executed by:
| 1055 | ||||||||||||||||||
| 521 | - | |||||||||||||||||||
| 522 | case BIO_C_NWRITE: executed 1055 times by 1 test: case 146:Executed by:
| 1055 | ||||||||||||||||||
| 523 | /* non-copying write */ | - | ||||||||||||||||||
| 524 | ret = (long)bio_nwrite(bio, ptr, (size_t)num); | - | ||||||||||||||||||
| 525 | break; executed 1055 times by 1 test: break;Executed by:
| 1055 | ||||||||||||||||||
| 526 | - | |||||||||||||||||||
| 527 | /* standard CTRL codes follow */ | - | ||||||||||||||||||
| 528 | - | |||||||||||||||||||
| 529 | case BIO_CTRL_RESET: never executed: case 1: | 0 | ||||||||||||||||||
| 530 | if (b->buf != NULL) {
| 0 | ||||||||||||||||||
| 531 | b->len = 0; | - | ||||||||||||||||||
| 532 | b->offset = 0; | - | ||||||||||||||||||
| 533 | } never executed: end of block | 0 | ||||||||||||||||||
| 534 | ret = 0; | - | ||||||||||||||||||
| 535 | break; never executed: break; | 0 | ||||||||||||||||||
| 536 | - | |||||||||||||||||||
| 537 | case BIO_CTRL_GET_CLOSE: never executed: case 8: | 0 | ||||||||||||||||||
| 538 | ret = bio->shutdown; | - | ||||||||||||||||||
| 539 | break; never executed: break; | 0 | ||||||||||||||||||
| 540 | - | |||||||||||||||||||
| 541 | case BIO_CTRL_SET_CLOSE: never executed: case 9: | 0 | ||||||||||||||||||
| 542 | bio->shutdown = (int)num; | - | ||||||||||||||||||
| 543 | ret = 1; | - | ||||||||||||||||||
| 544 | break; never executed: break; | 0 | ||||||||||||||||||
| 545 | - | |||||||||||||||||||
| 546 | case BIO_CTRL_PENDING: executed 3225 times by 1 test: case 10:Executed by:
| 3225 | ||||||||||||||||||
| 547 | if (b->peer != NULL) {
| 0-3225 | ||||||||||||||||||
| 548 | struct bio_bio_st *peer_b = b->peer->ptr; | - | ||||||||||||||||||
| 549 | - | |||||||||||||||||||
| 550 | ret = (long)peer_b->len; | - | ||||||||||||||||||
| 551 | } else executed 3225 times by 1 test: end of blockExecuted by:
| 3225 | ||||||||||||||||||
| 552 | ret = 0; never executed: ret = 0; | 0 | ||||||||||||||||||
| 553 | break; executed 3225 times by 1 test: break;Executed by:
| 3225 | ||||||||||||||||||
| 554 | - | |||||||||||||||||||
| 555 | case BIO_CTRL_WPENDING: never executed: case 13: | 0 | ||||||||||||||||||
| 556 | if (b->buf != NULL)
| 0 | ||||||||||||||||||
| 557 | ret = (long)b->len; never executed: ret = (long)b->len; | 0 | ||||||||||||||||||
| 558 | else | - | ||||||||||||||||||
| 559 | ret = 0; never executed: ret = 0; | 0 | ||||||||||||||||||
| 560 | break; never executed: break; | 0 | ||||||||||||||||||
| 561 | - | |||||||||||||||||||
| 562 | case BIO_CTRL_DUP: never executed: case 12: | 0 | ||||||||||||||||||
| 563 | /* See BIO_dup_chain for circumstances we have to expect. */ | - | ||||||||||||||||||
| 564 | { | - | ||||||||||||||||||
| 565 | BIO *other_bio = ptr; | - | ||||||||||||||||||
| 566 | struct bio_bio_st *other_b; | - | ||||||||||||||||||
| 567 | - | |||||||||||||||||||
| 568 | assert(other_bio != NULL); | - | ||||||||||||||||||
| 569 | other_b = other_bio->ptr; | - | ||||||||||||||||||
| 570 | assert(other_b != NULL); | - | ||||||||||||||||||
| 571 | - | |||||||||||||||||||
| 572 | assert(other_b->buf == NULL); /* other_bio is always fresh */ | - | ||||||||||||||||||
| 573 | - | |||||||||||||||||||
| 574 | other_b->size = b->size; | - | ||||||||||||||||||
| 575 | } | - | ||||||||||||||||||
| 576 | - | |||||||||||||||||||
| 577 | ret = 1; | - | ||||||||||||||||||
| 578 | break; never executed: break; | 0 | ||||||||||||||||||
| 579 | - | |||||||||||||||||||
| 580 | case BIO_CTRL_FLUSH: executed 183 times by 1 test: case 11:Executed by:
| 183 | ||||||||||||||||||
| 581 | ret = 1; | - | ||||||||||||||||||
| 582 | break; executed 183 times by 1 test: break;Executed by:
| 183 | ||||||||||||||||||
| 583 | - | |||||||||||||||||||
| 584 | case BIO_CTRL_EOF: never executed: case 2: | 0 | ||||||||||||||||||
| 585 | if (b->peer != NULL) {
| 0 | ||||||||||||||||||
| 586 | struct bio_bio_st *peer_b = b->peer->ptr; | - | ||||||||||||||||||
| 587 | - | |||||||||||||||||||
| 588 | if (peer_b->len == 0 && peer_b->closed)
| 0 | ||||||||||||||||||
| 589 | ret = 1; never executed: ret = 1; | 0 | ||||||||||||||||||
| 590 | else | - | ||||||||||||||||||
| 591 | ret = 0; never executed: ret = 0; | 0 | ||||||||||||||||||
| 592 | } else { | - | ||||||||||||||||||
| 593 | ret = 1; | - | ||||||||||||||||||
| 594 | } never executed: end of block | 0 | ||||||||||||||||||
| 595 | break; never executed: break; | 0 | ||||||||||||||||||
| 596 | - | |||||||||||||||||||
| 597 | default: executed 204 times by 1 test: default:Executed by:
| 204 | ||||||||||||||||||
| 598 | ret = 0; | - | ||||||||||||||||||
| 599 | } executed 204 times by 1 test: end of blockExecuted by:
| 204 | ||||||||||||||||||
| 600 | return ret; executed 9614 times by 1 test: return ret;Executed by:
| 9614 | ||||||||||||||||||
| 601 | } | - | ||||||||||||||||||
| 602 | - | |||||||||||||||||||
| 603 | static int bio_puts(BIO *bio, const char *str) | - | ||||||||||||||||||
| 604 | { | - | ||||||||||||||||||
| 605 | return bio_write(bio, str, strlen(str)); never executed: return bio_write(bio, str, strlen(str)); | 0 | ||||||||||||||||||
| 606 | } | - | ||||||||||||||||||
| 607 | - | |||||||||||||||||||
| 608 | static int bio_make_pair(BIO *bio1, BIO *bio2) | - | ||||||||||||||||||
| 609 | { | - | ||||||||||||||||||
| 610 | struct bio_bio_st *b1, *b2; | - | ||||||||||||||||||
| 611 | - | |||||||||||||||||||
| 612 | assert(bio1 != NULL); | - | ||||||||||||||||||
| 613 | assert(bio2 != NULL); | - | ||||||||||||||||||
| 614 | - | |||||||||||||||||||
| 615 | b1 = bio1->ptr; | - | ||||||||||||||||||
| 616 | b2 = bio2->ptr; | - | ||||||||||||||||||
| 617 | - | |||||||||||||||||||
| 618 | if (b1->peer != NULL || b2->peer != NULL) {
| 0-88 | ||||||||||||||||||
| 619 | BIOerr(BIO_F_BIO_MAKE_PAIR, BIO_R_IN_USE); | - | ||||||||||||||||||
| 620 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 621 | } | - | ||||||||||||||||||
| 622 | - | |||||||||||||||||||
| 623 | if (b1->buf == NULL) {
| 0-88 | ||||||||||||||||||
| 624 | b1->buf = OPENSSL_malloc(b1->size); | - | ||||||||||||||||||
| 625 | if (b1->buf == NULL) {
| 0-88 | ||||||||||||||||||
| 626 | BIOerr(BIO_F_BIO_MAKE_PAIR, ERR_R_MALLOC_FAILURE); | - | ||||||||||||||||||
| 627 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 628 | } | - | ||||||||||||||||||
| 629 | b1->len = 0; | - | ||||||||||||||||||
| 630 | b1->offset = 0; | - | ||||||||||||||||||
| 631 | } executed 88 times by 1 test: end of blockExecuted by:
| 88 | ||||||||||||||||||
| 632 | - | |||||||||||||||||||
| 633 | if (b2->buf == NULL) {
| 0-88 | ||||||||||||||||||
| 634 | b2->buf = OPENSSL_malloc(b2->size); | - | ||||||||||||||||||
| 635 | if (b2->buf == NULL) {
| 0-88 | ||||||||||||||||||
| 636 | BIOerr(BIO_F_BIO_MAKE_PAIR, ERR_R_MALLOC_FAILURE); | - | ||||||||||||||||||
| 637 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 638 | } | - | ||||||||||||||||||
| 639 | b2->len = 0; | - | ||||||||||||||||||
| 640 | b2->offset = 0; | - | ||||||||||||||||||
| 641 | } executed 88 times by 1 test: end of blockExecuted by:
| 88 | ||||||||||||||||||
| 642 | - | |||||||||||||||||||
| 643 | b1->peer = bio2; | - | ||||||||||||||||||
| 644 | b1->closed = 0; | - | ||||||||||||||||||
| 645 | b1->request = 0; | - | ||||||||||||||||||
| 646 | b2->peer = bio1; | - | ||||||||||||||||||
| 647 | b2->closed = 0; | - | ||||||||||||||||||
| 648 | b2->request = 0; | - | ||||||||||||||||||
| 649 | - | |||||||||||||||||||
| 650 | bio1->init = 1; | - | ||||||||||||||||||
| 651 | bio2->init = 1; | - | ||||||||||||||||||
| 652 | - | |||||||||||||||||||
| 653 | return 1; executed 88 times by 1 test: return 1;Executed by:
| 88 | ||||||||||||||||||
| 654 | } | - | ||||||||||||||||||
| 655 | - | |||||||||||||||||||
| 656 | static void bio_destroy_pair(BIO *bio) | - | ||||||||||||||||||
| 657 | { | - | ||||||||||||||||||
| 658 | struct bio_bio_st *b = bio->ptr; | - | ||||||||||||||||||
| 659 | - | |||||||||||||||||||
| 660 | if (b != NULL) {
| 0-88 | ||||||||||||||||||
| 661 | BIO *peer_bio = b->peer; | - | ||||||||||||||||||
| 662 | - | |||||||||||||||||||
| 663 | if (peer_bio != NULL) {
| 0-88 | ||||||||||||||||||
| 664 | struct bio_bio_st *peer_b = peer_bio->ptr; | - | ||||||||||||||||||
| 665 | - | |||||||||||||||||||
| 666 | assert(peer_b != NULL); | - | ||||||||||||||||||
| 667 | assert(peer_b->peer == bio); | - | ||||||||||||||||||
| 668 | - | |||||||||||||||||||
| 669 | peer_b->peer = NULL; | - | ||||||||||||||||||
| 670 | peer_bio->init = 0; | - | ||||||||||||||||||
| 671 | assert(peer_b->buf != NULL); | - | ||||||||||||||||||
| 672 | peer_b->len = 0; | - | ||||||||||||||||||
| 673 | peer_b->offset = 0; | - | ||||||||||||||||||
| 674 | - | |||||||||||||||||||
| 675 | b->peer = NULL; | - | ||||||||||||||||||
| 676 | bio->init = 0; | - | ||||||||||||||||||
| 677 | assert(b->buf != NULL); | - | ||||||||||||||||||
| 678 | b->len = 0; | - | ||||||||||||||||||
| 679 | b->offset = 0; | - | ||||||||||||||||||
| 680 | } executed 88 times by 1 test: end of blockExecuted by:
| 88 | ||||||||||||||||||
| 681 | } executed 88 times by 1 test: end of blockExecuted by:
| 88 | ||||||||||||||||||
| 682 | } executed 88 times by 1 test: end of blockExecuted by:
| 88 | ||||||||||||||||||
| 683 | - | |||||||||||||||||||
| 684 | /* Exported convenience functions */ | - | ||||||||||||||||||
| 685 | int BIO_new_bio_pair(BIO **bio1_p, size_t writebuf1, | - | ||||||||||||||||||
| 686 | BIO **bio2_p, size_t writebuf2) | - | ||||||||||||||||||
| 687 | { | - | ||||||||||||||||||
| 688 | BIO *bio1 = NULL, *bio2 = NULL; | - | ||||||||||||||||||
| 689 | long r; | - | ||||||||||||||||||
| 690 | int ret = 0; | - | ||||||||||||||||||
| 691 | - | |||||||||||||||||||
| 692 | bio1 = BIO_new(BIO_s_bio()); | - | ||||||||||||||||||
| 693 | if (bio1 == NULL)
| 0-88 | ||||||||||||||||||
| 694 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
| 695 | bio2 = BIO_new(BIO_s_bio()); | - | ||||||||||||||||||
| 696 | if (bio2 == NULL)
| 0-88 | ||||||||||||||||||
| 697 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
| 698 | - | |||||||||||||||||||
| 699 | if (writebuf1) {
| 0-88 | ||||||||||||||||||
| 700 | r = BIO_set_write_buf_size(bio1, writebuf1); | - | ||||||||||||||||||
| 701 | if (!r)
| 0-88 | ||||||||||||||||||
| 702 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
| 703 | } executed 88 times by 1 test: end of blockExecuted by:
| 88 | ||||||||||||||||||
| 704 | if (writebuf2) {
| 0-88 | ||||||||||||||||||
| 705 | r = BIO_set_write_buf_size(bio2, writebuf2); | - | ||||||||||||||||||
| 706 | if (!r)
| 0-88 | ||||||||||||||||||
| 707 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
| 708 | } executed 88 times by 1 test: end of blockExecuted by:
| 88 | ||||||||||||||||||
| 709 | - | |||||||||||||||||||
| 710 | r = BIO_make_bio_pair(bio1, bio2); | - | ||||||||||||||||||
| 711 | if (!r)
| 0-88 | ||||||||||||||||||
| 712 | goto err; never executed: goto err; | 0 | ||||||||||||||||||
| 713 | ret = 1; | - | ||||||||||||||||||
| 714 | - | |||||||||||||||||||
| 715 | err: code before this statement executed 88 times by 1 test: err:Executed by:
| 88 | ||||||||||||||||||
| 716 | if (ret == 0) {
| 0-88 | ||||||||||||||||||
| 717 | BIO_free(bio1); | - | ||||||||||||||||||
| 718 | bio1 = NULL; | - | ||||||||||||||||||
| 719 | BIO_free(bio2); | - | ||||||||||||||||||
| 720 | bio2 = NULL; | - | ||||||||||||||||||
| 721 | } never executed: end of block | 0 | ||||||||||||||||||
| 722 | - | |||||||||||||||||||
| 723 | *bio1_p = bio1; | - | ||||||||||||||||||
| 724 | *bio2_p = bio2; | - | ||||||||||||||||||
| 725 | return ret; executed 88 times by 1 test: return ret;Executed by:
| 88 | ||||||||||||||||||
| 726 | } | - | ||||||||||||||||||
| 727 | - | |||||||||||||||||||
| 728 | size_t BIO_ctrl_get_write_guarantee(BIO *bio) | - | ||||||||||||||||||
| 729 | { | - | ||||||||||||||||||
| 730 | return BIO_ctrl(bio, BIO_C_GET_WRITE_GUARANTEE, 0, NULL); executed 1814 times by 1 test: return BIO_ctrl(bio, 140, 0, ((void *)0) );Executed by:
| 1814 | ||||||||||||||||||
| 731 | } | - | ||||||||||||||||||
| 732 | - | |||||||||||||||||||
| 733 | size_t BIO_ctrl_get_read_request(BIO *bio) | - | ||||||||||||||||||
| 734 | { | - | ||||||||||||||||||
| 735 | return BIO_ctrl(bio, BIO_C_GET_READ_REQUEST, 0, NULL); executed 1411 times by 1 test: return BIO_ctrl(bio, 141, 0, ((void *)0) );Executed by:
| 1411 | ||||||||||||||||||
| 736 | } | - | ||||||||||||||||||
| 737 | - | |||||||||||||||||||
| 738 | int BIO_ctrl_reset_read_request(BIO *bio) | - | ||||||||||||||||||
| 739 | { | - | ||||||||||||||||||
| 740 | return (BIO_ctrl(bio, BIO_C_RESET_READ_REQUEST, 0, NULL) != 0); never executed: return (BIO_ctrl(bio, 147, 0, ((void *)0) ) != 0); | 0 | ||||||||||||||||||
| 741 | } | - | ||||||||||||||||||
| 742 | - | |||||||||||||||||||
| 743 | /* | - | ||||||||||||||||||
| 744 | * BIO_nread0/nread/nwrite0/nwrite are available only for BIO pairs for now | - | ||||||||||||||||||
| 745 | * (conceivably some other BIOs could allow non-copying reads and writes | - | ||||||||||||||||||
| 746 | * too.) | - | ||||||||||||||||||
| 747 | */ | - | ||||||||||||||||||
| 748 | int BIO_nread0(BIO *bio, char **buf) | - | ||||||||||||||||||
| 749 | { | - | ||||||||||||||||||
| 750 | long ret; | - | ||||||||||||||||||
| 751 | - | |||||||||||||||||||
| 752 | if (!bio->init) {
| 0 | ||||||||||||||||||
| 753 | BIOerr(BIO_F_BIO_NREAD0, BIO_R_UNINITIALIZED); | - | ||||||||||||||||||
| 754 | return -2; never executed: return -2; | 0 | ||||||||||||||||||
| 755 | } | - | ||||||||||||||||||
| 756 | - | |||||||||||||||||||
| 757 | ret = BIO_ctrl(bio, BIO_C_NREAD0, 0, buf); | - | ||||||||||||||||||
| 758 | if (ret > INT_MAX)
| 0 | ||||||||||||||||||
| 759 | return INT_MAX; never executed: return 0x7fffffff; | 0 | ||||||||||||||||||
| 760 | else | - | ||||||||||||||||||
| 761 | return (int)ret; never executed: return (int)ret; | 0 | ||||||||||||||||||
| 762 | } | - | ||||||||||||||||||
| 763 | - | |||||||||||||||||||
| 764 | int BIO_nread(BIO *bio, char **buf, int num) | - | ||||||||||||||||||
| 765 | { | - | ||||||||||||||||||
| 766 | int ret; | - | ||||||||||||||||||
| 767 | - | |||||||||||||||||||
| 768 | if (!bio->init) {
| 0-403 | ||||||||||||||||||
| 769 | BIOerr(BIO_F_BIO_NREAD, BIO_R_UNINITIALIZED); | - | ||||||||||||||||||
| 770 | return -2; never executed: return -2; | 0 | ||||||||||||||||||
| 771 | } | - | ||||||||||||||||||
| 772 | - | |||||||||||||||||||
| 773 | ret = (int)BIO_ctrl(bio, BIO_C_NREAD, num, buf); | - | ||||||||||||||||||
| 774 | if (ret > 0)
| 0-403 | ||||||||||||||||||
| 775 | bio->num_read += ret; executed 403 times by 1 test: bio->num_read += ret;Executed by:
| 403 | ||||||||||||||||||
| 776 | return ret; executed 403 times by 1 test: return ret;Executed by:
| 403 | ||||||||||||||||||
| 777 | } | - | ||||||||||||||||||
| 778 | - | |||||||||||||||||||
| 779 | int BIO_nwrite0(BIO *bio, char **buf) | - | ||||||||||||||||||
| 780 | { | - | ||||||||||||||||||
| 781 | long ret; | - | ||||||||||||||||||
| 782 | - | |||||||||||||||||||
| 783 | if (!bio->init) {
| 0-1055 | ||||||||||||||||||
| 784 | BIOerr(BIO_F_BIO_NWRITE0, BIO_R_UNINITIALIZED); | - | ||||||||||||||||||
| 785 | return -2; never executed: return -2; | 0 | ||||||||||||||||||
| 786 | } | - | ||||||||||||||||||
| 787 | - | |||||||||||||||||||
| 788 | ret = BIO_ctrl(bio, BIO_C_NWRITE0, 0, buf); | - | ||||||||||||||||||
| 789 | if (ret > INT_MAX)
| 0-1055 | ||||||||||||||||||
| 790 | return INT_MAX; never executed: return 0x7fffffff; | 0 | ||||||||||||||||||
| 791 | else | - | ||||||||||||||||||
| 792 | return (int)ret; executed 1055 times by 1 test: return (int)ret;Executed by:
| 1055 | ||||||||||||||||||
| 793 | } | - | ||||||||||||||||||
| 794 | - | |||||||||||||||||||
| 795 | int BIO_nwrite(BIO *bio, char **buf, int num) | - | ||||||||||||||||||
| 796 | { | - | ||||||||||||||||||
| 797 | int ret; | - | ||||||||||||||||||
| 798 | - | |||||||||||||||||||
| 799 | if (!bio->init) {
| 0-1055 | ||||||||||||||||||
| 800 | BIOerr(BIO_F_BIO_NWRITE, BIO_R_UNINITIALIZED); | - | ||||||||||||||||||
| 801 | return -2; never executed: return -2; | 0 | ||||||||||||||||||
| 802 | } | - | ||||||||||||||||||
| 803 | - | |||||||||||||||||||
| 804 | ret = BIO_ctrl(bio, BIO_C_NWRITE, num, buf); | - | ||||||||||||||||||
| 805 | if (ret > 0)
| 0-1055 | ||||||||||||||||||
| 806 | bio->num_write += ret; executed 1055 times by 1 test: bio->num_write += ret;Executed by:
| 1055 | ||||||||||||||||||
| 807 | return ret; executed 1055 times by 1 test: return ret;Executed by:
| 1055 | ||||||||||||||||||
| 808 | } | - | ||||||||||||||||||
| Source code | Switch to Preprocessed file |