OpenCoverage

ssl3_buffer.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/openssl/src/ssl/record/ssl3_buffer.c
Source codeSwitch to Preprocessed file
LineSourceCount
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 "../ssl_locl.h"-
11#include "record_locl.h"-
12-
13void SSL3_BUFFER_set_data(SSL3_BUFFER *b, const unsigned char *d, size_t n)-
14{-
15 if (d != NULL)
d != ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
16 memcpy(b->buf, d, n);
never executed: memcpy(b->buf, d, n);
0
17 b->left = n;-
18 b->offset = 0;-
19}
never executed: end of block
0
20-
21/*-
22 * Clear the contents of an SSL3_BUFFER but retain any memory allocated. Also-
23 * retains the default_len setting-
24 */-
25void SSL3_BUFFER_clear(SSL3_BUFFER *b)-
26{-
27 b->offset = 0;-
28 b->left = 0;-
29}
executed 16269 times by 2 tests: end of block
Executed by:
  • libssl.so.1.1
  • tls13encryptiontest
16269
30-
31void SSL3_BUFFER_release(SSL3_BUFFER *b)-
32{-
33 OPENSSL_free(b->buf);-
34 b->buf = NULL;-
35}
executed 14 times by 1 test: end of block
Executed by:
  • libssl.so.1.1
