OpenCoverage

dispatch.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/openssh/src/dispatch.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/* $OpenBSD: dispatch.c,v 1.31 2017/05/31 07:00:13 markus Exp $ */-
2/*-
3 * Copyright (c) 2000 Markus Friedl. All rights reserved.-
4 *-
5 * Redistribution and use in source and binary forms, with or without-
6 * modification, are permitted provided that the following conditions-
7 * are met:-
8 * 1. Redistributions of source code must retain the above copyright-
9 * notice, this list of conditions and the following disclaimer.-
10 * 2. Redistributions in binary form must reproduce the above copyright-
11 * notice, this list of conditions and the following disclaimer in the-
12 * documentation and/or other materials provided with the distribution.-
13 *-
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR-
15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES-
16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.-
17 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,-
18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT-
19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,-
20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY-
21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT-
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF-
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.-
24 */-
25-
26#include "includes.h"-
27-
28#include <sys/types.h>-
29-
30#include <signal.h>-
31#include <stdarg.h>-
32-
33#include "ssh2.h"-
34#include "log.h"-
35#include "dispatch.h"-
36#include "packet.h"-
37#include "compat.h"-
38#include "ssherr.h"-
39-
40int-
41dispatch_protocol_error(int type, u_int32_t seq, struct ssh *ssh)-
42{-
43 int r;-
44-
45 logit("dispatch_protocol_error: type %d seq %u", type, seq);-
46 if ((r = sshpkt_start(ssh, SSH2_MSG_UNIMPLEMENTED)) != 0 ||
(r = sshpkt_st...(ssh, 3)) != 0Description
TRUEnever evaluated
FALSEnever evaluated
0
47 (r = sshpkt_put_u32(ssh, seq)) != 0 ||
(r = sshpkt_pu...sh, seq)) != 0Description
TRUEnever evaluated
FALSEnever evaluated
0
48 (r = sshpkt_send(ssh)) != 0 ||
(r = sshpkt_send(ssh)) != 0Description
TRUEnever evaluated
FALSEnever evaluated
0
49 (r = ssh_packet_write_wait(ssh)) != 0)
(r = ssh_packe...ait(ssh)) != 0Description
TRUEnever evaluated
FALSEnever evaluated
0
50 sshpkt_fatal(ssh, __func__, r);
never executed: sshpkt_fatal(ssh, __func__, r);
0
51 return 0;
never executed: return 0;
0
52}-
53-
54int-
55dispatch_protocol_ignore(int type, u_int32_t seq, struct ssh *ssh)-
56{-
57 logit("dispatch_protocol_ignore: type %d seq %u", type, seq);-
58 return 0;
never executed: return 0;
0
59}-
60-
61void-
62ssh_dispatch_init(struct ssh *ssh, dispatch_fn *dflt)-
63{-
64 u_int i;-
65 for (i = 0; i < DISPATCH_MAX; i++)
i < 255Description
TRUEnever evaluated
FALSEnever evaluated
0
66 ssh->dispatch[i] = dflt;
never executed: ssh->dispatch[i] = dflt;
0
67}
never executed: end of block
0
68-
69void-
70ssh_dispatch_range(struct ssh *ssh, u_int from, u_int to, dispatch_fn *fn)-
71{-
72 u_int i;-
73-
74 for (i = from; i <= to; i++) {
i <= toDescription
TRUEevaluated 20384 times by 1 test
Evaluated by:
  • test_kex
FALSEevaluated 416 times by 1 test
Evaluated by:
  • test_kex
416-20384
75 if (i >= DISPATCH_MAX)
i >= 255Description
TRUEnever evaluated
FALSEevaluated 20384 times by 1 test
Evaluated by:
  • test_kex
0-20384
76 break;
never executed: break;
0
77 ssh->dispatch[i] = fn;-
78 }
executed 20384 times by 1 test: end of block
Executed by:
  • test_kex
20384
79}
executed 416 times by 1 test: end of block
Executed by:
  • test_kex
416
80-
81void-
82ssh_dispatch_set(struct ssh *ssh, int type, dispatch_fn *fn)-
83{-
84 ssh->dispatch[type] = fn;-
85}
executed 1816 times by 1 test: end of block
Executed by:
  • test_kex
1816
86-
87int-
88ssh_dispatch_run(struct ssh *ssh, int mode, volatile sig_atomic_t *done)-
89{-
90 int r;-
91 u_char type;-
92 u_int32_t seqnr;-
93-
94 for (;;) {-
95 if (mode == DISPATCH_BLOCK) {
mode == DISPATCH_BLOCKDescription
TRUEnever evaluated
FALSEnever evaluated
0
96 r = ssh_packet_read_seqnr(ssh, &type, &seqnr);-
97 if (r != 0)
r != 0Description
TRUEnever evaluated
FALSEnever evaluated
0
98 return r;
never executed: return r;
0
99 } else {
never executed: end of block
0
100 r = ssh_packet_read_poll_seqnr(ssh, &type, &seqnr);-
101 if (r != 0)
r != 0Description
TRUEnever evaluated
FALSEnever evaluated
0
102 return r;
never executed: return r;
0
103 if (type == SSH_MSG_NONE)
type == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
104 return 0;
never executed: return 0;
0
105 }
never executed: end of block
0
106 if (type > 0 && type < DISPATCH_MAX &&
type > 0Description
TRUEnever evaluated
FALSEnever evaluated
type < 255Description
TRUEnever evaluated
FALSEnever evaluated
0
107 ssh->dispatch[type] != NULL) {
ssh->dispatch[...!= ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
108 if (ssh->dispatch_skip_packets) {
ssh->dispatch_skip_packetsDescription
TRUEnever evaluated
FALSEnever evaluated
0
109 debug2("skipped packet (type %u)", type);-
110 ssh->dispatch_skip_packets--;-
111 continue;
never executed: continue;
0
112 }-
113 r = (*ssh->dispatch[type])(type, seqnr, ssh);-
114 if (r != 0)
r != 0Description
TRUEnever evaluated
FALSEnever evaluated
0
115 return r;
never executed: return r;
0
116 } else {
never executed: end of block
0
117 r = sshpkt_disconnect(ssh,-
118 "protocol error: rcvd type %d", type);-
119 if (r != 0)
r != 0Description
TRUEnever evaluated
FALSEnever evaluated
0
120 return r;
never executed: return r;
0
121 return SSH_ERR_DISCONNECTED;
never executed: return -29;
0
122 }-
123 if (done != NULL && *done)
done != ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
*doneDescription
TRUEnever evaluated
FALSEnever evaluated
0
124 return 0;
never executed: return 0;
0
125 }
never executed: end of block
0
126}
never executed: end of block
0
127-
128void-
129ssh_dispatch_run_fatal(struct ssh *ssh, int mode, volatile sig_atomic_t *done)-
130{-
131 int r;-
132-
133 if ((r = ssh_dispatch_run(ssh, mode, done)) != 0)
(r = ssh_dispa...e, done)) != 0Description
TRUEnever evaluated
FALSEnever evaluated
0
134 sshpkt_fatal(ssh, __func__, r);
never executed: sshpkt_fatal(ssh, __func__, r);
0
135}
never executed: end of block
0
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.2.2