OpenCoverage

sshbuf.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/openssh/src/sshbuf.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/* $OpenBSD: sshbuf.c,v 1.12 2018/07/09 21:56:06 markus Exp $ */-
2/*-
3 * Copyright (c) 2011 Damien Miller-
4 *-
5 * Permission to use, copy, modify, and distribute this software for any-
6 * purpose with or without fee is hereby granted, provided that the above-
7 * copyright notice and this permission notice appear in all copies.-
8 *-
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES-
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF-
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR-
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES-
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN-
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF-
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.-
16 */-
17-
18#define SSHBUF_INTERNAL-
19#include "includes.h"-
20-
21#include <sys/types.h>-
22#include <signal.h>-
23#include <stdlib.h>-
24#include <stdio.h>-
25#include <string.h>-
26-
27#include "ssherr.h"-
28#include "sshbuf.h"-
29#include "misc.h"-
30-
31static inline int-
32sshbuf_check_sanity(const struct sshbuf *buf)-
33{-
34 SSHBUF_TELL("sanity");-
35 if (__predict_false(buf == NULL ||
__builtin_expe...ize) != 0), 0)Description
TRUEnever evaluated
FALSEevaluated 49736721 times by 6 tests
Evaluated by:
  • ssh-keygen
  • sshd
  • test_hostkeys
  • test_kex
  • test_sshbuf
  • test_sshkey
0-49736721
36 (!buf->readonly && buf->d != buf->cd) ||-
37 buf->refcount < 1 || buf->refcount > SSHBUF_REFS_MAX ||-
38 buf->cd == NULL ||-
39 buf->max_size > SSHBUF_SIZE_MAX ||-
40 buf->alloc > buf->max_size ||-
41 buf->size > buf->alloc ||-
42 buf->off > buf->size)) {-
43 /* Do not try to recover from corrupted buffer internals */-
44 SSHBUF_DBG(("SSH_ERR_INTERNAL_ERROR"));-
45 signal(SIGSEGV, SIG_DFL);-
46 raise(SIGSEGV);-
47 return SSH_ERR_INTERNAL_ERROR;
never executed: return -1;
0
48 }-
49 return 0;
executed 49736721 times by 6 tests: return 0;
Executed by:
  • ssh-keygen
  • sshd
  • test_hostkeys
  • test_kex
  • test_sshbuf
  • test_sshkey
49736721
50}-
51-
52static void-
53sshbuf_maybe_pack(struct sshbuf *buf, int force)-
54{-
55 SSHBUF_DBG(("force %d", force));-
56 SSHBUF_TELL("pre-pack");-
57 if (buf->off == 0 || buf->readonly || buf->refcount > 1)
buf->off == 0Description
TRUEevaluated 9797402 times by 6 tests
Evaluated by:
  • ssh-keygen
  • sshd
  • test_hostkeys
  • test_kex
  • test_sshbuf
  • test_sshkey
FALSEevaluated 62084 times by 1 test
Evaluated by:
  • test_sshbuf
buf->readonlyDescription
TRUEnever evaluated
FALSEevaluated 62084 times by 1 test
Evaluated by:
  • test_sshbuf
buf->refcount > 1Description
TRUEnever evaluated
FALSEevaluated 62084 times by 1 test
Evaluated by:
  • test_sshbuf
0-9797402
58 return;
executed 9797402 times by 6 tests: return;
Executed by:
  • ssh-keygen
  • sshd
  • test_hostkeys
  • test_kex
  • test_sshbuf
  • test_sshkey
9797402
59 if (force ||
forceDescription
TRUEevaluated 16536 times by 1 test
Evaluated by:
  • test_sshbuf
FALSEevaluated 45548 times by 1 test
Evaluated by:
  • test_sshbuf
16536-45548
60 (buf->off >= SSHBUF_PACK_MIN && buf->off >= buf->size / 2)) {
buf->off >= 8192Description
TRUEevaluated 112 times by 1 test
Evaluated by:
  • test_sshbuf
FALSEevaluated 45436 times by 1 test
Evaluated by:
  • test_sshbuf
buf->off >= buf->size / 2Description
TRUEevaluated 112 times by 1 test
Evaluated by:
  • test_sshbuf
FALSEnever evaluated
0-45436
61 memmove(buf->d, buf->d + buf->off, buf->size - buf->off);-
62 buf->size -= buf->off;-
63 buf->off = 0;-
64 SSHBUF_TELL("packed");-
65 }
executed 16648 times by 1 test: end of block
Executed by:
  • test_sshbuf
16648
66}
executed 62084 times by 1 test: end of block
Executed by:
  • test_sshbuf