14
36-
37int ssl3_setup_read_buffer(SSL *s)-
38{-
39 unsigned char *p;-
40 size_t len, align = 0, headerlen;-
41 SSL3_BUFFER *b;-
42-
43 b = RECORD_LAYER_get_rbuf(&s->rlayer);-
44-
45 if (SSL_IS_DTLS(s))
(s->method->ss...c_flags & 0x8)Description
TRUEevaluated 400 times by 1 test
Evaluated by:
  • libssl.so.1.1
FALSEevaluated 9048 times by 1 test
Evaluated by:
  • libssl.so.1.1
400-9048
46 headerlen = DTLS1_RT_HEADER_LENGTH;
executed 400 times by 1 test: headerlen = 13;
Executed by:
  • libssl.so.1.1
400
47 else-
48 headerlen = SSL3_RT_HEADER_LENGTH;
executed 9048 times by 1 test: headerlen = 5;
Executed by:
  • libssl.so.1.1
9048
49-
50#if defined(SSL3_ALIGN_PAYLOAD) && SSL3_ALIGN_PAYLOAD!=0-
51 align = (-SSL3_RT_HEADER_LENGTH) & (SSL3_ALIGN_PAYLOAD - 1);-
52#endif-
53-
54 if (b->buf == NULL) {
b->buf == ((void *)0)Description
TRUEevaluated 7982 times by 1 test
Evaluated by:
  • libssl.so.1.1
FALSEevaluated 1466 times by 1 test
Evaluated by:
  • libssl.so.1.1
1466-7982
55 len = SSL3_RT_MAX_PLAIN_LENGTH-
56 + SSL3_RT_MAX_ENCRYPTED_OVERHEAD + headerlen + align;-
57#ifndef OPENSSL_NO_COMP-
58 if (ssl_allow_compression(s))
ssl_allow_compression(s)Description
TRUEnever evaluated
FALSEevaluated 7982 times by 1 test
Evaluated by:
  • libssl.so.1.1
0-7982
59 len += SSL3_RT_MAX_COMPRESSED_OVERHEAD;
never executed: len += 1024;
0
60#endif-
61 if (b->default_len > len)
b->default_len > lenDescription
TRUEnever evaluated
FALSEevaluated 7982 times by 1 test
Evaluated by:
  • libssl.so.1.1
0-7982
62 len = b->default_len;
never executed: len = b->default_len;
0
63 if ((p = OPENSSL_malloc(len)) == NULL) {
(p = CRYPTO_ma...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 7982 times by 1 test
Evaluated by:
  • libssl.so.1.1
0-7982
64 /*-
65 * We've got a malloc failure, and we're still initialising buffers.-
66 * We assume we're so doomed that we won't even be able to send an-
67 * alert.-
68 */-
69 SSLfatal(s, SSL_AD_NO_ALERT, SSL_F_SSL3_SETUP_READ_BUFFER,-
70 ERR_R_MALLOC_FAILURE);-
71 return 0;
never executed: return 0;
0
72 }-
73 b->buf = p;-
74 b->len = len;-
75 }
executed 7982 times by 1 test: end of block
Executed by:
  • libssl.so.1.1
7982
76-
77 RECORD_LAYER_set_packet(&s->rlayer, &(b->buf[0]));-
78 return 1;
executed 9448 times by 1 test: return 1;
Executed by:
  • libssl.so.1.1
9448
79}-
80-
81int ssl3_setup_write_buffer(SSL *s, size_t numwpipes, size_t len)-
82{-
83 unsigned char *p;-
84 size_t align = 0, headerlen;-
85 SSL3_BUFFER *wb;-
86 size_t currpipe;-
87-
88 s->rlayer.numwpipes = numwpipes;-
89-
90 if (len == 0) {
len == 0Description
TRUEevaluated 9354 times by 1 test
Evaluated by:
  • libssl.so.1.1
FALSEnever evaluated
0-9354
91 if (SSL_IS_DTLS(s))
(s->method->ss...c_flags & 0x8)Description
TRUEevaluated 400 times by 1 test
Evaluated by:
  • libssl.so.1.1
FALSEevaluated 8954 times by 1 test
Evaluated by:
  • libssl.so.1.1
400-8954
92 headerlen = DTLS1_RT_HEADER_LENGTH + 1;
executed 400 times by 1 test: headerlen = 13 + 1;
Executed by:
  • libssl.so.1.1
400
93 else-
94 headerlen = SSL3_RT_HEADER_LENGTH;
executed 8954 times by 1 test: headerlen = 5;
Executed by:
  • libssl.so.1.1
8954
95-
96#if defined(SSL3_ALIGN_PAYLOAD) && SSL3_ALIGN_PAYLOAD!=0-
97 align = (-SSL3_RT_HEADER_LENGTH) & (SSL3_ALIGN_PAYLOAD - 1);-
98#endif-
99-
100 len = ssl_get_max_send_fragment(s)-
101 + SSL3_RT_SEND_MAX_ENCRYPTED_OVERHEAD + headerlen + align;-
102#ifndef OPENSSL_NO_COMP-
103 if (ssl_allow_compression(s))
ssl_allow_compression(s)Description
TRUEnever evaluated
FALSEevaluated 9354 times by 1 test
Evaluated by:
  • libssl.so.1.1
0-9354
104 len += SSL3_RT_MAX_COMPRESSED_OVERHEAD;
never executed: len += 1024;
0
105#endif-
106 if (!(s->options & SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS))
!(s->options & 0x00000800U)Description
TRUEevaluated 9354 times by 1 test
Evaluated by:
  • libssl.so.1.1
FALSEnever evaluated
0-9354
107 len += headerlen + align + SSL3_RT_SEND_MAX_ENCRYPTED_OVERHEAD;
executed 9354 times by 1 test: len += headerlen + align + (16 + 64);
Executed by:
  • libssl.so.1.1
9354
108 }
executed 9354 times by 1 test: end of block
Executed by:
  • libssl.so.1.1
9354
109-
110 wb = RECORD_LAYER_get_wbuf(&s->rlayer);-
111 for (currpipe = 0; currpipe < numwpipes; currpipe++) {
currpipe < numwpipesDescription
TRUEevaluated 9354 times by 1 test
Evaluated by:
  • libssl.so.1.1
FALSEevaluated 9354 times by 1 test
Evaluated by:
  • libssl.so.1.1
9354
112 SSL3_BUFFER *thiswb = &wb[currpipe];-
113-
114 if (thiswb->buf != NULL && thiswb->len != len) {
thiswb->buf != ((void *)0)Description
TRUEevaluated 1323 times by 1 test
Evaluated by:
  • libssl.so.1.1
FALSEevaluated 8031 times by 1 test
Evaluated by:
  • libssl.so.1.1
thiswb->len != lenDescription
TRUEevaluated 14 times by 1 test
Evaluated by:
  • libssl.so.1.1
FALSEevaluated 1309 times by 1 test
Evaluated by:
  • libssl.so.1.1
14-8031
115 OPENSSL_free(thiswb->buf);-
116 thiswb->buf = NULL; /* force reallocation */-
117 }
executed 14 times by 1 test: end of block
Executed by:
  • libssl.so.1.1
14
118-
119 if (thiswb->buf == NULL) {
thiswb->buf == ((void *)0)Description
TRUEevaluated 8045 times by 1 test
Evaluated by:
  • libssl.so.1.1
FALSEevaluated 1309 times by 1 test
Evaluated by:
  • libssl.so.1.1
1309-8045
120 p = OPENSSL_malloc(len);-
121 if (p == NULL) {
p == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 8045 times by 1 test
Evaluated by:
  • libssl.so.1.1
0-8045
122 s->rlayer.numwpipes = currpipe;-
123 /*-
124 * We've got a malloc failure, and we're still initialising-
125 * buffers. We assume we're so doomed that we won't even be able-
126 * to send an alert.-
127 */-
128 SSLfatal(s, SSL_AD_NO_ALERT,-
129 SSL_F_SSL3_SETUP_WRITE_BUFFER, ERR_R_MALLOC_FAILURE);-
130 return 0;
never executed: return 0;
0
131 }-
132 memset(thiswb, 0, sizeof(SSL3_BUFFER));-
133 thiswb->buf = p;-
134 thiswb->len = len;-
135 }
executed 8045 times by 1 test: end of block
Executed by:
  • libssl.so.1.1
8045
136 }
executed 9354 times by 1 test: end of block
Executed by:
  • libssl.so.1.1
9354
137-
138 return 1;
executed 9354 times by 1 test: return 1;
Executed by:
  • libssl.so.1.1
9354
139}-
140-
141int ssl3_setup_buffers(SSL *s)-
142{-
143 if (!ssl3_setup_read_buffer(s)) {
!ssl3_setup_read_buffer(s)Description
TRUEnever evaluated
FALSEevaluated 9342 times by 1 test
Evaluated by:
  • libssl.so.1.1
0-9342
144 /* SSLfatal() already called */-
145 return 0;
never executed: return 0;
0
146 }-
147 if (!ssl3_setup_write_buffer(s, 1, 0)) {
!ssl3_setup_wr...uffer(s, 1, 0)Description
TRUEnever evaluated
FALSEevaluated 9342 times by 1 test
Evaluated by:
  • libssl.so.1.1
0-9342
148 /* SSLfatal() already called */-
149 return 0;
never executed: return 0;
0
150 }-
151 return 1;
executed 9342 times by 1 test: return 1;
Executed by:
  • libssl.so.1.1
9342
152}-
153-
154int ssl3_release_write_buffer(SSL *s)-
155{-
156 SSL3_BUFFER *wb;-
157 size_t pipes;-
158-
159 pipes = s->rlayer.numwpipes;-
160 while (pipes > 0) {
pipes > 0Description
TRUEevaluated 8031 times by 1 test
Evaluated by:
  • libssl.so.1.1
FALSEevaluated 24238 times by 2 tests
Evaluated by:
  • libssl.so.1.1
  • tls13encryptiontest
8031-24238
161 wb = &RECORD_LAYER_get_wbuf(&s->rlayer)[pipes - 1];-
162-
163 OPENSSL_free(wb->buf);-
164 wb->buf = NULL;-
165 pipes--;-
166 }
executed 8031 times by 1 test: end of block
Executed by:
  • libssl.so.1.1
8031
167 s->rlayer.numwpipes = 0;-
168 return 1;
executed 24238 times by 2 tests: return 1;
Executed by:
  • libssl.so.1.1
  • tls13encryptiontest
24238
169}-
170-
171int ssl3_release_read_buffer(SSL *s)-
172{-
173 SSL3_BUFFER *b;-
174-
175 b = RECORD_LAYER_get_rbuf(&s->rlayer);-
176 OPENSSL_free(b->buf);-
177 b->buf = NULL;-
178 return 1;
executed 7966 times by 1 test: return 1;
Executed by:
  • libssl.so.1.1
7966
179}-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.2.2