| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/bio/bss_mem.c |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /* | - | ||||||||||||||||||
| 2 | * Copyright 1995-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 <stdio.h> | - | ||||||||||||||||||
| 11 | #include <errno.h> | - | ||||||||||||||||||
| 12 | #include "bio_lcl.h" | - | ||||||||||||||||||
| 13 | #include "internal/cryptlib.h" | - | ||||||||||||||||||
| 14 | - | |||||||||||||||||||
| 15 | static int mem_write(BIO *h, const char *buf, int num); | - | ||||||||||||||||||
| 16 | static int mem_read(BIO *h, char *buf, int size); | - | ||||||||||||||||||
| 17 | static int mem_puts(BIO *h, const char *str); | - | ||||||||||||||||||
| 18 | static int mem_gets(BIO *h, char *str, int size); | - | ||||||||||||||||||
| 19 | static long mem_ctrl(BIO *h, int cmd, long arg1, void *arg2); | - | ||||||||||||||||||
| 20 | static int mem_new(BIO *h); | - | ||||||||||||||||||
| 21 | static int secmem_new(BIO *h); | - | ||||||||||||||||||
| 22 | static int mem_free(BIO *data); | - | ||||||||||||||||||
| 23 | static int mem_buf_free(BIO *data, int free_all); | - | ||||||||||||||||||
| 24 | static int mem_buf_sync(BIO *h); | - | ||||||||||||||||||
| 25 | - | |||||||||||||||||||
| 26 | static const BIO_METHOD mem_method = { | - | ||||||||||||||||||
| 27 | BIO_TYPE_MEM, | - | ||||||||||||||||||
| 28 | "memory buffer", | - | ||||||||||||||||||
| 29 | /* TODO: Convert to new style write function */ | - | ||||||||||||||||||
| 30 | bwrite_conv, | - | ||||||||||||||||||
| 31 | mem_write, | - | ||||||||||||||||||
| 32 | /* TODO: Convert to new style read function */ | - | ||||||||||||||||||
| 33 | bread_conv, | - | ||||||||||||||||||
| 34 | mem_read, | - | ||||||||||||||||||
| 35 | mem_puts, | - | ||||||||||||||||||
| 36 | mem_gets, | - | ||||||||||||||||||
| 37 | mem_ctrl, | - | ||||||||||||||||||
| 38 | mem_new, | - | ||||||||||||||||||
| 39 | mem_free, | - | ||||||||||||||||||
| 40 | NULL, /* mem_callback_ctrl */ | - | ||||||||||||||||||
| 41 | }; | - | ||||||||||||||||||
| 42 | - | |||||||||||||||||||
| 43 | static const BIO_METHOD secmem_method = { | - | ||||||||||||||||||
| 44 | BIO_TYPE_MEM, | - | ||||||||||||||||||
| 45 | "secure memory buffer", | - | ||||||||||||||||||
| 46 | /* TODO: Convert to new style write function */ | - | ||||||||||||||||||
| 47 | bwrite_conv, | - | ||||||||||||||||||
| 48 | mem_write, | - | ||||||||||||||||||
| 49 | /* TODO: Convert to new style read function */ | - | ||||||||||||||||||
| 50 | bread_conv, | - | ||||||||||||||||||
| 51 | mem_read, | - | ||||||||||||||||||
| 52 | mem_puts, | - | ||||||||||||||||||
| 53 | mem_gets, | - | ||||||||||||||||||
| 54 | mem_ctrl, | - | ||||||||||||||||||
| 55 | secmem_new, | - | ||||||||||||||||||
| 56 | mem_free, | - | ||||||||||||||||||
| 57 | NULL, /* mem_callback_ctrl */ | - | ||||||||||||||||||
| 58 | }; | - | ||||||||||||||||||
| 59 | - | |||||||||||||||||||
| 60 | /* BIO memory stores buffer and read pointer */ | - | ||||||||||||||||||
| 61 | typedef struct bio_buf_mem_st { | - | ||||||||||||||||||
| 62 | struct buf_mem_st *buf; /* allocated buffer */ | - | ||||||||||||||||||
| 63 | struct buf_mem_st *readp; /* read pointer */ | - | ||||||||||||||||||
| 64 | } BIO_BUF_MEM; | - | ||||||||||||||||||
| 65 | - | |||||||||||||||||||
| 66 | /* | - | ||||||||||||||||||
| 67 | * bio->num is used to hold the value to return on 'empty', if it is 0, | - | ||||||||||||||||||
| 68 | * should_retry is not set | - | ||||||||||||||||||
| 69 | */ | - | ||||||||||||||||||
| 70 | - | |||||||||||||||||||
| 71 | const BIO_METHOD *BIO_s_mem(void) | - | ||||||||||||||||||
| 72 | { | - | ||||||||||||||||||
| 73 | return &mem_method; executed 81666 times by 1 test: return &mem_method;Executed by:
| 81666 | ||||||||||||||||||
| 74 | } | - | ||||||||||||||||||
| 75 | - | |||||||||||||||||||
| 76 | const BIO_METHOD *BIO_s_secmem(void) | - | ||||||||||||||||||
| 77 | { | - | ||||||||||||||||||
| 78 | return(&secmem_method); executed 7726 times by 1 test: return(&secmem_method);Executed by:
| 7726 | ||||||||||||||||||
| 79 | } | - | ||||||||||||||||||
| 80 | - | |||||||||||||||||||
| 81 | BIO *BIO_new_mem_buf(const void *buf, int len) | - | ||||||||||||||||||
| 82 | { | - | ||||||||||||||||||
| 83 | BIO *ret; | - | ||||||||||||||||||
| 84 | BUF_MEM *b; | - | ||||||||||||||||||
| 85 | BIO_BUF_MEM *bb; | - | ||||||||||||||||||
| 86 | size_t sz; | - | ||||||||||||||||||
| 87 | - | |||||||||||||||||||
| 88 | if (buf == NULL) {
| 0-37022 | ||||||||||||||||||
| 89 | BIOerr(BIO_F_BIO_NEW_MEM_BUF, BIO_R_NULL_PARAMETER); | - | ||||||||||||||||||
| 90 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||
| 91 | } | - | ||||||||||||||||||
| 92 | sz = (len < 0) ? strlen(buf) : (size_t)len;
| 0-37022 | ||||||||||||||||||
| 93 | if ((ret = BIO_new(BIO_s_mem())) == NULL)
| 0-37022 | ||||||||||||||||||
| 94 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||
| 95 | bb = (BIO_BUF_MEM *)ret->ptr; | - | ||||||||||||||||||
| 96 | b = bb->buf; | - | ||||||||||||||||||
| 97 | /* Cast away const and trust in the MEM_RDONLY flag. */ | - | ||||||||||||||||||
| 98 | b->data = (void *)buf; | - | ||||||||||||||||||
| 99 | b->length = sz; | - | ||||||||||||||||||
| 100 | b->max = sz; | - | ||||||||||||||||||
| 101 | *bb->readp = *bb->buf; | - | ||||||||||||||||||
| 102 | ret->flags |= BIO_FLAGS_MEM_RDONLY; | - | ||||||||||||||||||
| 103 | /* Since this is static data retrying won't help */ | - | ||||||||||||||||||
| 104 | ret->num = 0; | - | ||||||||||||||||||
| 105 | return ret; executed 37022 times by 1 test: return ret;Executed by:
| 37022 | ||||||||||||||||||
| 106 | } | - | ||||||||||||||||||
| 107 | - | |||||||||||||||||||
| 108 | static int mem_init(BIO *bi, unsigned long flags) | - | ||||||||||||||||||
| 109 | { | - | ||||||||||||||||||
| 110 | BIO_BUF_MEM *bb = OPENSSL_zalloc(sizeof(*bb)); | - | ||||||||||||||||||
| 111 | - | |||||||||||||||||||
| 112 | if (bb == NULL)
| 0-111695 | ||||||||||||||||||
| 113 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 114 | if ((bb->buf = BUF_MEM_new_ex(flags)) == NULL) {
| 0-111695 | ||||||||||||||||||
| 115 | OPENSSL_free(bb); | - | ||||||||||||||||||
| 116 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 117 | } | - | ||||||||||||||||||
| 118 | if ((bb->readp = OPENSSL_zalloc(sizeof(*bb->readp))) == NULL) {
| 0-111695 | ||||||||||||||||||
| 119 | BUF_MEM_free(bb->buf); | - | ||||||||||||||||||
| 120 | OPENSSL_free(bb); | - | ||||||||||||||||||
| 121 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 122 | } | - | ||||||||||||||||||
| 123 | *bb->readp = *bb->buf; | - | ||||||||||||||||||
| 124 | bi->shutdown = 1; | - | ||||||||||||||||||
| 125 | bi->init = 1; | - | ||||||||||||||||||
| 126 | bi->num = -1; | - | ||||||||||||||||||
| 127 | bi->ptr = (char *)bb; | - | ||||||||||||||||||
| 128 | return 1; executed 111695 times by 1 test: return 1;Executed by:
| 111695 | ||||||||||||||||||
| 129 | } | - | ||||||||||||||||||
| 130 | - | |||||||||||||||||||
| 131 | static int mem_new(BIO *bi) | - | ||||||||||||||||||
| 132 | { | - | ||||||||||||||||||
| 133 | return mem_init(bi, 0L); executed 96243 times by 1 test: return mem_init(bi, 0L);Executed by:
| 96243 | ||||||||||||||||||
| 134 | } | - | ||||||||||||||||||
| 135 | - | |||||||||||||||||||
| 136 | static int secmem_new(BIO *bi) | - | ||||||||||||||||||
| 137 | { | - | ||||||||||||||||||
| 138 | return mem_init(bi, BUF_MEM_FLAG_SECURE); executed 15452 times by 1 test: return mem_init(bi, 0x01);Executed by:
| 15452 | ||||||||||||||||||
| 139 | } | - | ||||||||||||||||||
| 140 | - | |||||||||||||||||||
| 141 | static int mem_free(BIO *a) | - | ||||||||||||||||||
| 142 | { | - | ||||||||||||||||||
| 143 | return mem_buf_free(a, 1); executed 111695 times by 1 test: return mem_buf_free(a, 1);Executed by:
| 111695 | ||||||||||||||||||
| 144 | } | - | ||||||||||||||||||
| 145 | - | |||||||||||||||||||
| 146 | static int mem_buf_free(BIO *a, int free_all) | - | ||||||||||||||||||
| 147 | { | - | ||||||||||||||||||
| 148 | if (a == NULL)
| 0-111695 | ||||||||||||||||||
| 149 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 150 | - | |||||||||||||||||||
| 151 | if (a->shutdown && a->init && a->ptr != NULL) {
| 0-111695 | ||||||||||||||||||
| 152 | BIO_BUF_MEM *bb = (BIO_BUF_MEM *)a->ptr; | - | ||||||||||||||||||
| 153 | BUF_MEM *b = bb->buf; | - | ||||||||||||||||||
| 154 | - | |||||||||||||||||||
| 155 | if (a->flags & BIO_FLAGS_MEM_RDONLY)
| 37039-74656 | ||||||||||||||||||
| 156 | b->data = NULL; executed 37039 times by 1 test: b->data = ((void *)0) ;Executed by:
| 37039 | ||||||||||||||||||
| 157 | BUF_MEM_free(b); | - | ||||||||||||||||||
| 158 | if (free_all) {
| 0-111695 | ||||||||||||||||||
| 159 | OPENSSL_free(bb->readp); | - | ||||||||||||||||||
| 160 | OPENSSL_free(bb); | - | ||||||||||||||||||
| 161 | } executed 111695 times by 1 test: end of blockExecuted by:
| 111695 | ||||||||||||||||||
| 162 | a->ptr = NULL; | - | ||||||||||||||||||
| 163 | } executed 111695 times by 1 test: end of blockExecuted by:
| 111695 | ||||||||||||||||||
| 164 | return 1; executed 111695 times by 1 test: return 1;Executed by:
| 111695 | ||||||||||||||||||
| 165 | } | - | ||||||||||||||||||
| 166 | - | |||||||||||||||||||
| 167 | /* | - | ||||||||||||||||||
| 168 | * Reallocate memory buffer if read pointer differs | - | ||||||||||||||||||
| 169 | */ | - | ||||||||||||||||||
| 170 | static int mem_buf_sync(BIO *b) | - | ||||||||||||||||||
| 171 | { | - | ||||||||||||||||||
| 172 | if (b != NULL && b->init != 0 && b->ptr != NULL) {
| 0-346472 | ||||||||||||||||||
| 173 | BIO_BUF_MEM *bbm = (BIO_BUF_MEM *)b->ptr; | - | ||||||||||||||||||
| 174 | - | |||||||||||||||||||
| 175 | if (bbm->readp->data != bbm->buf->data) {
| 7781-338691 | ||||||||||||||||||
| 176 | memmove(bbm->buf->data, bbm->readp->data, bbm->readp->length); | - | ||||||||||||||||||
| 177 | bbm->buf->length = bbm->readp->length; | - | ||||||||||||||||||
| 178 | bbm->readp->data = bbm->buf->data; | - | ||||||||||||||||||
| 179 | } executed 7781 times by 1 test: end of blockExecuted by:
| 7781 | ||||||||||||||||||
| 180 | } executed 346472 times by 1 test: end of blockExecuted by:
| 346472 | ||||||||||||||||||
| 181 | return 0; executed 346472 times by 1 test: return 0;Executed by:
| 346472 | ||||||||||||||||||
| 182 | } | - | ||||||||||||||||||
| 183 | - | |||||||||||||||||||
| 184 | static int mem_read(BIO *b, char *out, int outl) | - | ||||||||||||||||||
| 185 | { | - | ||||||||||||||||||
| 186 | int ret = -1; | - | ||||||||||||||||||
| 187 | BIO_BUF_MEM *bbm = (BIO_BUF_MEM *)b->ptr; | - | ||||||||||||||||||
| 188 | BUF_MEM *bm = bbm->readp; | - | ||||||||||||||||||
| 189 | - | |||||||||||||||||||
| 190 | BIO_clear_retry_flags(b); | - | ||||||||||||||||||
| 191 | ret = (outl >= 0 && (size_t)outl > bm->length) ? (int)bm->length : outl;
| 0-929320 | ||||||||||||||||||
| 192 | if ((out != NULL) && (ret > 0)) {
| 0-929320 | ||||||||||||||||||
| 193 | memcpy(out, bm->data, ret); | - | ||||||||||||||||||
| 194 | bm->length -= ret; | - | ||||||||||||||||||
| 195 | bm->data += ret; | - | ||||||||||||||||||
| 196 | } else if (bm->length == 0) { executed 862038 times by 1 test: end of blockExecuted by:
| 0-862038 | ||||||||||||||||||
| 197 | ret = b->num; | - | ||||||||||||||||||
| 198 | if (ret != 0)
| 30279-37003 | ||||||||||||||||||
| 199 | BIO_set_retry_read(b); executed 30279 times by 1 test: BIO_set_flags(b, (0x01|0x08));Executed by:
| 30279 | ||||||||||||||||||
| 200 | } executed 67282 times by 1 test: end of blockExecuted by:
| 67282 | ||||||||||||||||||
| 201 | return ret; executed 929320 times by 1 test: return ret;Executed by:
| 929320 | ||||||||||||||||||
| 202 | } | - | ||||||||||||||||||
| 203 | - | |||||||||||||||||||
| 204 | static int mem_write(BIO *b, const char *in, int inl) | - | ||||||||||||||||||
| 205 | { | - | ||||||||||||||||||
| 206 | int ret = -1; | - | ||||||||||||||||||
| 207 | int blen; | - | ||||||||||||||||||
| 208 | BIO_BUF_MEM *bbm = (BIO_BUF_MEM *)b->ptr; | - | ||||||||||||||||||
| 209 | - | |||||||||||||||||||
| 210 | if (in == NULL) {
| 0-328234 | ||||||||||||||||||
| 211 | BIOerr(BIO_F_MEM_WRITE, BIO_R_NULL_PARAMETER); | - | ||||||||||||||||||
| 212 | goto end; never executed: goto end; | 0 | ||||||||||||||||||
| 213 | } | - | ||||||||||||||||||
| 214 | if (b->flags & BIO_FLAGS_MEM_RDONLY) {
| 0-328234 | ||||||||||||||||||
| 215 | BIOerr(BIO_F_MEM_WRITE, BIO_R_WRITE_TO_READ_ONLY_BIO); | - | ||||||||||||||||||
| 216 | goto end; never executed: goto end; | 0 | ||||||||||||||||||
| 217 | } | - | ||||||||||||||||||
| 218 | BIO_clear_retry_flags(b); | - | ||||||||||||||||||
| 219 | if (inl == 0)
| 0-328234 | ||||||||||||||||||
| 220 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
| 221 | blen = bbm->readp->length; | - | ||||||||||||||||||
| 222 | mem_buf_sync(b); | - | ||||||||||||||||||
| 223 | if (BUF_MEM_grow_clean(bbm->buf, blen + inl) == 0)
| 0-328234 | ||||||||||||||||||
| 224 | goto end; never executed: goto end; | 0 | ||||||||||||||||||
| 225 | memcpy(bbm->buf->data + blen, in, inl); | - | ||||||||||||||||||
| 226 | *bbm->readp = *bbm->buf; | - | ||||||||||||||||||
| 227 | ret = inl; | - | ||||||||||||||||||
| 228 | end: code before this statement executed 328234 times by 1 test: end:Executed by:
| 328234 | ||||||||||||||||||
| 229 | return ret; executed 328234 times by 1 test: return ret;Executed by:
| 328234 | ||||||||||||||||||
| 230 | } | - | ||||||||||||||||||
| 231 | - | |||||||||||||||||||
| 232 | static long mem_ctrl(BIO *b, int cmd, long num, void *ptr) | - | ||||||||||||||||||
| 233 | { | - | ||||||||||||||||||
| 234 | long ret = 1; | - | ||||||||||||||||||
| 235 | char **pptr; | - | ||||||||||||||||||
| 236 | BIO_BUF_MEM *bbm = (BIO_BUF_MEM *)b->ptr; | - | ||||||||||||||||||
| 237 | BUF_MEM *bm; | - | ||||||||||||||||||
| 238 | - | |||||||||||||||||||
| 239 | switch (cmd) { | - | ||||||||||||||||||
| 240 | case BIO_CTRL_RESET: executed 1974 times by 1 test: case 1:Executed by:
| 1974 | ||||||||||||||||||
| 241 | bm = bbm->buf; | - | ||||||||||||||||||
| 242 | if (bm->data != NULL) {
| 6-1968 | ||||||||||||||||||
| 243 | /* For read only case reset to the start again */ | - | ||||||||||||||||||
| 244 | if ((b->flags & BIO_FLAGS_MEM_RDONLY) || (b->flags & BIO_FLAGS_NONCLEAR_RST)) {
| 0-1968 | ||||||||||||||||||
| 245 | bm->length = bm->max; | - | ||||||||||||||||||
| 246 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 247 | memset(bm->data, 0, bm->max); | - | ||||||||||||||||||
| 248 | bm->length = 0; | - | ||||||||||||||||||
| 249 | } executed 1968 times by 1 test: end of blockExecuted by:
| 1968 | ||||||||||||||||||
| 250 | *bbm->readp = *bbm->buf; | - | ||||||||||||||||||
| 251 | } executed 1968 times by 1 test: end of blockExecuted by:
| 1968 | ||||||||||||||||||
| 252 | break; executed 1974 times by 1 test: break;Executed by:
| 1974 | ||||||||||||||||||
| 253 | case BIO_CTRL_EOF: never executed: case 2: | 0 | ||||||||||||||||||
| 254 | bm = bbm->readp; | - | ||||||||||||||||||
| 255 | ret = (long)(bm->length == 0); | - | ||||||||||||||||||
| 256 | break; never executed: break; | 0 | ||||||||||||||||||
| 257 | case BIO_C_SET_BUF_MEM_EOF_RETURN: executed 927 times by 1 test: case 130:Executed by:
| 927 | ||||||||||||||||||
| 258 | b->num = (int)num; | - | ||||||||||||||||||
| 259 | break; executed 927 times by 1 test: break;Executed by:
| 927 | ||||||||||||||||||
| 260 | case BIO_CTRL_INFO: executed 23655 times by 1 test: case 3:Executed by:
| 23655 | ||||||||||||||||||
| 261 | bm = bbm->readp; | - | ||||||||||||||||||
| 262 | ret = (long)bm->length; | - | ||||||||||||||||||
| 263 | if (ptr != NULL) {
| 5424-18231 | ||||||||||||||||||
| 264 | pptr = (char **)ptr; | - | ||||||||||||||||||
| 265 | *pptr = (char *)&(bm->data[0]); | - | ||||||||||||||||||
| 266 | } executed 5424 times by 1 test: end of blockExecuted by:
| 5424 | ||||||||||||||||||
| 267 | break; executed 23655 times by 1 test: break;Executed by:
| 23655 | ||||||||||||||||||
| 268 | case BIO_C_SET_BUF_MEM: never executed: case 114: | 0 | ||||||||||||||||||
| 269 | mem_buf_free(b, 0); | - | ||||||||||||||||||
| 270 | b->shutdown = (int)num; | - | ||||||||||||||||||
| 271 | bbm->buf = ptr; | - | ||||||||||||||||||
| 272 | *bbm->readp = *bbm->buf; | - | ||||||||||||||||||
| 273 | b->ptr = bbm; | - | ||||||||||||||||||
| 274 | break; never executed: break; | 0 | ||||||||||||||||||
| 275 | case BIO_C_GET_BUF_MEM_PTR: executed 18238 times by 1 test: case 115:Executed by:
| 18238 | ||||||||||||||||||
| 276 | if (ptr != NULL) {
| 0-18238 | ||||||||||||||||||
| 277 | mem_buf_sync(b); | - | ||||||||||||||||||
| 278 | bm = bbm->readp; | - | ||||||||||||||||||
| 279 | pptr = (char **)ptr; | - | ||||||||||||||||||
| 280 | *pptr = (char *)bm; | - | ||||||||||||||||||
| 281 | } executed 18238 times by 1 test: end of blockExecuted by:
| 18238 | ||||||||||||||||||
| 282 | break; executed 18238 times by 1 test: break;Executed by:
| 18238 | ||||||||||||||||||
| 283 | case BIO_CTRL_GET_CLOSE: never executed: case 8: | 0 | ||||||||||||||||||
| 284 | ret = (long)b->shutdown; | - | ||||||||||||||||||
| 285 | break; never executed: break; | 0 | ||||||||||||||||||
| 286 | case BIO_CTRL_SET_CLOSE: executed 9057 times by 1 test: case 9:Executed by:
| 9057 | ||||||||||||||||||
| 287 | b->shutdown = (int)num; | - | ||||||||||||||||||
| 288 | break; executed 9057 times by 1 test: break;Executed by:
| 9057 | ||||||||||||||||||
| 289 | case BIO_CTRL_WPENDING: executed 483 times by 1 test: case 13:Executed by:
| 483 | ||||||||||||||||||
| 290 | ret = 0L; | - | ||||||||||||||||||
| 291 | break; executed 483 times by 1 test: break;Executed by:
| 483 | ||||||||||||||||||
| 292 | case BIO_CTRL_PENDING: executed 1564 times by 1 test: case 10:Executed by:
| 1564 | ||||||||||||||||||
| 293 | bm = bbm->readp; | - | ||||||||||||||||||
| 294 | ret = (long)bm->length; | - | ||||||||||||||||||
| 295 | break; executed 1564 times by 1 test: break;Executed by:
| 1564 | ||||||||||||||||||
| 296 | case BIO_CTRL_DUP: never executed: case 12: | 0 | ||||||||||||||||||
| 297 | case BIO_CTRL_FLUSH: executed 17065 times by 1 test: case 11:Executed by:
| 17065 | ||||||||||||||||||
| 298 | ret = 1; | - | ||||||||||||||||||
| 299 | break; executed 17065 times by 1 test: break;Executed by:
| 17065 | ||||||||||||||||||
| 300 | case BIO_CTRL_PUSH: executed 45670 times by 1 test: case 6:Executed by:
| 45670 | ||||||||||||||||||
| 301 | case BIO_CTRL_POP: executed 8620 times by 1 test: case 7:Executed by:
| 8620 | ||||||||||||||||||
| 302 | default: executed 7648 times by 1 test: default:Executed by:
| 7648 | ||||||||||||||||||
| 303 | ret = 0; | - | ||||||||||||||||||
| 304 | break; executed 61938 times by 1 test: break;Executed by:
| 61938 | ||||||||||||||||||
| 305 | } | - | ||||||||||||||||||
| 306 | return ret; executed 134901 times by 1 test: return ret;Executed by:
| 134901 | ||||||||||||||||||
| 307 | } | - | ||||||||||||||||||
| 308 | - | |||||||||||||||||||
| 309 | static int mem_gets(BIO *bp, char *buf, int size) | - | ||||||||||||||||||
| 310 | { | - | ||||||||||||||||||
| 311 | int i, j; | - | ||||||||||||||||||
| 312 | int ret = -1; | - | ||||||||||||||||||
| 313 | char *p; | - | ||||||||||||||||||
| 314 | BIO_BUF_MEM *bbm = (BIO_BUF_MEM *)bp->ptr; | - | ||||||||||||||||||
| 315 | BUF_MEM *bm = bbm->readp; | - | ||||||||||||||||||
| 316 | - | |||||||||||||||||||
| 317 | BIO_clear_retry_flags(bp); | - | ||||||||||||||||||
| 318 | j = bm->length; | - | ||||||||||||||||||
| 319 | if ((size - 1) < j)
| 57017-73714 | ||||||||||||||||||
| 320 | j = size - 1; executed 73714 times by 1 test: j = size - 1;Executed by:
| 73714 | ||||||||||||||||||
| 321 | if (j <= 0) {
| 591-130140 | ||||||||||||||||||
| 322 | *buf = '\0'; | - | ||||||||||||||||||
| 323 | return 0; executed 591 times by 1 test: return 0;Executed by:
| 591 | ||||||||||||||||||
| 324 | } | - | ||||||||||||||||||
| 325 | p = bm->data; | - | ||||||||||||||||||
| 326 | for (i = 0; i < j; i++) {
| 402-5014074 | ||||||||||||||||||
| 327 | if (p[i] == '\n') {
| 129738-4884336 | ||||||||||||||||||
| 328 | i++; | - | ||||||||||||||||||
| 329 | break; executed 129738 times by 1 test: break;Executed by:
| 129738 | ||||||||||||||||||
| 330 | } | - | ||||||||||||||||||
| 331 | } executed 4884336 times by 1 test: end of blockExecuted by:
| 4884336 | ||||||||||||||||||
| 332 | - | |||||||||||||||||||
| 333 | /* | - | ||||||||||||||||||
| 334 | * i is now the max num of bytes to copy, either j or up to | - | ||||||||||||||||||
| 335 | * and including the first newline | - | ||||||||||||||||||
| 336 | */ | - | ||||||||||||||||||
| 337 | - | |||||||||||||||||||
| 338 | i = mem_read(bp, buf, i); | - | ||||||||||||||||||
| 339 | if (i > 0)
| 0-130140 | ||||||||||||||||||
| 340 | buf[i] = '\0'; executed 130140 times by 1 test: buf[i] = '\0';Executed by:
| 130140 | ||||||||||||||||||
| 341 | ret = i; | - | ||||||||||||||||||
| 342 | return ret; executed 130140 times by 1 test: return ret;Executed by:
| 130140 | ||||||||||||||||||
| 343 | } | - | ||||||||||||||||||
| 344 | - | |||||||||||||||||||
| 345 | static int mem_puts(BIO *bp, const char *str) | - | ||||||||||||||||||
| 346 | { | - | ||||||||||||||||||
| 347 | int n, ret; | - | ||||||||||||||||||
| 348 | - | |||||||||||||||||||
| 349 | n = strlen(str); | - | ||||||||||||||||||
| 350 | ret = mem_write(bp, str, n); | - | ||||||||||||||||||
| 351 | /* memory semantics is that it will always work */ | - | ||||||||||||||||||
| 352 | return ret; executed 263329 times by 1 test: return ret;Executed by:
| 263329 | ||||||||||||||||||
| 353 | } | - | ||||||||||||||||||
| Source code | Switch to Preprocessed file |