62084
67-
68struct sshbuf *-
69sshbuf_new(void)-
70{-
71 struct sshbuf *ret;-
72-
73 if ((ret = calloc(sizeof(*ret), 1)) == NULL)
(ret = calloc(...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 2058693 times by 6 tests
Evaluated by:
  • ssh-keygen
  • sshd
  • test_hostkeys
  • test_kex
  • test_sshbuf
  • test_sshkey
0-2058693
74 return NULL;
never executed: return ((void *)0) ;
0
75 ret->alloc = SSHBUF_SIZE_INIT;-
76 ret->max_size = SSHBUF_SIZE_MAX;-
77 ret->readonly = 0;-
78 ret->refcount = 1;-
79 ret->parent = NULL;-
80 if ((ret->cd = ret->d = calloc(1, ret->alloc)) == NULL) {
(ret->cd = ret...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 2058693 times by 6 tests
Evaluated by:
  • ssh-keygen
  • sshd
  • test_hostkeys
  • test_kex
  • test_sshbuf
  • test_sshkey
0-2058693
81 free(ret);-
82 return NULL;
never executed: return ((void *)0) ;
0
83 }-
84 return ret;
executed 2058693 times by 6 tests: return ret;
Executed by:
  • ssh-keygen
  • sshd
  • test_hostkeys
  • test_kex
  • test_sshbuf
  • test_sshkey
2058693
85}-
86-
87struct sshbuf *-
88sshbuf_from(const void *blob, size_t len)-
89{-
90 struct sshbuf *ret;-
91-
92 if (blob == NULL || len > SSHBUF_SIZE_MAX ||
blob == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 265205 times by 6 tests
Evaluated by:
  • ssh-keygen
  • sshd
  • test_hostkeys
  • test_kex
  • test_sshbuf
  • test_sshkey
len > 0x8000000Description
TRUEnever evaluated
FALSEevaluated 265205 times by 6 tests
Evaluated by:
  • ssh-keygen
  • sshd
  • test_hostkeys
  • test_kex
  • test_sshbuf
  • test_sshkey
0-265205
93 (ret = calloc(sizeof(*ret), 1)) == NULL)
(ret = calloc(...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 265205 times by 6 tests
Evaluated by:
  • ssh-keygen
  • sshd
  • test_hostkeys
  • test_kex
  • test_sshbuf
  • test_sshkey
0-265205
94 return NULL;
never executed: return ((void *)0) ;
0
95 ret->alloc = ret->size = ret->max_size = len;-
96 ret->readonly = 1;-
97 ret->refcount = 1;-
98 ret->parent = NULL;-
99 ret->cd = blob;-
100 ret->d = NULL;-
101 return ret;
executed 265205 times by 6 tests: return ret;
Executed by:
  • ssh-keygen
  • sshd
  • test_hostkeys
  • test_kex
  • test_sshbuf
  • test_sshkey
265205
102}-
103-
104int-
105sshbuf_set_parent(struct sshbuf *child, struct sshbuf *parent)-
106{-
107 int r;-
108-
109 if ((r = sshbuf_check_sanity(child)) != 0 ||
(r = sshbuf_ch...y(child)) != 0Description
TRUEnever evaluated
FALSEevaluated 132747 times by 6 tests
Evaluated by:
  • ssh-keygen
  • sshd
  • test_hostkeys
  • test_kex
  • test_sshbuf
  • test_sshkey
0-132747
110 (r = sshbuf_check_sanity(parent)) != 0)
(r = sshbuf_ch...(parent)) != 0Description
TRUEnever evaluated
FALSEevaluated 132747 times by 6 tests
Evaluated by:
  • ssh-keygen
  • sshd
  • test_hostkeys
  • test_kex
  • test_sshbuf
  • test_sshkey
0-132747
111 return r;
never executed: return r;
0
112 child->parent = parent;-
113 child->parent->refcount++;-
114 return 0;
executed 132747 times by 6 tests: return 0;
Executed by:
  • ssh-keygen
  • sshd
  • test_hostkeys
  • test_kex
  • test_sshbuf
  • test_sshkey
132747
115}-
116-
117struct sshbuf *-
118sshbuf_fromb(struct sshbuf *buf)-
119{-
120 struct sshbuf *ret;-
121-
122 if (sshbuf_check_sanity(buf) != 0)
sshbuf_check_sanity(buf) != 0Description
TRUEnever evaluated
FALSEevaluated 43764 times by 6 tests
Evaluated by:
  • ssh-keygen
  • sshd
  • test_hostkeys
  • test_kex
  • test_sshbuf
  • test_sshkey
0-43764
123 return NULL;
never executed: return ((void *)0) ;
0
124 if ((ret = sshbuf_from(sshbuf_ptr(buf), sshbuf_len(buf))) == NULL)
(ret = sshbuf_...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 43764 times by 6 tests
Evaluated by:
  • ssh-keygen
  • sshd
  • test_hostkeys
  • test_kex
  • test_sshbuf
  • test_sshkey
0-43764
125 return NULL;
never executed: return ((void *)0) ;
0
126 if (sshbuf_set_parent(ret, buf) != 0) {
sshbuf_set_par...ret, buf) != 0Description
TRUEnever evaluated
FALSEevaluated 43764 times by 6 tests
Evaluated by:
  • ssh-keygen
  • sshd
  • test_hostkeys
  • test_kex
  • test_sshbuf
  • test_sshkey
0-43764
127 sshbuf_free(ret);-
128 return NULL;
never executed: return ((void *)0) ;
0
129 }-
130 return ret;
executed 43764 times by 6 tests: return ret;
Executed by:
  • ssh-keygen
  • sshd
  • test_hostkeys
  • test_kex
  • test_sshbuf
  • test_sshkey
43764
131}-
132-
133void-
134sshbuf_free(struct sshbuf *buf)-
135{-
136 if (buf == NULL)
buf == ((void *)0)Description
TRUEevaluated 2564902 times by 6 tests
Evaluated by:
  • ssh-keygen
  • sshd
  • test_hostkeys
  • test_kex
  • test_sshbuf
  • test_sshkey
FALSEevaluated 2456643 times by 6 tests
Evaluated by:
  • ssh-keygen
  • sshd
  • test_hostkeys
  • test_kex
  • test_sshbuf
  • test_sshkey
2456643-2564902
137 return;
executed 2564902 times by 6 tests: return;
Executed by:
  • ssh-keygen
  • sshd
  • test_hostkeys
  • test_kex
  • test_sshbuf
  • test_sshkey
2564902
138 /*-
139 * The following will leak on insane buffers, but this is the safest-
140 * course of action - an invalid pointer or already-freed pointer may-
141 * have been passed to us and continuing to scribble over memory would-
142 * be bad.-
143 */-
144 if (sshbuf_check_sanity(buf) != 0)
sshbuf_check_sanity(buf) != 0Description
TRUEnever evaluated
FALSEevaluated 2456643 times by 6 tests
Evaluated by:
  • ssh-keygen
  • sshd
  • test_hostkeys
  • test_kex
  • test_sshbuf
  • test_sshkey
0-2456643
145 return;
never executed: return;
0
146 /*-
147 * If we are a child, the free our parent to decrement its reference-
148 * count and possibly free it.-
149 */-
150 sshbuf_free(buf->parent);-
151 buf->parent = NULL;-
152 /*-
153 * If we are a parent with still-extant children, then don't free just-
154 * yet. The last child's call to sshbuf_free should decrement our-
155 * refcount to 0 and trigger the actual free.-
156 */-
157 buf->refcount--;-
158 if (buf->refcount > 0)
buf->refcount > 0Description
TRUEevaluated 132747 times by 6 tests
Evaluated by:
  • ssh-keygen
  • sshd
  • test_hostkeys
  • test_kex
  • test_sshbuf
  • test_sshkey
FALSEevaluated 2323896 times by 6 tests
Evaluated by:
  • ssh-keygen
  • sshd
  • test_hostkeys
  • test_kex
  • test_sshbuf
  • test_sshkey
132747-2323896
159 return;
executed 132747 times by 6 tests: return;
Executed by:
  • ssh-keygen
  • sshd
  • test_hostkeys
  • test_kex
  • test_sshbuf
  • test_sshkey
132747
160 if (!buf->readonly) {
!buf->readonlyDescription
TRUEevaluated 2058691 times by 6 tests
Evaluated by:
  • ssh-keygen
  • sshd
  • test_hostkeys
  • test_kex
  • test_sshbuf
  • test_sshkey
FALSEevaluated 265205 times by 6 tests
Evaluated by:
  • ssh-keygen
  • sshd
  • test_hostkeys
  • test_kex
  • test_sshbuf
  • test_sshkey
265205-2058691
161 explicit_bzero(buf->d, buf->alloc);-
162 free(buf->d);-
163 }
executed 2058691 times by 6 tests: end of block
Executed by:
  • ssh-keygen
  • sshd
  • test_hostkeys
  • test_kex
  • test_sshbuf
  • test_sshkey
2058691
164 explicit_bzero(buf, sizeof(*buf));-
165 free(buf);-
166}
executed 2323896 times by 6 tests: end of block
Executed by:
  • ssh-keygen
  • sshd
  • test_hostkeys
  • test_kex
  • test_sshbuf
  • test_sshkey
2323896
167-
168void-
169sshbuf_reset(struct sshbuf *buf)-
170{-
171 u_char *d;-
172-
173 if (buf->readonly || buf->refcount > 1) {
buf->readonlyDescription
TRUEnever evaluated
FALSEevaluated 258629 times by 5 tests
Evaluated by:
  • ssh-keygen
  • sshd
  • test_kex
  • test_sshbuf
  • test_sshkey
buf->refcount > 1Description
TRUEnever evaluated
FALSEevaluated 258629 times by 5 tests
Evaluated by:
  • ssh-keygen
  • sshd
  • test_kex
  • test_sshbuf
  • test_sshkey
0-258629
174 /* Nonsensical. Just make buffer appear empty */-
175 buf->off = buf->size;-
176 return;
never executed: return;
0
177 }-
178 (void) sshbuf_check_sanity(buf);-
179 buf->off = buf->size = 0;-
180 if (buf->alloc != SSHBUF_SIZE_INIT) {
buf->alloc != 256Description
TRUEevaluated 227377 times by 4 tests
Evaluated by:
  • sshd
  • test_kex
  • test_sshbuf
  • test_sshkey
FALSEevaluated 31252 times by 4 tests
Evaluated by:
  • ssh-keygen
  • sshd
  • test_kex
  • test_sshkey
31252-227377
181 if ((d = recallocarray(buf->d, buf->alloc, SSHBUF_SIZE_INIT,
(d = recalloca...!= ((void *)0)Description
TRUEevaluated 227377 times by 4 tests
Evaluated by:
  • sshd
  • test_kex
  • test_sshbuf
  • test_sshkey
FALSEnever evaluated
0-227377
182 1)) != NULL) {
(d = recalloca...!= ((void *)0)Description
TRUEevaluated 227377 times by 4 tests
Evaluated by:
  • sshd
  • test_kex
  • test_sshbuf
  • test_sshkey
FALSEnever evaluated
0-227377
183 buf->cd = buf->d = d;-
184 buf->alloc = SSHBUF_SIZE_INIT;-
185 }
executed 227377 times by 4 tests: end of block
Executed by:
  • sshd
  • test_kex
  • test_sshbuf
  • test_sshkey
227377
186 }
executed 227377 times by 4 tests: end of block
Executed by:
  • sshd
  • test_kex
  • test_sshbuf
  • test_sshkey
227377
187 explicit_bzero(buf->d, SSHBUF_SIZE_INIT);-
188}
executed 258629 times by 5 tests: end of block
Executed by:
  • ssh-keygen
  • sshd
  • test_kex
  • test_sshbuf
  • test_sshkey
258629
189-
190size_t-
191sshbuf_max_size(const struct sshbuf *buf)-
192{-
193 return buf->max_size;
executed 315020 times by 1 test: return buf->max_size;
Executed by:
  • test_sshbuf
315020
194}-
195-
196size_t-
197sshbuf_alloc(const struct sshbuf *buf)-
198{-
199 return buf->alloc;
executed 1 time by 1 test: return buf->alloc;
Executed by:
  • test_sshbuf
1
200}-
201-
202const struct sshbuf *-
203sshbuf_parent(const struct sshbuf *buf)-
204{-
205 return buf->parent;
executed 3 times by 1 test: return buf->parent;
Executed by:
  • test_sshbuf
3
206}-
207-
208u_int-
209sshbuf_refcount(const struct sshbuf *buf)-
210{-
211 return buf->refcount;
executed 3 times by 1 test: return buf->refcount;
Executed by:
  • test_sshbuf
3
212}-
213-
214int-
215sshbuf_set_max_size(struct sshbuf *buf, size_t max_size)-
216{-
217 size_t rlen;-
218 u_char *dp;-
219 int r;-
220-
221 SSHBUF_DBG(("set max buf = %p len = %zu", buf, max_size));-
222 if ((r = sshbuf_check_sanity(buf)) != 0)
(r = sshbuf_ch...ity(buf)) != 0Description
TRUEnever evaluated
FALSEevaluated 26457 times by 1 test
Evaluated by:
  • test_sshbuf
0-26457
223 return r;
never executed: return r;
0
224 if (max_size == buf->max_size)
max_size == buf->max_sizeDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • test_sshbuf
FALSEevaluated 26456 times by 1 test
Evaluated by:
  • test_sshbuf
1-26456
225 return 0;
executed 1 time by 1 test: return 0;
Executed by:
  • test_sshbuf
1
226 if (buf->readonly || buf->refcount > 1)
buf->readonlyDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • test_sshbuf
FALSEevaluated 26455 times by 1 test
Evaluated by:
  • test_sshbuf
buf->refcount > 1Description
TRUEnever evaluated
FALSEevaluated 26455 times by 1 test
Evaluated by:
  • test_sshbuf
0-26455
227 return SSH_ERR_BUFFER_READ_ONLY;
executed 1 time by 1 test: return -49;
Executed by:
  • test_sshbuf
1
228 if (max_size > SSHBUF_SIZE_MAX)
max_size > 0x8000000Description
TRUEnever evaluated
FALSEevaluated 26455 times by 1 test
Evaluated by:
  • test_sshbuf
0-26455
229 return SSH_ERR_NO_BUFFER_SPACE;
never executed: return -9;
0
230 /* pack and realloc if necessary */-
231 sshbuf_maybe_pack(buf, max_size < buf->size);-
232 if (max_size < buf->alloc && max_size > buf->size) {
max_size < buf->allocDescription
TRUEevaluated 15829 times by 1 test
Evaluated by:
  • test_sshbuf
FALSEevaluated 10626 times by 1 test
Evaluated by:
  • test_sshbuf
max_size > buf->sizeDescription
TRUEevaluated 5581 times by 1 test
Evaluated by:
  • test_sshbuf
FALSEevaluated 10248 times by 1 test
Evaluated by:
  • test_sshbuf
5581-15829
233 if (buf->size < SSHBUF_SIZE_INIT)
buf->size < 256Description
TRUEevaluated 197 times by 1 test
Evaluated by:
  • test_sshbuf
FALSEevaluated 5384 times by 1 test
Evaluated by:
  • test_sshbuf
197-5384
234 rlen = SSHBUF_SIZE_INIT;
executed 197 times by 1 test: rlen = 256;
Executed by:
  • test_sshbuf
197
235 else-
236 rlen = ROUNDUP(buf->size, SSHBUF_SIZE_INC);
executed 5384 times by 1 test: rlen = ((((buf->size)+((256)-1))/(256))*(256));
Executed by:
  • test_sshbuf
5384
237 if (rlen > max_size)
rlen > max_sizeDescription
TRUEevaluated 379 times by 1 test
Evaluated by:
  • test_sshbuf
FALSEevaluated 5202 times by 1 test
Evaluated by:
  • test_sshbuf
379-5202
238 rlen = max_size;
executed 379 times by 1 test: rlen = max_size;
Executed by:
  • test_sshbuf
379
239 SSHBUF_DBG(("new alloc = %zu", rlen));-
240 if ((dp = recallocarray(buf->d, buf->alloc, rlen, 1)) == NULL)
(dp = recalloc...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 5581 times by 1 test
Evaluated by:
  • test_sshbuf
0-5581
241 return SSH_ERR_ALLOC_FAIL;
never executed: return -2;
0
242 buf->cd = buf->d = dp;-
243 buf->alloc = rlen;-
244 }
executed 5581 times by 1 test: end of block
Executed by:
  • test_sshbuf
5581
245 SSHBUF_TELL("new-max");-
246 if (max_size < buf->alloc)
max_size < buf->allocDescription
TRUEevaluated 10248 times by 1 test
Evaluated by:
  • test_sshbuf
FALSEevaluated 16207 times by 1 test
Evaluated by:
  • test_sshbuf
10248-16207
247 return SSH_ERR_NO_BUFFER_SPACE;
executed 10248 times by 1 test: return -9;
Executed by:
  • test_sshbuf
10248
248 buf->max_size = max_size;-
249 return 0;
executed 16207 times by 1 test: return 0;
Executed by:
  • test_sshbuf
16207
250}-
251-
252size_t-
253sshbuf_len(const struct sshbuf *buf)-
254{-
255 if (sshbuf_check_sanity(buf) != 0)
sshbuf_check_sanity(buf) != 0Description
TRUEnever evaluated
FALSEevaluated 16980196 times by 6 tests
Evaluated by:
  • ssh-keygen
  • sshd
  • test_hostkeys
  • test_kex
  • test_sshbuf
  • test_sshkey
0-16980196
256 return 0;
never executed: return 0;
0
257 return buf->size - buf->off;
executed 16980196 times by 6 tests: return buf->size - buf->off;
Executed by:
  • ssh-keygen
  • sshd
  • test_hostkeys
  • test_kex
  • test_sshbuf
  • test_sshkey
16980196
258}-
259-
260size_t-
261sshbuf_avail(const struct sshbuf *buf)-
262{-
263 if (sshbuf_check_sanity(buf) != 0 || buf->readonly || buf->refcount > 1)
sshbuf_check_sanity(buf) != 0Description
TRUEnever evaluated
FALSEevaluated 471423 times by 1 test
Evaluated by:
  • test_sshbuf
buf->readonlyDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • test_sshbuf
FALSEevaluated 471422 times by 1 test
Evaluated by:
  • test_sshbuf
buf->refcount > 1Description
TRUEnever evaluated
FALSEevaluated 471422 times by 1 test
Evaluated by:
  • test_sshbuf
0-471423
264 return 0;
executed 1 time by 1 test: return 0;
Executed by:
  • test_sshbuf
1
265 return buf->max_size - (buf->size - buf->off);
executed 471422 times by 1 test: return buf->max_size - (buf->size - buf->off);
Executed by:
  • test_sshbuf
471422
266}-
267-
268const u_char *-
269sshbuf_ptr(const struct sshbuf *buf)-
270{-
271 if (sshbuf_check_sanity(buf) != 0)
sshbuf_check_sanity(buf) != 0Description
TRUEnever evaluated
FALSEevaluated 11919937 times by 6 tests
Evaluated by:
  • ssh-keygen
  • sshd
  • test_hostkeys
  • test_kex
  • test_sshbuf
  • test_sshkey
0-11919937
272 return NULL;
never executed: return ((void *)0) ;
0
273 return buf->cd + buf->off;
executed 11919937 times by 6 tests: return buf->cd + buf->off;
Executed by:
  • ssh-keygen
  • sshd
  • test_hostkeys
  • test_kex
  • test_sshbuf
  • test_sshkey
11919937
274}-
275-
276u_char *-
277sshbuf_mutable_ptr(const struct sshbuf *buf)-
278{-
279 if (sshbuf_check_sanity(buf) != 0 || buf->readonly || buf->refcount > 1)
sshbuf_check_sanity(buf) != 0Description
TRUEnever evaluated
FALSEevaluated 1386 times by 4 tests
Evaluated by:
  • ssh-keygen
  • test_kex
  • test_sshbuf
  • test_sshkey
buf->readonlyDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • test_sshbuf
FALSEevaluated 1384 times by 4 tests
Evaluated by:
  • ssh-keygen
  • test_kex
  • test_sshbuf
  • test_sshkey
buf->refcount > 1Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • test_sshbuf
FALSEevaluated 1383 times by 4 tests
Evaluated by:
  • ssh-keygen
  • test_kex
  • test_sshbuf
  • test_sshkey
0-1386
280 return NULL;
executed 3 times by 1 test: return ((void *)0) ;
Executed by:
  • test_sshbuf
3
281 return buf->d + buf->off;
executed 1383 times by 4 tests: return buf->d + buf->off;
Executed by:
  • ssh-keygen
  • test_kex
  • test_sshbuf
  • test_sshkey
1383
282}-
283-
284int-
285sshbuf_check_reserve(const struct sshbuf *buf, size_t len)-
286{-
287 int r;-
288-
289 if ((r = sshbuf_check_sanity(buf)) != 0)
(r = sshbuf_ch...ity(buf)) != 0Description
TRUEnever evaluated
FALSEevaluated 10164853 times by 6 tests
Evaluated by:
  • ssh-keygen
  • sshd
  • test_hostkeys
  • test_kex
  • test_sshbuf
  • test_sshkey
0-10164853
290 return r;
never executed: return r;
0
291 if (buf->readonly || buf->refcount > 1)
buf->readonlyDescription
TRUEevaluated 3 times by 1 test
Evaluated by:
  • test_sshbuf
FALSEevaluated 10164850 times by 6 tests
Evaluated by:
  • ssh-keygen
  • sshd
  • test_hostkeys
  • test_kex
  • test_sshbuf
  • test_sshkey
buf->refcount > 1Description
TRUEnever evaluated
FALSEevaluated 10164850 times by 6 tests
Evaluated by:
  • ssh-keygen
  • sshd
  • test_hostkeys
  • test_kex
  • test_sshbuf
  • test_sshkey
0-10164850
292 return SSH_ERR_BUFFER_READ_ONLY;
executed 3 times by 1 test: return -49;
Executed by:
  • test_sshbuf
3
293 SSHBUF_TELL("check");-
294 /* Check that len is reasonable and that max_size + available < len */-
295 if (len > buf->max_size || buf->max_size - len < buf->size - buf->off)
len > buf->max_sizeDescription
TRUEevaluated 29305 times by 1 test
Evaluated by:
  • test_sshbuf
FALSEevaluated 10135545 times by 6 tests
Evaluated by:
  • ssh-keygen
  • sshd
  • test_hostkeys
  • test_kex
  • test_sshbuf
  • test_sshkey
buf->max_size ...ize - buf->offDescription
TRUEevaluated 19512 times by 1 test
Evaluated by:
  • test_sshbuf
FALSEevaluated 10116033 times by 6 tests
Evaluated by:
  • ssh-keygen
  • sshd
  • test_hostkeys
  • test_kex
  • test_sshbuf
  • test_sshkey
19512-10135545
296 return SSH_ERR_NO_BUFFER_SPACE;
executed 48817 times by 1 test: return -9;
Executed by:
  • test_sshbuf
48817
297 return 0;
executed 10116033 times by 6 tests: return 0;
Executed by:
  • ssh-keygen
  • sshd
  • test_hostkeys
  • test_kex
  • test_sshbuf
  • test_sshkey
10116033
298}-
299-
300int-
301sshbuf_allocate(struct sshbuf *buf, size_t len)-
302{-
303 size_t rlen, need;-
304 u_char *dp;-
305 int r;-
306-
307 SSHBUF_DBG(("allocate buf = %p len = %zu", buf, len));-
308 if ((r = sshbuf_check_reserve(buf, len)) != 0)
(r = sshbuf_ch...uf, len)) != 0Description
TRUEevaluated 48819 times by 1 test
Evaluated by:
  • test_sshbuf
FALSEevaluated 9833031 times by 6 tests
Evaluated by:
  • ssh-keygen
  • sshd
  • test_hostkeys
  • test_kex
  • test_sshbuf
  • test_sshkey
48819-9833031
309 return r;
executed 48819 times by 1 test: return r;
Executed by:
  • test_sshbuf
48819
310 /*-
311 * If the requested allocation appended would push us past max_size-
312 * then pack the buffer, zeroing buf->off.-
313 */-
314 sshbuf_maybe_pack(buf, buf->size + len > buf->max_size);-
315 SSHBUF_TELL("allocate");-
316 if (len + buf->size <= buf->alloc)
len + buf->size <= buf->allocDescription
TRUEevaluated 9550029 times by 6 tests
Evaluated by:
  • ssh-keygen
  • sshd
  • test_hostkeys
  • test_kex
  • test_sshbuf
  • test_sshkey
FALSEevaluated 283002 times by 6 tests
Evaluated by:
  • ssh-keygen
  • sshd
  • test_hostkeys
  • test_kex
  • test_sshbuf
  • test_sshkey
283002-9550029
317 return 0; /* already have it. */
executed 9550029 times by 6 tests: return 0;
Executed by:
  • ssh-keygen
  • sshd
  • test_hostkeys
  • test_kex
  • test_sshbuf
  • test_sshkey
9550029
318-
319 /*-
320 * Prefer to alloc in SSHBUF_SIZE_INC units, but-
321 * allocate less if doing so would overflow max_size.-
322 */-
323 need = len + buf->size - buf->alloc;-
324 rlen = ROUNDUP(buf->alloc + need, SSHBUF_SIZE_INC);-
325 SSHBUF_DBG(("need %zu initial rlen %zu", need, rlen));-
326 if (rlen > buf->max_size)
rlen > buf->max_sizeDescription
TRUEevaluated 1385 times by 1 test
Evaluated by:
  • test_sshbuf
FALSEevaluated 281617 times by 6 tests
Evaluated by:
  • ssh-keygen
  • sshd
  • test_hostkeys
  • test_kex
  • test_sshbuf
  • test_sshkey
1385-281617
327 rlen = buf->alloc + need;
executed 1385 times by 1 test: rlen = buf->alloc + need;
Executed by:
  • test_sshbuf
1385
328 SSHBUF_DBG(("adjusted rlen %zu", rlen));-
329 if ((dp = recallocarray(buf->d, buf->alloc, rlen, 1)) == NULL) {
(dp = recalloc...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 283002 times by 6 tests
Evaluated by:
  • ssh-keygen
  • sshd
  • test_hostkeys
  • test_kex
  • test_sshbuf
  • test_sshkey
0-283002
330 SSHBUF_DBG(("realloc fail"));-
331 return SSH_ERR_ALLOC_FAIL;
never executed: return -2;
0
332 }-
333 buf->alloc = rlen;-
334 buf->cd = buf->d = dp;-
335 if ((r = sshbuf_check_reserve(buf, len)) < 0) {
(r = sshbuf_ch...buf, len)) < 0Description
TRUEnever evaluated
FALSEevaluated 283002 times by 6 tests
Evaluated by:
  • ssh-keygen
  • sshd
  • test_hostkeys
  • test_kex
  • test_sshbuf
  • test_sshkey
0-283002
336 /* shouldn't fail */-
337 return r;
never executed: return r;
0
338 }-
339 SSHBUF_TELL("done");-
340 return 0;
executed 283002 times by 6 tests: return 0;
Executed by:
  • ssh-keygen
  • sshd
  • test_hostkeys
  • test_kex
  • test_sshbuf
  • test_sshkey
283002
341}-
342-
343int-
344sshbuf_reserve(struct sshbuf *buf, size_t len, u_char **dpp)-
345{-
346 u_char *dp;-
347 int r;-
348-
349 if (dpp != NULL)
dpp != ((void *)0)Description
TRUEevaluated 9881846 times by 6 tests
Evaluated by:
  • ssh-keygen
  • sshd
  • test_hostkeys
  • test_kex
  • test_sshbuf
  • test_sshkey
FALSEevaluated 4 times by 1 test
Evaluated by:
  • test_sshbuf
4-9881846
350 *dpp = NULL;
executed 9881846 times by 6 tests: *dpp = ((void *)0) ;
Executed by:
  • ssh-keygen
  • sshd
  • test_hostkeys
  • test_kex
  • test_sshbuf
  • test_sshkey
9881846
351-
352 SSHBUF_DBG(("reserve buf = %p len = %zu", buf, len));-
353 if ((r = sshbuf_allocate(buf, len)) != 0)
(r = sshbuf_al...uf, len)) != 0Description
TRUEevaluated 48819 times by 1 test
Evaluated by:
  • test_sshbuf
FALSEevaluated 9833031 times by 6 tests
Evaluated by:
  • ssh-keygen
  • sshd
  • test_hostkeys
  • test_kex
  • test_sshbuf
  • test_sshkey
48819-9833031
354 return r;
executed 48819 times by 1 test: return r;
Executed by:
  • test_sshbuf
48819
355-
356 dp = buf->d + buf->size;-
357 buf->size += len;-
358 if (dpp != NULL)
dpp != ((void *)0)Description
TRUEevaluated 9833028 times by 6 tests
Evaluated by:
  • ssh-keygen
  • sshd
  • test_hostkeys
  • test_kex
  • test_sshbuf
  • test_sshkey
FALSEevaluated 3 times by 1 test
Evaluated by:
  • test_sshbuf
3-9833028
359 *dpp = dp;
executed 9833028 times by 6 tests: *dpp = dp;
Executed by:
  • ssh-keygen
  • sshd
  • test_hostkeys
  • test_kex
  • test_sshbuf
  • test_sshkey
9833028
360 return 0;
executed 9833031 times by 6 tests: return 0;
Executed by:
  • ssh-keygen
  • sshd
  • test_hostkeys
  • test_kex
  • test_sshbuf
  • test_sshkey
9833031
361}-
362-
363int-
364sshbuf_consume(struct sshbuf *buf, size_t len)-
365{-
366 int r;-
367-
368 SSHBUF_DBG(("len = %zu", len));-
369 if ((r = sshbuf_check_sanity(buf)) != 0)
(r = sshbuf_ch...ity(buf)) != 0Description
TRUEnever evaluated
FALSEevaluated 7081632 times by 6 tests
Evaluated by:
  • ssh-keygen
  • sshd
  • test_hostkeys
  • test_kex
  • test_sshbuf
  • test_sshkey
0-7081632
370 return r;
never executed: return r;
0
371 if (len == 0)
len == 0Description
TRUEevaluated 1295 times by 2 tests
Evaluated by:
  • test_kex
  • test_sshbuf
FALSEevaluated 7080337 times by 6 tests
Evaluated by:
  • ssh-keygen
  • sshd
  • test_hostkeys
  • test_kex
  • test_sshbuf
  • test_sshkey
1295-7080337
372 return 0;
executed 1295 times by 2 tests: return 0;
Executed by:
  • test_kex
  • test_sshbuf
1295
373 if (len > sshbuf_len(buf))
len > sshbuf_len(buf)Description
TRUEevaluated 7059 times by 2 tests
Evaluated by:
  • test_sshbuf
  • test_sshkey
FALSEevaluated 7073278 times by 6 tests
Evaluated by:
  • ssh-keygen
  • sshd
  • test_hostkeys
  • test_kex
  • test_sshbuf
  • test_sshkey
7059-7073278
374 return SSH_ERR_MESSAGE_INCOMPLETE;
executed 7059 times by 2 tests: return -3;
Executed by:
  • test_sshbuf
  • test_sshkey
7059
375 buf->off += len;-
376 /* deal with empty buffer */-
377 if (buf->off == buf->size)
buf->off == buf->sizeDescription
TRUEevaluated 167940 times by 6 tests
Evaluated by:
  • ssh-keygen
  • sshd
  • test_hostkeys
  • test_kex
  • test_sshbuf
  • test_sshkey
FALSEevaluated 6905338 times by 6 tests
Evaluated by:
  • ssh-keygen
  • sshd
  • test_hostkeys
  • test_kex
  • test_sshbuf
  • test_sshkey
167940-6905338
378 buf->off = buf->size = 0;
executed 167940 times by 6 tests: buf->off = buf->size = 0;
Executed by:
  • ssh-keygen
  • sshd
  • test_hostkeys
  • test_kex
  • test_sshbuf
  • test_sshkey
167940
379 SSHBUF_TELL("done");-
380 return 0;
executed 7073278 times by 6 tests: return 0;
Executed by:
  • ssh-keygen
  • sshd
  • test_hostkeys
  • test_kex
  • test_sshbuf
  • test_sshkey
7073278
381}-
382-
383int-
384sshbuf_consume_end(struct sshbuf *buf, size_t len)-
385{-
386 int r;-
387-
388 SSHBUF_DBG(("len = %zu", len));-
389 if ((r = sshbuf_check_sanity(buf)) != 0)
(r = sshbuf_ch...ity(buf)) != 0Description
TRUEnever evaluated
FALSEevaluated 66307 times by 4 tests
Evaluated by:
  • ssh-keygen
  • test_kex
  • test_sshbuf
  • test_sshkey
0-66307
390 return r;
never executed: return r;
0
391 if (len == 0)
len == 0Description
TRUEevaluated 1335 times by 1 test
Evaluated by:
  • test_sshbuf
FALSEevaluated 64972 times by 4 tests
Evaluated by:
  • ssh-keygen
  • test_kex
  • test_sshbuf
  • test_sshkey
1335-64972
392 return 0;
executed 1335 times by 1 test: return 0;
Executed by:
  • test_sshbuf
1335
393 if (len > sshbuf_len(buf))
len > sshbuf_len(buf)Description
TRUEevaluated 7040 times by 1 test
Evaluated by:
  • test_sshbuf
FALSEevaluated 57932 times by 4 tests
Evaluated by:
  • ssh-keygen
  • test_kex
  • test_sshbuf
  • test_sshkey
7040-57932
394 return SSH_ERR_MESSAGE_INCOMPLETE;
executed 7040 times by 1 test: return -3;
Executed by:
  • test_sshbuf
7040
395 buf->size -= len;-
396 SSHBUF_TELL("done");-
397 return 0;
executed 57932 times by 4 tests: return 0;
Executed by:
  • ssh-keygen
  • test_kex
  • test_sshbuf
  • test_sshkey
57932
398}-
399-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.2.2