OpenCoverage

opacket.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/openssh/src/opacket.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/* $OpenBSD: opacket.c,v 1.7 2017/10/20 01:56:39 djm Exp $ */-
2/* Written by Markus Friedl. Placed in the public domain. */-
3-
4#include "includes.h"-
5-
6#include <stdarg.h>-
7-
8#include "ssherr.h"-
9#include "packet.h"-
10#include "log.h"-
11-
12struct ssh *active_state, *backup_state;-
13-
14/* Map old to new API */-
15-
16void-
17ssh_packet_start(struct ssh *ssh, u_char type)-
18{-
19 int r;-
20-
21 if ((r = sshpkt_start(ssh, type)) != 0)
(r = sshpkt_st...h, type)) != 0Description
TRUEnever evaluated
FALSEnever evaluated
0
22 fatal("%s: %s", __func__, ssh_err(r));
never executed: fatal("%s: %s", __func__, ssh_err(r));
0
23}
never executed: end of block
0
24-
25void-
26ssh_packet_put_char(struct ssh *ssh, int value)-
27{-
28 u_char ch = value;-
29 int r;-
30-
31 if ((r = sshpkt_put_u8(ssh, ch)) != 0)
(r = sshpkt_pu...ssh, ch)) != 0Description
TRUEnever evaluated
FALSEnever evaluated
0
32 fatal("%s: %s", __func__, ssh_err(r));
never executed: fatal("%s: %s", __func__, ssh_err(r));
0
33}
never executed: end of block
0
34-
35void-
36ssh_packet_put_int(struct ssh *ssh, u_int value)-
37{-
38 int r;-
39-
40 if ((r = sshpkt_put_u32(ssh, value)) != 0)
(r = sshpkt_pu..., value)) != 0Description
TRUEnever evaluated
FALSEnever evaluated
0
41 fatal("%s: %s", __func__, ssh_err(r));
never executed: fatal("%s: %s", __func__, ssh_err(r));
0
42}
never executed: end of block
0
43-
44void-
45ssh_packet_put_int64(struct ssh *ssh, u_int64_t value)-
46{-
47 int r;-
48-
49 if ((r = sshpkt_put_u64(ssh, value)) != 0)
(r = sshpkt_pu..., value)) != 0Description
TRUEnever evaluated
FALSEnever evaluated
0
50 fatal("%s: %s", __func__, ssh_err(r));
never executed: fatal("%s: %s", __func__, ssh_err(r));
0
51}
never executed: end of block
0
52-
53void-
54ssh_packet_put_string(struct ssh *ssh, const void *buf, u_int len)-
55{-
56 int r;-
57-
58 if ((r = sshpkt_put_string(ssh, buf, len)) != 0)
(r = sshpkt_pu...uf, len)) != 0Description
TRUEnever evaluated
FALSEnever evaluated
0
59 fatal("%s: %s", __func__, ssh_err(r));
never executed: fatal("%s: %s", __func__, ssh_err(r));
0
60}
never executed: end of block
0
61-
62void-
63ssh_packet_put_cstring(struct ssh *ssh, const char *str)-
64{-
65 int r;-
66-
67 if ((r = sshpkt_put_cstring(ssh, str)) != 0)
(r = sshpkt_pu...sh, str)) != 0Description
TRUEnever evaluated
FALSEnever evaluated
0
68 fatal("%s: %s", __func__, ssh_err(r));
never executed: fatal("%s: %s", __func__, ssh_err(r));
0
69}
never executed: end of block
0
70-
71void-
72ssh_packet_put_raw(struct ssh *ssh, const void *buf, u_int len)-
73{-
74 int r;-
75-
76 if ((r = sshpkt_put(ssh, buf, len)) != 0)
(r = sshpkt_pu...uf, len)) != 0Description
TRUEnever evaluated
FALSEnever evaluated
0
77 fatal("%s: %s", __func__, ssh_err(r));
never executed: fatal("%s: %s", __func__, ssh_err(r));
0
78}
never executed: end of block
0
79-
80-
81#ifdef WITH_OPENSSL-
82void-
83ssh_packet_put_bignum2(struct ssh *ssh, BIGNUM * value)-
84{-
85 int r;-
86-
87 if ((r = sshpkt_put_bignum2(ssh, value)) != 0)
(r = sshpkt_pu..., value)) != 0Description
TRUEnever evaluated
FALSEnever evaluated
0
88 fatal("%s: %s", __func__, ssh_err(r));
never executed: fatal("%s: %s", __func__, ssh_err(r));
0
89}
never executed: end of block
0
90-
91# ifdef OPENSSL_HAS_ECC-
92void-
93ssh_packet_put_ecpoint(struct ssh *ssh, const EC_GROUP *curve,-
94 const EC_POINT *point)-
95{-
96 int r;-
97-
98 if ((r = sshpkt_put_ec(ssh, point, curve)) != 0)
(r = sshpkt_pu..., curve)) != 0Description
TRUEnever evaluated
FALSEnever evaluated
0
99 fatal("%s: %s", __func__, ssh_err(r));
never executed: fatal("%s: %s", __func__, ssh_err(r));
0
100}
never executed: end of block
0
101# endif-
102#endif /* WITH_OPENSSL */-
103-
104void-
105ssh_packet_send(struct ssh *ssh)-
106{-
107 int r;-
108-
109 if ((r = sshpkt_send(ssh)) != 0)
(r = sshpkt_send(ssh)) != 0Description
TRUEnever evaluated
FALSEnever evaluated
0
110 fatal("%s: %s", __func__, ssh_err(r));
never executed: fatal("%s: %s", __func__, ssh_err(r));
0
111}
never executed: end of block
0
112-
113u_int-
114ssh_packet_get_char(struct ssh *ssh)-
115{-
116 u_char ch;-
117 int r;-
118-
119 if ((r = sshpkt_get_u8(ssh, &ch)) != 0)
(r = sshpkt_ge...sh, &ch)) != 0Description
TRUEnever evaluated
FALSEnever evaluated
0
120 fatal("%s: %s", __func__, ssh_err(r));
never executed: fatal("%s: %s", __func__, ssh_err(r));
0
121 return ch;
never executed: return ch;
0
122}-
123-
124u_int-
125ssh_packet_get_int(struct ssh *ssh)-
126{-
127 u_int val;-
128 int r;-
129-
130 if ((r = sshpkt_get_u32(ssh, &val)) != 0)
(r = sshpkt_ge...h, &val)) != 0Description
TRUEnever evaluated
FALSEnever evaluated
0
131 fatal("%s: %s", __func__, ssh_err(r));
never executed: fatal("%s: %s", __func__, ssh_err(r));
0
132 return val;
never executed: return val;
0
133}-
134-
135u_int64_t-
136ssh_packet_get_int64(struct ssh *ssh)-
137{-
138 u_int64_t val;-
139 int r;-
140-
141 if ((r = sshpkt_get_u64(ssh, &val)) != 0)
(r = sshpkt_ge...h, &val)) != 0Description
TRUEnever evaluated
FALSEnever evaluated
0
142 fatal("%s: %s", __func__, ssh_err(r));
never executed: fatal("%s: %s", __func__, ssh_err(r));
0
143 return val;
never executed: return val;
0
144}-
145-
146-
147#ifdef WITH_OPENSSL-
148void-
149ssh_packet_get_bignum2(struct ssh *ssh, BIGNUM * value)-
150{-
151 int r;-
152-
153 if ((r = sshpkt_get_bignum2(ssh, value)) != 0)
(r = sshpkt_ge..., value)) != 0Description
TRUEnever evaluated
FALSEnever evaluated
0
154 fatal("%s: %s", __func__, ssh_err(r));
never executed: fatal("%s: %s", __func__, ssh_err(r));
0
155}
never executed: end of block
0
156-
157# ifdef OPENSSL_HAS_ECC-
158void-
159ssh_packet_get_ecpoint(struct ssh *ssh, const EC_GROUP *curve, EC_POINT *point)-
160{-
161 int r;-
162-
163 if ((r = sshpkt_get_ec(ssh, point, curve)) != 0)
(r = sshpkt_ge..., curve)) != 0Description
TRUEnever evaluated
FALSEnever evaluated
0
164 fatal("%s: %s", __func__, ssh_err(r));
never executed: fatal("%s: %s", __func__, ssh_err(r));
0
165}
never executed: end of block
0
166# endif-
167#endif /* WITH_OPENSSL */-
168-
169void *-
170ssh_packet_get_string(struct ssh *ssh, u_int *length_ptr)-
171{-
172 int r;-
173 size_t len;-
174 u_char *val;-
175-
176 if ((r = sshpkt_get_string(ssh, &val, &len)) != 0)
(r = sshpkt_ge...l, &len)) != 0Description
TRUEnever evaluated
FALSEnever evaluated
0
177 fatal("%s: %s", __func__, ssh_err(r));
never executed: fatal("%s: %s", __func__, ssh_err(r));
0
178 if (length_ptr != NULL)
length_ptr != ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
179 *length_ptr = (u_int)len;
never executed: *length_ptr = (u_int)len;
0
180 return val;
never executed: return val;
0
181}-
182-
183const void *-
184ssh_packet_get_string_ptr(struct ssh *ssh, u_int *length_ptr)-
185{-
186 int r;-
187 size_t len;-
188 const u_char *val;-
189-
190 if ((r = sshpkt_get_string_direct(ssh, &val, &len)) != 0)
(r = sshpkt_ge...l, &len)) != 0Description
TRUEnever evaluated
FALSEnever evaluated
0
191 fatal("%s: %s", __func__, ssh_err(r));
never executed: fatal("%s: %s", __func__, ssh_err(r));
0
192 if (length_ptr != NULL)
length_ptr != ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
193 *length_ptr = (u_int)len;
never executed: *length_ptr = (u_int)len;
0
194 return val;
never executed: return val;
0
195}-
196-
197char *-
198ssh_packet_get_cstring(struct ssh *ssh, u_int *length_ptr)-
199{-
200 int r;-
201 size_t len;-
202 char *val;-
203-
204 if ((r = sshpkt_get_cstring(ssh, &val, &len)) != 0)
(r = sshpkt_ge...l, &len)) != 0Description
TRUEnever evaluated
FALSEnever evaluated
0
205 fatal("%s: %s", __func__, ssh_err(r));
never executed: fatal("%s: %s", __func__, ssh_err(r));
0
206 if (length_ptr != NULL)
length_ptr != ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
207 *length_ptr = (u_int)len;
never executed: *length_ptr = (u_int)len;
0
208 return val;
never executed: return val;
0
209}-
210-
211/* Old API, that had to be reimplemented */-
212-
213void-
214packet_set_connection(int fd_in, int fd_out)-
215{-
216 active_state = ssh_packet_set_connection(active_state, fd_in, fd_out);-
217 if (active_state == NULL)
active_state == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
218 fatal("%s: ssh_packet_set_connection failed", __func__);
never executed: fatal("%s: ssh_packet_set_connection failed", __func__);
0
219}
never executed: end of block
0
220-
221u_int-
222packet_get_char(void)-
223{-
224 return (ssh_packet_get_char(active_state));
never executed: return (ssh_packet_get_char(active_state));
0
225}-
226-
227u_int-
228packet_get_int(void)-
229{-
230 return (ssh_packet_get_int(active_state));
never executed: return (ssh_packet_get_int(active_state));
0
231}-
232-
233int-
234packet_read_seqnr(u_int32_t *seqnr)-
235{-
236 u_char type;-
237 int r;-
238-
239 if ((r = ssh_packet_read_seqnr(active_state, &type, seqnr)) != 0)
(r = ssh_packe..., seqnr)) != 0Description
TRUEnever evaluated
FALSEnever evaluated
0
240 sshpkt_fatal(active_state, __func__, r);
never executed: sshpkt_fatal(active_state, __func__, r);
0
241 return type;
never executed: return type;
0
242}-
243-
244int-
245packet_read_poll_seqnr(u_int32_t *seqnr)-
246{-
247 u_char type;-
248 int r;-
249-
250 if ((r = ssh_packet_read_poll_seqnr(active_state, &type, seqnr)))
(r = ssh_packe...&type, seqnr))Description
TRUEnever evaluated
FALSEnever evaluated
0
251 sshpkt_fatal(active_state, __func__, r);
never executed: sshpkt_fatal(active_state, __func__, r);
0
252 return type;
never executed: return type;
0
253}-
254-
255void-
256packet_close(void)-
257{-
258 ssh_packet_close(active_state);-
259 active_state = NULL;-
260}
never executed: end of block
0
261-
262void-
263packet_process_incoming(const char *buf, u_int len)-
264{-
265 int r;-
266-
267 if ((r = ssh_packet_process_incoming(active_state, buf, len)) != 0)
(r = ssh_packe...uf, len)) != 0Description
TRUEnever evaluated
FALSEnever evaluated
0
268 sshpkt_fatal(active_state, __func__, r);
never executed: sshpkt_fatal(active_state, __func__, r);
0
269}
never executed: end of block
0
270-
271void-
272packet_write_wait(void)-
273{-
274 int r;-
275-
276 if ((r = ssh_packet_write_wait(active_state)) != 0)
(r = ssh_packe...e_state)) != 0Description
TRUEnever evaluated
FALSEnever evaluated
0
277 sshpkt_fatal(active_state, __func__, r);
never executed: sshpkt_fatal(active_state, __func__, r);
0
278}
never executed: end of block
0
279-
280void-
281packet_write_poll(void)-
282{-
283 int r;-
284-
285 if ((r = ssh_packet_write_poll(active_state)) != 0)
(r = ssh_packe...e_state)) != 0Description
TRUEnever evaluated
FALSEnever evaluated
0
286 sshpkt_fatal(active_state, __func__, r);
never executed: sshpkt_fatal(active_state, __func__, r);
0
287}
never executed: end of block
0
288-
289void-
290packet_read_expect(int expected_type)-
291{-
292 int r;-
293-
294 if ((r = ssh_packet_read_expect(active_state, expected_type)) != 0)
(r = ssh_packe...ed_type)) != 0Description
TRUEnever evaluated
FALSEnever evaluated
0
295 sshpkt_fatal(active_state, __func__, r);
never executed: sshpkt_fatal(active_state, __func__, r);
0
296}
never executed: end of block
0
297-
298void-
299packet_disconnect(const char *fmt, ...)-
300{-
301 char buf[1024];-
302 va_list args;-
303-
304 va_start(args, fmt);-
305 vsnprintf(buf, sizeof(buf), fmt, args);-
306 va_end(args);-
307 ssh_packet_disconnect(active_state, "%s", buf);-
308}
never executed: end of block
0
309-
310void-
311packet_send_debug(const char *fmt, ...)-
312{-
313 char buf[1024];-
314 va_list args;-
315-
316 va_start(args, fmt);-
317 vsnprintf(buf, sizeof(buf), fmt, args);-
318 va_end(args);-
319 ssh_packet_send_debug(active_state, "%s", buf);-
320}
never executed: end of block
0
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.2.2