Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/libressl/src/tls/tls_bio_cb.c |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||
2 | - | |||||||||||||
3 | - | |||||||||||||
4 | static int bio_cb_write(BIO *bio, const char *buf, int num); | - | ||||||||||||
5 | static int bio_cb_read(BIO *bio, char *buf, int size); | - | ||||||||||||
6 | static int bio_cb_puts(BIO *bio, const char *str); | - | ||||||||||||
7 | static long bio_cb_ctrl(BIO *bio, int cmd, long num, void *ptr); | - | ||||||||||||
8 | - | |||||||||||||
9 | static BIO_METHOD bio_cb_method = { | - | ||||||||||||
10 | .type = (1|0x0400), | - | ||||||||||||
11 | .name = "libtls_callbacks", | - | ||||||||||||
12 | .bwrite = bio_cb_write, | - | ||||||||||||
13 | .bread = bio_cb_read, | - | ||||||||||||
14 | .bputs = bio_cb_puts, | - | ||||||||||||
15 | .ctrl = bio_cb_ctrl, | - | ||||||||||||
16 | }; | - | ||||||||||||
17 | - | |||||||||||||
18 | static BIO_METHOD * | - | ||||||||||||
19 | bio_s_cb(void) | - | ||||||||||||
20 | { | - | ||||||||||||
21 | return executed 4 times by 1 test: (&bio_cb_method);return (&bio_cb_method); Executed by:
executed 4 times by 1 test: return (&bio_cb_method); Executed by:
| 4 | ||||||||||||
22 | } | - | ||||||||||||
23 | - | |||||||||||||
24 | static int | - | ||||||||||||
25 | bio_cb_puts(BIO *bio, const char *str) | - | ||||||||||||
26 | { | - | ||||||||||||
27 | return never executed: (bio_cb_write(bio, str, strlen(str)));return (bio_cb_write(bio, str, strlen(str))); never executed: return (bio_cb_write(bio, str, strlen(str))); | 0 | ||||||||||||
28 | } | - | ||||||||||||
29 | - | |||||||||||||
30 | static long | - | ||||||||||||
31 | bio_cb_ctrl(BIO *bio, int cmd, long num, void *ptr) | - | ||||||||||||
32 | { | - | ||||||||||||
33 | long ret = 1; | - | ||||||||||||
34 | - | |||||||||||||
35 | switch (cmd) { | - | ||||||||||||
36 | case never executed: 8:case 8: never executed: case 8: | 0 | ||||||||||||
37 | ret = (long)bio->shutdown; | - | ||||||||||||
38 | break; never executed: break; | 0 | ||||||||||||
39 | case never executed: 9:case 9: never executed: case 9: | 0 | ||||||||||||
40 | bio->shutdown = (int)num; | - | ||||||||||||
41 | break; never executed: break; | 0 | ||||||||||||
42 | case never executed: 12:case 12: never executed: case 12: | 0 | ||||||||||||
43 | case executed 6 times by 1 test: 11:case 11: Executed by:
executed 6 times by 1 test: case 11: Executed by:
| 6 | ||||||||||||
44 | break; executed 6 times by 1 test: break; Executed by:
| 6 | ||||||||||||
45 | case never executed: 3:case 3: never executed: case 3: | 0 | ||||||||||||
46 | case never executed: 5:case 5: never executed: case 5: | 0 | ||||||||||||
47 | case never executed: 4:case 4: never executed: case 4: | 0 | ||||||||||||
48 | default executed 8 times by 1 test: :default: Executed by:
executed 8 times by 1 test: default: Executed by:
| 8 | ||||||||||||
49 | ret = BIO_ctrl(bio->next_bio, cmd, num, ptr); | - | ||||||||||||
50 | } executed 8 times by 1 test: end of block Executed by:
| 8 | ||||||||||||
51 | - | |||||||||||||
52 | return executed 14 times by 1 test: (ret);return (ret); Executed by:
executed 14 times by 1 test: return (ret); Executed by:
| 14 | ||||||||||||
53 | } | - | ||||||||||||
54 | - | |||||||||||||
55 | static int | - | ||||||||||||
56 | bio_cb_write(BIO *bio, const char *buf, int num) | - | ||||||||||||
57 | { | - | ||||||||||||
58 | struct tls *ctx = bio->ptr; | - | ||||||||||||
59 | int rv; | - | ||||||||||||
60 | - | |||||||||||||
61 | BIO_clear_flags(bio, ((0x01|0x02|0x04)|0x08)); | - | ||||||||||||
62 | rv = (ctx->write_cb)(ctx, buf, num, ctx->cb_arg); | - | ||||||||||||
63 | if (rv == -2
| 0-20 | ||||||||||||
64 | BIO_set_flags(bio, (0x01|0x08)); | - | ||||||||||||
65 | rv = -1; | - | ||||||||||||
66 | } never executed: else if (rv == -3end of block
| 0-16 | ||||||||||||
67 | BIO_set_flags(bio, (0x02|0x08)); | - | ||||||||||||
68 | rv = -1; | - | ||||||||||||
69 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||
70 | return executed 20 times by 1 test: (rv);return (rv); Executed by:
executed 20 times by 1 test: return (rv); Executed by:
| 20 | ||||||||||||
71 | } | - | ||||||||||||
72 | - | |||||||||||||
73 | static int | - | ||||||||||||
74 | bio_cb_read(BIO *bio, char *buf, int size) | - | ||||||||||||
75 | { | - | ||||||||||||
76 | struct tls *ctx = bio->ptr; | - | ||||||||||||
77 | int rv; | - | ||||||||||||
78 | - | |||||||||||||
79 | BIO_clear_flags(bio, ((0x01|0x02|0x04)|0x08)); | - | ||||||||||||
80 | rv = (ctx->read_cb)(ctx, buf, size, ctx->cb_arg); | - | ||||||||||||
81 | if (rv == -2
| 10-44 | ||||||||||||
82 | BIO_set_flags(bio, (0x01|0x08)); | - | ||||||||||||
83 | rv = -1; | - | ||||||||||||
84 | } executed 10 times by 1 test: else if (rv == -3end of block Executed by:
| 0-44 | ||||||||||||
85 | BIO_set_flags(bio, (0x02|0x08)); | - | ||||||||||||
86 | rv = -1; | - | ||||||||||||
87 | } never executed: end of block | 0 | ||||||||||||
88 | return executed 54 times by 1 test: (rv);return (rv); Executed by:
executed 54 times by 1 test: return (rv); Executed by:
| 54 | ||||||||||||
89 | } | - | ||||||||||||
90 | - | |||||||||||||
91 | int | - | ||||||||||||
92 | tls_set_cbs(struct tls *ctx, tls_read_cb read_cb, tls_write_cb write_cb, | - | ||||||||||||
93 | void *cb_arg) | - | ||||||||||||
94 | { | - | ||||||||||||
95 | int rv = -1; | - | ||||||||||||
96 | BIO *bio; | - | ||||||||||||
97 | - | |||||||||||||
98 | if (read_cb ==
| 0-4 | ||||||||||||
99 | ((void *)0)
| 0-4 | ||||||||||||
100 | || write_cb ==
| 0-4 | ||||||||||||
101 | ((void *)0)
| 0-4 | ||||||||||||
102 | ) { | - | ||||||||||||
103 | tls_set_errorx(ctx, "no callbacks provided"); | - | ||||||||||||
104 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
105 | } | - | ||||||||||||
106 | - | |||||||||||||
107 | ctx->read_cb = read_cb; | - | ||||||||||||
108 | ctx->write_cb = write_cb; | - | ||||||||||||
109 | ctx->cb_arg = cb_arg; | - | ||||||||||||
110 | - | |||||||||||||
111 | if ((
| 0-4 | ||||||||||||
112 | ((void *)0)
| 0-4 | ||||||||||||
113 | ) { | - | ||||||||||||
114 | tls_set_errorx(ctx, "failed to create callback i/o"); | - | ||||||||||||
115 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||||||||
116 | } | - | ||||||||||||
117 | bio->ptr = ctx; | - | ||||||||||||
118 | bio->init = 1; | - | ||||||||||||
119 | - | |||||||||||||
120 | SSL_set_bio(ctx->ssl_conn, bio, bio); | - | ||||||||||||
121 | - | |||||||||||||
122 | rv = 0; | - | ||||||||||||
123 | - | |||||||||||||
124 | err: code before this statement executed 4 times by 1 test: err: Executed by:
| 4 | ||||||||||||
125 | return executed 4 times by 1 test: (rv);return (rv); Executed by:
executed 4 times by 1 test: return (rv); Executed by:
| 4 | ||||||||||||
126 | } | - | ||||||||||||
Switch to Source code | Preprocessed file |