| 1 |
|
| /* ClamAV::Clamd |
| 2 |
|
| * |
| 3 |
|
| * The .xs lives at the top level, not under lib/. A single-XS dist with |
| 4 |
|
| * its source under lib/ makes lib/Clamd.def while dlltool goes looking |
| 5 |
|
| * for $(BASEEXT).def, and that is somebody else's three releases of |
| 6 |
|
| * Win32 scar tissue already paid for. |
| 7 |
|
| */ |
| 8 |
|
| #define PERL_NO_GET_CONTEXT |
| 9 |
|
| /* The C core under include/clamav is plain C with no interpreter to |
| 10 |
|
| * hand. On a PERL_IMPLICIT_SYS perl - every Strawberry - XSUB.h rewrites |
| 11 |
|
| * malloc, free, send, socket, read and the rest into macros that |
| 12 |
|
| * dereference my_perl; this is the switch it provides to not do that. |
| 13 |
|
| * Nothing here hands a libc pointer to perl's allocator or takes one. */ |
| 14 |
|
| #define NO_XSLOCKS |
| 15 |
|
| #include "EXTERN.h" |
| 16 |
|
| #include "perl.h" |
| 17 |
|
| #include "XSUB.h" |
| 18 |
|
| |
| 19 |
|
| #include "clamav/clamd_conn.h" |
| 20 |
|
| #include "clamav/clamd_scan.h" |
| 21 |
|
| #include "clamav/clamd_verdict.h" |
| 22 |
|
| #include "clamav/clamd_abi_impl.h" |
| 23 |
|
| |
| 24 |
|
| #define CC_DEF_PORT 3310 |
| 25 |
|
| #define CC_DEF_CONNECT_TIMEOUT 5.0 |
| 26 |
|
| #define CC_DEF_REPLY_TIMEOUT 30.0 |
| 27 |
|
| #define CC_DEF_REPLY_MAX (1024 * 1024) |
| 28 |
|
| |
| 29 |
261 |
| static HV *cc_self_hv(pTHX_ SV *self, const char *who) { |
| 30 |
261 |
▶ | if (!SvROK(self) || SvTYPE(SvRV(self)) != SVt_PVHV) |
Branch: 2 branches
| Branch | True | False | Total |
| if (!SvROK(self) || SvTYPE(SvRV(self)) != SVt_PVHV) |
250 |
11 |
261 |
| if (!SvROK(self) || SvTYPE(SvRV(self)) != SVt_PVHV) |
11 |
239 |
250 |
|
| 31 |
22 |
| croak("ClamAV::Clamd::%s: not a ClamAV::Clamd object", who); |
| 32 |
239 |
| return (HV *)SvRV(self); |
| 33 |
|
| } |
| 34 |
|
| |
| 35 |
|
| /* Pull the target out of the object. The defaults live here as well as |
| 36 |
|
| * in the constructor, so the C side stays usable on a hash that did not |
| 37 |
|
| * come through new(). */ |
| 38 |
158 |
| static void cc_target_from_hv(pTHX_ HV *self, cc_target *t) { |
| 39 |
|
| SV **sv; |
| 40 |
|
| |
| 41 |
158 |
| memset(t, 0, sizeof *t); |
| 42 |
158 |
| t->connect_timeout = CC_DEF_CONNECT_TIMEOUT; |
| 43 |
158 |
| t->reply_timeout = CC_DEF_REPLY_TIMEOUT; |
| 44 |
158 |
| t->reply_max = CC_DEF_REPLY_MAX; |
| 45 |
158 |
| t->frame = CC_FRAME_Z; |
| 46 |
158 |
| t->port = CC_DEF_PORT; |
| 47 |
|
| |
| 48 |
158 |
▶ | if ((sv = hv_fetchs(self, "socket", 0)) && SvOK(*sv)) |
Branch: 2 branches
| Branch | True | False | Total |
| if ((sv = hv_fetchs(self, "socket", 0)) && SvOK(*sv)) |
140 |
18 |
158 |
| if ((sv = hv_fetchs(self, "socket", 0)) && SvOK(*sv)) |
139 |
1 |
140 |
|
| 49 |
278 |
| t->path = SvPV_nolen(*sv); |
| 50 |
158 |
▶ | if ((sv = hv_fetchs(self, "host", 0)) && SvOK(*sv)) |
Branch: 2 branches
| Branch | True | False | Total |
| if ((sv = hv_fetchs(self, "host", 0)) && SvOK(*sv)) |
19 |
139 |
158 |
| if ((sv = hv_fetchs(self, "host", 0)) && SvOK(*sv)) |
18 |
1 |
19 |
|
| 51 |
36 |
| t->host = SvPV_nolen(*sv); |
| 52 |
158 |
▶ | if ((sv = hv_fetchs(self, "port", 0)) && SvOK(*sv)) |
Branch: 2 branches
| Branch | True | False | Total |
| if ((sv = hv_fetchs(self, "port", 0)) && SvOK(*sv)) |
153 |
5 |
158 |
| if ((sv = hv_fetchs(self, "port", 0)) && SvOK(*sv)) |
152 |
1 |
153 |
|
| 53 |
152 |
| t->port = (int)SvIV(*sv); |
| 54 |
158 |
▶ | if ((sv = hv_fetchs(self, "connect_timeout", 0)) && SvOK(*sv)) |
Branch: 2 branches
| Branch | True | False | Total |
| if ((sv = hv_fetchs(self, "connect_timeout", 0)) && SvOK(*sv)) |
152 |
6 |
158 |
| if ((sv = hv_fetchs(self, "connect_timeout", 0)) && SvOK(*sv)) |
151 |
1 |
152 |
|
| 55 |
151 |
| t->connect_timeout = SvNV(*sv); |
| 56 |
158 |
▶ | if ((sv = hv_fetchs(self, "reply_timeout", 0)) && SvOK(*sv)) |
Branch: 2 branches
| Branch | True | False | Total |
| if ((sv = hv_fetchs(self, "reply_timeout", 0)) && SvOK(*sv)) |
154 |
4 |
158 |
| if ((sv = hv_fetchs(self, "reply_timeout", 0)) && SvOK(*sv)) |
153 |
1 |
154 |
|
| 57 |
153 |
| t->reply_timeout = SvNV(*sv); |
| 58 |
158 |
▶ | if ((sv = hv_fetchs(self, "reply_max", 0)) && SvOK(*sv)) |
Branch: 2 branches
| Branch | True | False | Total |
| if ((sv = hv_fetchs(self, "reply_max", 0)) && SvOK(*sv)) |
154 |
4 |
158 |
| if ((sv = hv_fetchs(self, "reply_max", 0)) && SvOK(*sv)) |
153 |
1 |
154 |
|
| 59 |
153 |
| t->reply_max = (size_t)SvUV(*sv); |
| 60 |
158 |
▶ | if ((sv = hv_fetchs(self, "chunk", 0)) && SvOK(*sv)) |
Branch: 2 branches
| Branch | True | False | Total |
| if ((sv = hv_fetchs(self, "chunk", 0)) && SvOK(*sv)) |
17 |
141 |
158 |
| if ((sv = hv_fetchs(self, "chunk", 0)) && SvOK(*sv)) |
16 |
1 |
17 |
|
| 61 |
16 |
| t->chunk = (size_t)SvUV(*sv); |
| 62 |
158 |
▶ | if ((sv = hv_fetchs(self, "max_size", 0)) && SvOK(*sv)) |
Branch: 2 branches
| Branch | True | False | Total |
| if ((sv = hv_fetchs(self, "max_size", 0)) && SvOK(*sv)) |
7 |
151 |
158 |
| if ((sv = hv_fetchs(self, "max_size", 0)) && SvOK(*sv)) |
6 |
1 |
7 |
|
| 63 |
6 |
| t->max_size = (size_t)SvUV(*sv); |
| 64 |
158 |
▶ | if ((sv = hv_fetchs(self, "frame", 0)) && SvOK(*sv)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if ((sv = hv_fetchs(self, "frame", 0)) && SvOK(*sv)) { |
152 |
6 |
158 |
| if ((sv = hv_fetchs(self, "frame", 0)) && SvOK(*sv)) { |
151 |
1 |
152 |
|
| 65 |
151 |
| const char *f = SvPV_nolen(*sv); |
| 66 |
151 |
| t->frame = (*f == 'n') ? CC_FRAME_N : CC_FRAME_Z; |
| 67 |
|
| } |
| 68 |
158 |
| } |
| 69 |
|
| |
| 70 |
165 |
| static void cc_clear_error(pTHX_ HV *self) { |
| 71 |
165 |
| (void)hv_delete(self, "error", 5, G_DISCARD); |
| 72 |
165 |
| (void)hv_delete(self, "error_code", 10, G_DISCARD); |
| 73 |
165 |
| } |
| 74 |
|
| |
| 75 |
65 |
| static void cc_set_error(pTHX_ HV *self, int code, const char *msg) { |
| 76 |
65 |
| (void)hv_stores(self, "error_code", newSViv(code)); |
| 77 |
65 |
| (void)hv_stores(self, "error", newSVpv(msg, 0)); |
| 78 |
65 |
| } |
| 79 |
|
| |
| 80 |
|
| /* One command, one connection. Returns a mortal SV holding the reply, or |
| 81 |
|
| * NULL with error/error_code set on the object. |
| 82 |
|
| * |
| 83 |
|
| * Nothing operational croaks: a clamd that went away mid-request is a |
| 84 |
|
| * condition the caller handles, not a bug in their program. */ |
| 85 |
48 |
| static SV *cc_do_command(pTHX_ SV *self, const char *cmd, const char *who) { |
| 86 |
48 |
| HV *hv = cc_self_hv(aTHX_ self, who); |
| 87 |
|
| cc_target t; |
| 88 |
|
| cc_err err; |
| 89 |
40 |
| char *reply = NULL; |
| 90 |
40 |
| size_t len = 0; |
| 91 |
|
| int rc; |
| 92 |
|
| SV *out; |
| 93 |
|
| |
| 94 |
40 |
| cc_clear_error(aTHX_ hv); |
| 95 |
40 |
| cc_target_from_hv(aTHX_ hv, &t); |
| 96 |
|
| |
| 97 |
40 |
| memset(&err, 0, sizeof err); |
| 98 |
40 |
| rc = cc_roundtrip(&t, cmd, &reply, &len, &err); |
| 99 |
|
| |
| 100 |
40 |
▶ | if (rc != CC_OK) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (rc != CC_OK) { |
20 |
20 |
40 |
|
| 101 |
20 |
| cc_set_error(aTHX_ hv, rc, err.msg); |
| 102 |
20 |
| return NULL; |
| 103 |
|
| } |
| 104 |
|
| |
| 105 |
|
| /* ClamAV 1.5 lets clamd.conf switch commands off one by one |
| 106 |
|
| * (EnableVersionCommand no, EnableStatsCommand no, EnableReloadCommand |
| 107 |
|
| * no, ...) and answers a switched-off one with this exact line. It is a |
| 108 |
|
| * refusal, not a version string or a statistics block, and must not |
| 109 |
|
| * come back as one: a caller logging "COMMAND UNAVAILABLE" as the |
| 110 |
|
| * scanner version is wrong in a way it cannot detect. */ |
| 111 |
20 |
▶ | if (len == 19 && memcmp(reply, "COMMAND UNAVAILABLE", 19) == 0) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (len == 19 && memcmp(reply, "COMMAND UNAVAILABLE", 19) == 0) { |
4 |
16 |
20 |
| if (len == 19 && memcmp(reply, "COMMAND UNAVAILABLE", 19) == 0) { |
3 |
1 |
4 |
|
| 112 |
3 |
| SV *m = sv_2mortal(newSVpvf( |
| 113 |
|
| "clamd has %s disabled (clamd.conf Enable*Command no)", cmd)); |
| 114 |
3 |
| cc_set_error(aTHX_ hv, CC_ERR_UNAVAILABLE, SvPV_nolen(m)); |
| 115 |
3 |
| free(reply); |
| 116 |
3 |
| return NULL; |
| 117 |
|
| } |
| 118 |
|
| |
| 119 |
17 |
| out = sv_2mortal(newSVpvn(reply, len)); |
| 120 |
17 |
| free(reply); |
| 121 |
17 |
| return out; |
| 122 |
|
| } |
| 123 |
|
| |
| 124 |
|
| /* A command whose reply must be one exact word. Anything else is a |
| 125 |
|
| * protocol failure and must not read as success. */ |
| 126 |
38 |
| static SV *cc_do_exact(pTHX_ SV *self, const char *cmd, const char *want, |
| 127 |
|
| const char *who) { |
| 128 |
38 |
| SV *r = cc_do_command(aTHX_ self, cmd, who); |
| 129 |
34 |
▶ | if (!r) return NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!r) return NULL; |
21 |
13 |
34 |
|
| 130 |
|
| { |
| 131 |
|
| STRLEN l; |
| 132 |
13 |
| const char *p = SvPV(r, l); |
| 133 |
13 |
▶ | if (l == strlen(want) && memcmp(p, want, l) == 0) |
Branch: 2 branches
| Branch | True | False | Total |
| if (l == strlen(want) && memcmp(p, want, l) == 0) |
12 |
1 |
13 |
| if (l == strlen(want) && memcmp(p, want, l) == 0) |
11 |
1 |
12 |
|
| 134 |
11 |
| return r; |
| 135 |
|
| } |
| 136 |
|
| { |
| 137 |
2 |
| HV *hv = (HV *)SvRV(self); |
| 138 |
2 |
| SV *m = sv_2mortal(newSVpvf("unexpected reply to %s: %" SVf, cmd, SVfARG(r))); |
| 139 |
2 |
| cc_set_error(aTHX_ hv, CC_ERR_IO, SvPV_nolen(m)); |
| 140 |
|
| } |
| 141 |
2 |
| return NULL; |
| 142 |
|
| } |
| 143 |
|
| |
| 144 |
|
| /* Accept either a raw descriptor number or a Perl filehandle, because |
| 145 |
|
| * the caller who has a file open has a filehandle - Punk::Upload's fh |
| 146 |
|
| * among them - and making them dig out fileno() is a papercut with a |
| 147 |
|
| * wrong answer available (calling fileno on the wrong thing). */ |
| 148 |
18 |
| static int cc_fileno(pTHX_ SV *sv) { |
| 149 |
18 |
▶ | if (!SvOK(sv)) return -1; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!SvOK(sv)) return -1; |
1 |
17 |
18 |
|
| 150 |
|
| |
| 151 |
|
| /* sv_2io croaks on what is not a handle at all, and answers a closed |
| 152 |
|
| * one with no input stream. */ |
| 153 |
17 |
▶ | if (SvROK(sv) || SvTYPE(sv) == SVt_PVGV) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (SvROK(sv) || SvTYPE(sv) == SVt_PVGV) { |
9 |
8 |
17 |
| if (SvROK(sv) || SvTYPE(sv) == SVt_PVGV) { |
1 |
8 |
9 |
|
| 154 |
9 |
| IO *io = sv_2io(sv); |
| 155 |
9 |
▶ | if (IoIFP(io)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (IoIFP(io)) { |
8 |
1 |
9 |
|
| 156 |
8 |
| int fd = PerlIO_fileno(IoIFP(io)); |
| 157 |
8 |
| return fd < 0 ? -1 : fd; |
| 158 |
|
| } |
| 159 |
1 |
| return -1; |
| 160 |
|
| } |
| 161 |
8 |
▶ | if (SvIOK(sv) || looks_like_number(sv)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (SvIOK(sv) || looks_like_number(sv)) { |
4 |
4 |
8 |
| if (SvIOK(sv) || looks_like_number(sv)) { |
2 |
2 |
4 |
|
| 162 |
6 |
| IV v = SvIV(sv); |
| 163 |
6 |
▶ | return (v < 0 || v > 0x7fffffff) ? -1 : (int)v; |
Branch: 2 branches
| Branch | True | False | Total |
| return (v < 0 || v > 0x7fffffff) ? -1 : (int)v; |
5 |
1 |
6 |
| return (v < 0 || v > 0x7fffffff) ? -1 : (int)v; |
4 |
1 |
5 |
|
| 164 |
|
| } |
| 165 |
2 |
| return -1; |
| 166 |
|
| } |
| 167 |
|
| |
| 168 |
|
| /* Shared tail for the scan entry points. |
| 169 |
|
| * |
| 170 |
|
| * ALWAYS returns a verdict, including when the scan never reached clamd. |
| 171 |
|
| * Returning undef on a timeout would mean |
| 172 |
|
| * |
| 173 |
|
| * if ($clamd->scan($x)->is_clean) { ... } |
| 174 |
|
| * |
| 175 |
|
| * dies on the one path where it most matters. The safe reading has to be |
| 176 |
|
| * the short one, so every scan yields something is_clean() can be called |
| 177 |
|
| * on, and is_clean() is true for exactly one of the four states. |
| 178 |
|
| */ |
| 179 |
104 |
| static SV *cc_scan_result(pTHX_ HV *hv, int rc, char *reply, size_t len, |
| 180 |
|
| int transport, cc_err *err) { |
| 181 |
|
| cc_verdict v; |
| 182 |
|
| HV *vh; |
| 183 |
|
| SV *rv; |
| 184 |
|
| |
| 185 |
104 |
| (void)hv_stores(hv, "transport", newSViv(transport)); |
| 186 |
|
| |
| 187 |
104 |
▶ | if (rc == CC_OK) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (rc == CC_OK) { |
64 |
40 |
104 |
|
| 188 |
64 |
| cc_parse_reply(reply, len, &v); |
| 189 |
|
| } else { |
| 190 |
40 |
| cc_verdict_from_error(rc, &v); |
| 191 |
40 |
| cc_set_error(aTHX_ hv, rc, err->msg); |
| 192 |
|
| } |
| 193 |
|
| |
| 194 |
104 |
| vh = newHV(); |
| 195 |
104 |
| (void)hv_stores(vh, "state", newSVpv(cc_state_name(v.state), 0)); |
| 196 |
104 |
▶ | (void)hv_stores(vh, "signature", |
Branch: 1 branch
| Branch | True | False | Total |
| (void)hv_stores(vh, "signature", |
22 |
82 |
104 |
|
| 197 |
|
| v.signature[0] ? newSVpv(v.signature, 0) : newSV(0)); |
| 198 |
104 |
▶ | (void)hv_stores(vh, "reason", |
Branch: 1 branch
| Branch | True | False | Total |
| (void)hv_stores(vh, "reason", |
23 |
81 |
104 |
|
| 199 |
|
| v.reason[0] ? newSVpv(v.reason, 0) : newSV(0)); |
| 200 |
104 |
▶ | (void)hv_stores(vh, "transport", |
Branch: 2 branches
| Branch | True | False | Total |
| (void)hv_stores(vh, "transport", |
9 |
95 |
104 |
| (void)hv_stores(vh, "transport", |
76 |
19 |
95 |
|
| 201 |
|
| transport == CC_TRANSPORT_FILDES ? newSVpvs("fildes") : |
| 202 |
|
| transport == CC_TRANSPORT_INSTREAM ? newSVpvs("instream") : newSV(0)); |
| 203 |
104 |
▶ | (void)hv_stores(vh, "raw", |
Branch: 1 branch
| Branch | True | False | Total |
| (void)hv_stores(vh, "raw", |
64 |
40 |
104 |
|
| 204 |
|
| (rc == CC_OK) ? newSVpvn(reply, len) : newSV(0)); |
| 205 |
104 |
▶ | (void)hv_stores(vh, "error", |
Branch: 1 branch
| Branch | True | False | Total |
| (void)hv_stores(vh, "error", |
64 |
40 |
104 |
|
| 206 |
|
| (rc == CC_OK) ? newSV(0) : newSVpv(err->msg, 0)); |
| 207 |
|
| |
| 208 |
104 |
▶ | if (reply) free(reply); |
Branch: 1 branch
| Branch | True | False | Total |
| if (reply) free(reply); |
75 |
29 |
104 |
|
| 209 |
|
| |
| 210 |
104 |
| rv = newRV_noinc((SV *)vh); |
| 211 |
104 |
| (void)sv_bless(rv, gv_stashpvs("ClamAV::Clamd::Verdict", GV_ADD)); |
| 212 |
104 |
| return sv_2mortal(rv); |
| 213 |
|
| } |
| 214 |
|
| |
| 215 |
244 |
| static SV *cc_vfield(pTHX_ SV *self, const char *key, I32 klen) { |
| 216 |
|
| SV **sv; |
| 217 |
244 |
▶ | if (!SvROK(self) || SvTYPE(SvRV(self)) != SVt_PVHV) |
Branch: 2 branches
| Branch | True | False | Total |
| if (!SvROK(self) || SvTYPE(SvRV(self)) != SVt_PVHV) |
233 |
11 |
244 |
| if (!SvROK(self) || SvTYPE(SvRV(self)) != SVt_PVHV) |
10 |
223 |
233 |
|
| 218 |
21 |
| croak("ClamAV::Clamd::Verdict: not a verdict"); |
| 219 |
223 |
| sv = hv_fetch((HV *)SvRV(self), key, klen, 0); |
| 220 |
223 |
▶ | return (sv && SvOK(*sv)) ? *sv : NULL; |
Branch: 2 branches
| Branch | True | False | Total |
| return (sv && SvOK(*sv)) ? *sv : NULL; |
211 |
12 |
223 |
| return (sv && SvOK(*sv)) ? *sv : NULL; |
191 |
20 |
211 |
|
| 221 |
|
| } |
| 222 |
|
| |
| 223 |
10324 |
| static cc_scan *cc_scan_of(pTHX_ SV *self) { |
| 224 |
|
| SV **e; |
| 225 |
10324 |
▶ | if (!SvROK(self) || SvTYPE(SvRV(self)) != SVt_PVHV) |
Branch: 2 branches
| Branch | True | False | Total |
| if (!SvROK(self) || SvTYPE(SvRV(self)) != SVt_PVHV) |
10319 |
5 |
10324 |
| if (!SvROK(self) || SvTYPE(SvRV(self)) != SVt_PVHV) |
5 |
10314 |
10319 |
|
| 226 |
10 |
| croak("ClamAV::Clamd::Scan: not a scan handle"); |
| 227 |
10314 |
| e = hv_fetchs((HV *)SvRV(self), "_ptr", 0); |
| 228 |
10314 |
▶ | return (e && SvIOK(*e)) ? INT2PTR(cc_scan *, SvIV(*e)) : NULL; |
Branch: 2 branches
| Branch | True | False | Total |
| return (e && SvIOK(*e)) ? INT2PTR(cc_scan *, SvIV(*e)) : NULL; |
10307 |
7 |
10314 |
| return (e && SvIOK(*e)) ? INT2PTR(cc_scan *, SvIV(*e)) : NULL; |
10300 |
7 |
10307 |
|
| 229 |
|
| } |
| 230 |
|
| |
| 231 |
60 |
| static int cc_vstate_is(pTHX_ SV *self, const char *want) { |
| 232 |
60 |
| SV *s = cc_vfield(aTHX_ self, "state", 5); |
| 233 |
97 |
▶ | return s && strEQ(SvPV_nolen(s), want); |
Branch: 2 branches
| Branch | True | False | Total |
| return s && strEQ(SvPV_nolen(s), want); |
46 |
5 |
51 |
| return s && strEQ(SvPV_nolen(s), want); |
7 |
39 |
46 |
|
| 234 |
|
| } |
| 235 |
|
| |
| 236 |
|
| /* A scan for a handle to own, empty and finished until started. */ |
| 237 |
52 |
| static cc_scan *cc_scan_alloc(pTHX) { |
| 238 |
52 |
| cc_scan *sc = (cc_scan *)malloc(sizeof *sc); |
| 239 |
|
| /* |
| 240 |
|
| # uncoverable branch true |
| 241 |
|
| # uncoverable condition left count:1 */ |
| 242 |
52 |
▶ | if (!sc) croak("ClamAV::Clamd->start_scan: out of memory"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!sc) croak("ClamAV::Clamd->start_scan: out of memory"); |
0 |
52 |
52 |
|
| 243 |
52 |
| memset(sc, 0, sizeof *sc); |
| 244 |
52 |
| sc->sock = CC_INVALID_SOCK; |
| 245 |
52 |
| return sc; |
| 246 |
|
| } |
| 247 |
|
| |
| 248 |
|
| /* The table hands back no scan only when it could not allocate one. */ |
| 249 |
29 |
| static void *cc_abi_scan_or_croak(pTHX_ void *scan, void *target, const char *who) { |
| 250 |
|
| /* |
| 251 |
|
| # uncoverable branch true |
| 252 |
|
| # uncoverable condition left count:1 */ |
| 253 |
29 |
▶ | if (!scan) { CLAMD_ABI.target_free(aTHX_ target); croak("%s: no scan handle", who); } |
Branch: 1 branch
| Branch | True | False | Total |
| if (!scan) { CLAMD_ABI.target_free(aTHX_ target); croak("%s: no scan handle", who); } |
0 |
29 |
29 |
|
| 254 |
29 |
| return scan; |
| 255 |
|
| } |
| 256 |
|
| |
| 257 |
|
| /* Drive a scan through the table on poll, as a consumer would, and say |
| 258 |
|
| * how many steps it took. */ |
| 259 |
3 |
| static int cc_abi_drive(pTHX_ void *scan) { |
| 260 |
3 |
| const clamd_abi *abi = &CLAMD_ABI; |
| 261 |
3 |
| int steps = 0; |
| 262 |
5 |
▶ | while (abi->scan_step(aTHX_ scan) == CLAMD_ABI_STEP_MORE) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (abi->scan_step(aTHX_ scan) == CLAMD_ABI_STEP_MORE) { |
2 |
3 |
5 |
|
| 263 |
2 |
| int w = abi->scan_want(aTHX_ scan); |
| 264 |
2 |
| (void)cc_wait(abi->scan_socket(aTHX_ scan), w == CLAMD_ABI_WANT_WRITE, cc_now() + 5.0); |
| 265 |
|
| /* |
| 266 |
|
| # uncoverable branch true |
| 267 |
|
| # uncoverable condition left count:1 */ |
| 268 |
2 |
▶ | if (++steps > 100000) break; |
Branch: 1 branch
| Branch | True | False | Total |
| if (++steps > 100000) break; |
0 |
2 |
2 |
|
| 269 |
|
| } |
| 270 |
3 |
| return steps; |
| 271 |
|
| } |
| 272 |
|
| |
| 273 |
|
| MODULE = ClamAV::Clamd PACKAGE = ClamAV::Clamd PREFIX = cc_ |
| 274 |
|
| |
| 275 |
|
| PROTOTYPES: DISABLE |
| 276 |
|
| |
| 277 |
|
| BOOT: |
| 278 |
|
| { |
| 279 |
18 |
| HV *stash = gv_stashpvs("ClamAV::Clamd", GV_ADD); |
| 280 |
18 |
| newCONSTSUB(stash, "CC_OK", newSViv(CC_OK)); |
| 281 |
18 |
| newCONSTSUB(stash, "ERR_CONNECT", newSViv(CC_ERR_CONNECT)); |
| 282 |
18 |
| newCONSTSUB(stash, "ERR_TIMEOUT", newSViv(CC_ERR_TIMEOUT)); |
| 283 |
18 |
| newCONSTSUB(stash, "ERR_IO", newSViv(CC_ERR_IO)); |
| 284 |
18 |
| newCONSTSUB(stash, "ERR_TOOBIG", newSViv(CC_ERR_TOOBIG)); |
| 285 |
18 |
| newCONSTSUB(stash, "ERR_CONFIG", newSViv(CC_ERR_CONFIG)); |
| 286 |
18 |
| newCONSTSUB(stash, "ERR_CLOSED", newSViv(CC_ERR_CLOSED)); |
| 287 |
18 |
| newCONSTSUB(stash, "ERR_NOTREG", newSViv(CC_ERR_NOTREG)); |
| 288 |
18 |
| newCONSTSUB(stash, "ERR_NOFDPASS", newSViv(CC_ERR_NOFDPASS)); |
| 289 |
18 |
| newCONSTSUB(stash, "ERR_STREAMCUT", newSViv(CC_ERR_STREAMCUT)); |
| 290 |
18 |
| newCONSTSUB(stash, "ERR_TOOBIGLOCAL", newSViv(CC_ERR_TOOBIGLOC)); |
| 291 |
18 |
| newCONSTSUB(stash, "ERR_UNAVAILABLE", newSViv(CC_ERR_UNAVAILABLE)); |
| 292 |
|
| } |
| 293 |
|
| |
| 294 |
|
| # Validates and stores. Nothing connects here. |
| 295 |
|
| # |
| 296 |
|
| # Configuration that cannot work croaks - that is a mistake in the |
| 297 |
|
| # caller's program and should not be survivable. Operational failure is |
| 298 |
|
| # reported through error()/error_code() instead. |
| 299 |
|
| SV * |
| 300 |
|
| cc_new(class, ...) |
| 301 |
|
| SV *class |
| 302 |
|
| PREINIT: |
| 303 |
|
| HV *self; |
| 304 |
|
| I32 i; |
| 305 |
|
| SV **sv; |
| 306 |
|
| const char *frame; |
| 307 |
|
| STRLEN flen; |
| 308 |
|
| int have_socket, have_host; |
| 309 |
|
| CODE: |
| 310 |
116 |
▶ | if ((items - 1) % 2) |
Branch: 1 branch
| Branch | True | False | Total |
| if ((items - 1) % 2) |
1 |
115 |
116 |
|
| 311 |
1 |
| croak("ClamAV::Clamd->new: expected a list of key => value pairs"); |
| 312 |
|
| |
| 313 |
115 |
| self = newHV(); |
| 314 |
115 |
| (void)hv_stores(self, "port", newSViv(CC_DEF_PORT)); |
| 315 |
115 |
| (void)hv_stores(self, "connect_timeout", newSVnv(CC_DEF_CONNECT_TIMEOUT)); |
| 316 |
115 |
| (void)hv_stores(self, "reply_timeout", newSVnv(CC_DEF_REPLY_TIMEOUT)); |
| 317 |
115 |
| (void)hv_stores(self, "reply_max", newSVuv(CC_DEF_REPLY_MAX)); |
| 318 |
115 |
| (void)hv_stores(self, "frame", newSVpvs("z")); |
| 319 |
|
| |
| 320 |
328 |
▶ | for (i = 1; i < items; i += 2) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 1; i < items; i += 2) { |
213 |
115 |
328 |
|
| 321 |
|
| STRLEN klen; |
| 322 |
213 |
| const char *k = SvPV(ST(i), klen); |
| 323 |
213 |
| (void)hv_store(self, k, (I32)klen, newSVsv(ST(i + 1)), 0); |
| 324 |
|
| } |
| 325 |
|
| |
| 326 |
115 |
| sv = hv_fetchs(self, "socket", 0); |
| 327 |
115 |
▶ | have_socket = (sv && SvOK(*sv)); |
Branch: 2 branches
| Branch | True | False | Total |
| have_socket = (sv && SvOK(*sv)); |
91 |
24 |
115 |
| have_socket = (sv && SvOK(*sv)); |
90 |
1 |
91 |
|
| 328 |
115 |
| sv = hv_fetchs(self, "host", 0); |
| 329 |
115 |
▶ | have_host = (sv && SvOK(*sv)); |
Branch: 2 branches
| Branch | True | False | Total |
| have_host = (sv && SvOK(*sv)); |
26 |
89 |
115 |
| have_host = (sv && SvOK(*sv)); |
25 |
1 |
26 |
|
| 330 |
|
| |
| 331 |
115 |
▶ | if (!have_socket && !have_host) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (!have_socket && !have_host) { |
25 |
90 |
115 |
| if (!have_socket && !have_host) { |
1 |
24 |
25 |
|
| 332 |
1 |
| SvREFCNT_dec((SV *)self); |
| 333 |
1 |
| croak("ClamAV::Clamd->new: one of 'socket' or 'host' is required"); |
| 334 |
|
| } |
| 335 |
114 |
▶ | if (have_socket && have_host) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (have_socket && have_host) { |
90 |
24 |
114 |
| if (have_socket && have_host) { |
1 |
89 |
90 |
|
| 336 |
1 |
| SvREFCNT_dec((SV *)self); |
| 337 |
1 |
| croak("ClamAV::Clamd->new: give 'socket' or 'host', not both"); |
| 338 |
|
| } |
| 339 |
|
| |
| 340 |
|
| /* A UNIX socket path that does not fit sockaddr_un is refused here, |
| 341 |
|
| * loudly, rather than truncated by the kernel. A truncated path |
| 342 |
|
| * connects to a DIFFERENT socket - and a scanner that believes an |
| 343 |
|
| * answer from an unidentified peer is worse than one that fails. */ |
| 344 |
113 |
▶ | if (have_socket) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (have_socket) { |
89 |
24 |
113 |
|
| 345 |
|
| #ifdef _WIN32 |
| 346 |
|
| SvREFCNT_dec((SV *)self); |
| 347 |
|
| croak("ClamAV::Clamd->new: UNIX sockets are not supported on this platform; use host/port"); |
| 348 |
|
| #else |
| 349 |
|
| STRLEN plen; |
| 350 |
89 |
| SV **psv = hv_fetchs(self, "socket", 0); |
| 351 |
89 |
| const char *p = SvPV(*psv, plen); |
| 352 |
89 |
▶ | if (plen >= CC_SUN_PATH_MAX) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (plen >= CC_SUN_PATH_MAX) { |
1 |
88 |
89 |
|
| 353 |
1 |
| SV *msg = sv_2mortal(newSVpvf( |
| 354 |
|
| "ClamAV::Clamd->new: socket path is %" UVuf |
| 355 |
|
| " bytes, this platform allows %" UVuf ": %s", |
| 356 |
|
| (UV)plen, (UV)(CC_SUN_PATH_MAX - 1), p)); |
| 357 |
1 |
| SvREFCNT_dec((SV *)self); |
| 358 |
1 |
| croak("%s", SvPV_nolen(msg)); |
| 359 |
|
| } |
| 360 |
|
| #endif |
| 361 |
|
| } |
| 362 |
|
| |
| 363 |
|
| /* Every key below was stored above, so each fetch finds a slot; an |
| 364 |
|
| * undef given by the caller is what SvOK is for. */ |
| 365 |
112 |
| sv = hv_fetchs(self, "frame", 0); |
| 366 |
223 |
▶ | if (SvOK(*sv)) frame = SvPV(*sv, flen); |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvOK(*sv)) frame = SvPV(*sv, flen); |
111 |
1 |
112 |
|
| 367 |
1 |
| else { frame = "z"; flen = 1; } |
| 368 |
112 |
▶ | if (!(flen == 1 && (*frame == 'z' || *frame == 'n'))) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (!(flen == 1 && (*frame == 'z' || *frame == 'n'))) { |
111 |
1 |
112 |
| if (!(flen == 1 && (*frame == 'z' || *frame == 'n'))) { |
3 |
108 |
111 |
| if (!(flen == 1 && (*frame == 'z' || *frame == 'n'))) { |
1 |
2 |
3 |
|
| 369 |
2 |
| SvREFCNT_dec((SV *)self); |
| 370 |
2 |
| croak("ClamAV::Clamd->new: frame must be 'z' or 'n'"); |
| 371 |
|
| } |
| 372 |
|
| |
| 373 |
|
| { |
| 374 |
|
| const char *keys[2]; |
| 375 |
|
| int n; |
| 376 |
110 |
| keys[0] = "connect_timeout"; |
| 377 |
110 |
| keys[1] = "reply_timeout"; |
| 378 |
325 |
▶ | for (n = 0; n < 2; n++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (n = 0; n < 2; n++) { |
218 |
107 |
325 |
|
| 379 |
218 |
| SV **t = hv_fetch(self, keys[n], (I32)strlen(keys[n]), 0); |
| 380 |
218 |
▶ | if (!SvOK(*t) || SvNV(*t) <= 0.0) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (!SvOK(*t) || SvNV(*t) <= 0.0) { |
217 |
1 |
218 |
| if (!SvOK(*t) || SvNV(*t) <= 0.0) { |
2 |
215 |
217 |
|
| 381 |
3 |
| SV *msg = sv_2mortal(newSVpvf( |
| 382 |
|
| "ClamAV::Clamd->new: %s must be a positive number", keys[n])); |
| 383 |
3 |
| SvREFCNT_dec((SV *)self); |
| 384 |
3 |
| croak("%s", SvPV_nolen(msg)); |
| 385 |
|
| } |
| 386 |
|
| } |
| 387 |
|
| } |
| 388 |
|
| |
| 389 |
107 |
| RETVAL = sv_bless(newRV_noinc((SV *)self), gv_stashsv(class, GV_ADD)); |
| 390 |
|
| OUTPUT: |
| 391 |
|
| RETVAL |
| 392 |
|
| |
| 393 |
|
| # True if clamd answered PONG. Undef on any failure, with error() set. |
| 394 |
|
| void |
| 395 |
|
| cc_ping(self) |
| 396 |
|
| SV *self |
| 397 |
|
| PPCODE: |
| 398 |
33 |
▶ | if (!cc_do_exact(aTHX_ self, "PING", "PONG", "ping")) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!cc_do_exact(aTHX_ self, "PING", "PONG", "ping")) |
21 |
10 |
31 |
|
| 399 |
21 |
| XSRETURN_UNDEF; |
| 400 |
10 |
| XSRETURN_YES; |
| 401 |
|
| |
| 402 |
|
| # clamd's version string, or undef. |
| 403 |
|
| void |
| 404 |
|
| cc_version(self) |
| 405 |
|
| SV *self |
| 406 |
|
| PREINIT: |
| 407 |
|
| SV *r; |
| 408 |
|
| PPCODE: |
| 409 |
6 |
| r = cc_do_command(aTHX_ self, "VERSION", "version"); |
| 410 |
4 |
▶ | if (!r) XSRETURN_UNDEF; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!r) XSRETURN_UNDEF; |
1 |
3 |
4 |
|
| 411 |
3 |
▶ | XPUSHs(r); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(r); |
0 |
3 |
3 |
|
| 412 |
|
| |
| 413 |
|
| # The STATS reply, or undef. |
| 414 |
|
| void |
| 415 |
|
| cc_stats(self) |
| 416 |
|
| SV *self |
| 417 |
|
| PREINIT: |
| 418 |
|
| SV *r; |
| 419 |
|
| PPCODE: |
| 420 |
4 |
| r = cc_do_command(aTHX_ self, "STATS", "stats"); |
| 421 |
2 |
▶ | if (!r) XSRETURN_UNDEF; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!r) XSRETURN_UNDEF; |
1 |
1 |
2 |
|
| 422 |
1 |
▶ | XPUSHs(r); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(r); |
0 |
1 |
1 |
|
| 423 |
|
| |
| 424 |
|
| # Asks clamd to reload its signature database. True if it accepted. |
| 425 |
|
| void |
| 426 |
|
| cc_reload(self) |
| 427 |
|
| SV *self |
| 428 |
|
| PPCODE: |
| 429 |
5 |
▶ | if (!cc_do_exact(aTHX_ self, "RELOAD", "RELOADING", "reload")) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!cc_do_exact(aTHX_ self, "RELOAD", "RELOADING", "reload")) |
2 |
1 |
3 |
|
| 430 |
2 |
| XSRETURN_UNDEF; |
| 431 |
1 |
| XSRETURN_YES; |
| 432 |
|
| |
| 433 |
|
| # The failure from the last command, or undef if it succeeded. |
| 434 |
|
| void |
| 435 |
|
| cc_error(self) |
| 436 |
|
| SV *self |
| 437 |
|
| PREINIT: |
| 438 |
|
| SV **sv; |
| 439 |
|
| PPCODE: |
| 440 |
24 |
| sv = hv_fetchs(cc_self_hv(aTHX_ self, "error"), "error", 0); |
| 441 |
22 |
▶ | if (!sv || !SvOK(*sv)) XSRETURN_UNDEF; |
Branch: 2 branches
| Branch | True | False | Total |
| if (!sv || !SvOK(*sv)) XSRETURN_UNDEF; |
20 |
2 |
22 |
| if (!sv || !SvOK(*sv)) XSRETURN_UNDEF; |
1 |
19 |
20 |
|
| 442 |
19 |
▶ | XPUSHs(sv_mortalcopy(*sv)); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(sv_mortalcopy(*sv)); |
0 |
19 |
19 |
|
| 443 |
|
| |
| 444 |
|
| # The code for that failure, so failures can be told apart without |
| 445 |
|
| # matching on message text. |
| 446 |
|
| void |
| 447 |
|
| cc_error_code(self) |
| 448 |
|
| SV *self |
| 449 |
|
| PREINIT: |
| 450 |
|
| SV **sv; |
| 451 |
|
| PPCODE: |
| 452 |
46 |
| sv = hv_fetchs(cc_self_hv(aTHX_ self, "error_code"), "error_code", 0); |
| 453 |
44 |
▶ | if (!sv || !SvOK(*sv)) XSRETURN_UNDEF; |
Branch: 2 branches
| Branch | True | False | Total |
| if (!sv || !SvOK(*sv)) XSRETURN_UNDEF; |
42 |
2 |
44 |
| if (!sv || !SvOK(*sv)) XSRETURN_UNDEF; |
1 |
41 |
42 |
|
| 454 |
41 |
▶ | XPUSHs(sv_mortalcopy(*sv)); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(sv_mortalcopy(*sv)); |
0 |
41 |
41 |
|
| 455 |
|
| |
| 456 |
|
| # Scan an open descriptor or filehandle by passing it to clamd. |
| 457 |
|
| # |
| 458 |
|
| # The descriptor is BORROWED: never closed here, and never seeked - |
| 459 |
|
| # clamd scans the whole file wherever the descriptor is positioned, so |
| 460 |
|
| # there is nothing to correct and correcting it would mutate the |
| 461 |
|
| # caller's state. |
| 462 |
|
| void |
| 463 |
|
| cc_scan_fd(self, fh) |
| 464 |
|
| SV *self |
| 465 |
|
| SV *fh |
| 466 |
|
| PREINIT: |
| 467 |
|
| HV *hv; |
| 468 |
|
| cc_target t; |
| 469 |
|
| cc_err err; |
| 470 |
16 |
| char *reply = NULL; |
| 471 |
16 |
| size_t len = 0; |
| 472 |
16 |
| int rc, fd, transport = CC_TRANSPORT_NONE; |
| 473 |
|
| SV *out; |
| 474 |
|
| PPCODE: |
| 475 |
16 |
| hv = cc_self_hv(aTHX_ self, "scan_fd"); |
| 476 |
14 |
| cc_clear_error(aTHX_ hv); |
| 477 |
|
| |
| 478 |
14 |
| fd = cc_fileno(aTHX_ fh); |
| 479 |
14 |
▶ | if (fd < 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (fd < 0) { |
5 |
9 |
14 |
|
| 480 |
5 |
| cc_err bad; memset(&bad, 0, sizeof bad); |
| 481 |
5 |
| cc_err_set(&bad, CC_ERR_CONFIG, |
| 482 |
|
| "scan_fd needs an open filehandle or a descriptor number", NULL); |
| 483 |
5 |
▶ | XPUSHs(cc_scan_result(aTHX_ hv, CC_ERR_CONFIG, NULL, 0, CC_TRANSPORT_NONE, &bad)); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(cc_scan_result(aTHX_ hv, CC_ERR_CONFIG, NULL, 0, CC_TRANSPORT_NONE, &bad)); |
0 |
5 |
5 |
|
| 484 |
5 |
| XSRETURN(1); |
| 485 |
|
| } |
| 486 |
|
| |
| 487 |
9 |
| cc_target_from_hv(aTHX_ hv, &t); |
| 488 |
9 |
| memset(&err, 0, sizeof err); |
| 489 |
9 |
| rc = cc_scan_fd(&t, fd, &reply, &len, &transport, &err); |
| 490 |
9 |
▶ | XPUSHs(cc_scan_result(aTHX_ hv, rc, reply, len, transport, &err)); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(cc_scan_result(aTHX_ hv, rc, reply, len, transport, &err)); |
0 |
9 |
9 |
|
| 491 |
|
| |
| 492 |
|
| # Scan a path. The file is opened HERE and the descriptor is what |
| 493 |
|
| # travels - this is not clamd's SCAN command, and clamd needs no |
| 494 |
|
| # permission on the path. |
| 495 |
|
| void |
| 496 |
|
| cc_scan_path(self, path) |
| 497 |
|
| SV *self |
| 498 |
|
| const char *path |
| 499 |
|
| PREINIT: |
| 500 |
|
| HV *hv; |
| 501 |
|
| cc_target t; |
| 502 |
|
| cc_err err; |
| 503 |
9 |
| char *reply = NULL; |
| 504 |
9 |
| size_t len = 0; |
| 505 |
9 |
| int rc, transport = CC_TRANSPORT_NONE; |
| 506 |
|
| SV *out; |
| 507 |
|
| PPCODE: |
| 508 |
9 |
| hv = cc_self_hv(aTHX_ self, "scan_path"); |
| 509 |
7 |
| cc_clear_error(aTHX_ hv); |
| 510 |
|
| |
| 511 |
7 |
| cc_target_from_hv(aTHX_ hv, &t); |
| 512 |
7 |
| memset(&err, 0, sizeof err); |
| 513 |
7 |
| rc = cc_scan_path(&t, path, &reply, &len, &transport, &err); |
| 514 |
7 |
▶ | XPUSHs(cc_scan_result(aTHX_ hv, rc, reply, len, transport, &err)); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(cc_scan_result(aTHX_ hv, rc, reply, len, transport, &err)); |
0 |
7 |
7 |
|
| 515 |
|
| |
| 516 |
|
| # Scan bytes that were never a file. |
| 517 |
|
| # |
| 518 |
|
| # They go out from where they already are - no assembly buffer, no copy - |
| 519 |
|
| # because "already in memory" is the whole reason this path exists rather |
| 520 |
|
| # than spilling to a file and using scan_fd. |
| 521 |
|
| void |
| 522 |
|
| cc_scan(self, data) |
| 523 |
|
| SV *self |
| 524 |
|
| SV *data |
| 525 |
|
| PREINIT: |
| 526 |
|
| HV *hv; |
| 527 |
|
| cc_target t; |
| 528 |
|
| cc_err err; |
| 529 |
54 |
| char *reply = NULL; |
| 530 |
54 |
| size_t len = 0; |
| 531 |
|
| int rc; |
| 532 |
|
| STRLEN dlen; |
| 533 |
|
| const char *dp; |
| 534 |
|
| SV *out; |
| 535 |
|
| PPCODE: |
| 536 |
54 |
| hv = cc_self_hv(aTHX_ self, "scan"); |
| 537 |
52 |
| cc_clear_error(aTHX_ hv); |
| 538 |
|
| |
| 539 |
52 |
▶ | if (!SvOK(data)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!SvOK(data)) { |
1 |
51 |
52 |
|
| 540 |
1 |
| cc_err bad; memset(&bad, 0, sizeof bad); |
| 541 |
1 |
| cc_err_set(&bad, CC_ERR_CONFIG, "scan needs a defined scalar of bytes", NULL); |
| 542 |
1 |
▶ | XPUSHs(cc_scan_result(aTHX_ hv, CC_ERR_CONFIG, NULL, 0, CC_TRANSPORT_NONE, &bad)); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(cc_scan_result(aTHX_ hv, CC_ERR_CONFIG, NULL, 0, CC_TRANSPORT_NONE, &bad)); |
0 |
1 |
1 |
|
| 543 |
1 |
| XSRETURN(1); |
| 544 |
|
| } |
| 545 |
|
| /* Wide characters are not bytes. Guessing an encoding here would |
| 546 |
|
| * mean scanning something the caller never stored. */ |
| 547 |
51 |
▶ | if (DO_UTF8(data) && !sv_utf8_downgrade(data, 1)) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (DO_UTF8(data) && !sv_utf8_downgrade(data, 1)) { |
1 |
50 |
51 |
| if (DO_UTF8(data) && !sv_utf8_downgrade(data, 1)) { |
1 |
0 |
1 |
| if (DO_UTF8(data) && !sv_utf8_downgrade(data, 1)) { |
1 |
0 |
1 |
|
| 548 |
1 |
| cc_err bad; memset(&bad, 0, sizeof bad); |
| 549 |
1 |
| cc_err_set(&bad, CC_ERR_CONFIG, |
| 550 |
|
| "scan needs bytes, not wide characters; encode it first", NULL); |
| 551 |
1 |
▶ | XPUSHs(cc_scan_result(aTHX_ hv, CC_ERR_CONFIG, NULL, 0, CC_TRANSPORT_NONE, &bad)); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(cc_scan_result(aTHX_ hv, CC_ERR_CONFIG, NULL, 0, CC_TRANSPORT_NONE, &bad)); |
0 |
1 |
1 |
|
| 552 |
1 |
| XSRETURN(1); |
| 553 |
|
| } |
| 554 |
|
| |
| 555 |
50 |
| dp = SvPV_const(data, dlen); |
| 556 |
|
| |
| 557 |
50 |
| cc_target_from_hv(aTHX_ hv, &t); |
| 558 |
50 |
| memset(&err, 0, sizeof err); |
| 559 |
50 |
▶ | if (t.max_size && (size_t)dlen > t.max_size) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (t.max_size && (size_t)dlen > t.max_size) { |
2 |
48 |
50 |
| if (t.max_size && (size_t)dlen > t.max_size) { |
1 |
1 |
2 |
|
| 560 |
1 |
| cc_err_set(&err, CC_ERR_TOOBIGLOC, |
| 561 |
|
| "larger than max_size; refused without scanning", NULL); |
| 562 |
1 |
| rc = CC_ERR_TOOBIGLOC; |
| 563 |
|
| } else { |
| 564 |
|
| cc_scan sc; |
| 565 |
49 |
| rc = cc_scan_start(&sc, &t, CC_TRANSPORT_INSTREAM, -1, 0, |
| 566 |
|
| dp, (size_t)dlen, -1); |
| 567 |
49 |
▶ | if (rc == CC_OK) rc = cc_scan_run(&sc, &reply, &len, &err); |
Branch: 1 branch
| Branch | True | False | Total |
| if (rc == CC_OK) rc = cc_scan_run(&sc, &reply, &len, &err); |
48 |
1 |
49 |
|
| 568 |
1 |
| else err = sc.err; |
| 569 |
49 |
| cc_scan_free(&sc); |
| 570 |
|
| } |
| 571 |
50 |
▶ | XPUSHs(cc_scan_result(aTHX_ hv, rc, reply, len, CC_TRANSPORT_INSTREAM, &err)); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(cc_scan_result(aTHX_ hv, rc, reply, len, CC_TRANSPORT_INSTREAM, &err)); |
0 |
50 |
50 |
|
| 572 |
|
| |
| 573 |
|
| # Which transport produced the last scan: 'fildes', 'instream', or undef. |
| 574 |
|
| void |
| 575 |
|
| cc_transport(self) |
| 576 |
|
| SV *self |
| 577 |
|
| PREINIT: |
| 578 |
|
| SV **sv; |
| 579 |
|
| IV v; |
| 580 |
|
| const char *name; |
| 581 |
|
| PPCODE: |
| 582 |
10 |
| sv = hv_fetchs(cc_self_hv(aTHX_ self, "transport"), "transport", 0); |
| 583 |
8 |
▶ | if (!sv || !SvOK(*sv)) XSRETURN_UNDEF; |
Branch: 2 branches
| Branch | True | False | Total |
| if (!sv || !SvOK(*sv)) XSRETURN_UNDEF; |
7 |
1 |
8 |
| if (!sv || !SvOK(*sv)) XSRETURN_UNDEF; |
1 |
6 |
7 |
|
| 584 |
6 |
| v = SvIV(*sv); |
| 585 |
6 |
▶ | if (v == CC_TRANSPORT_NONE) XSRETURN_UNDEF; |
Branch: 1 branch
| Branch | True | False | Total |
| if (v == CC_TRANSPORT_NONE) XSRETURN_UNDEF; |
2 |
4 |
6 |
|
| 586 |
4 |
▶ | name = (v == CC_TRANSPORT_FILDES) ? "fildes" : "instream"; |
Branch: 1 branch
| Branch | True | False | Total |
| name = (v == CC_TRANSPORT_FILDES) ? "fildes" : "instream"; |
1 |
3 |
4 |
|
| 587 |
4 |
▶ | XPUSHs(sv_2mortal(newSVpv(name, 0))); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(sv_2mortal(newSVpv(name, 0))); |
0 |
4 |
4 |
|
| 588 |
|
| |
| 589 |
|
| # Whether this platform can pass descriptors over a socket. False on |
| 590 |
|
| # Windows, which has AF_UNIX but no SCM_RIGHTS. Phase 2 needs it, and it |
| 591 |
|
| # is a platform fact rather than a runtime guess. |
| 592 |
|
| IV |
| 593 |
|
| cc_have_fd_passing(...) |
| 594 |
|
| CODE: |
| 595 |
|
| PERL_UNUSED_VAR(items); |
| 596 |
4 |
▶ | RETVAL = CC_HAVE_FD_PASSING; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = CC_HAVE_FD_PASSING; |
0 |
4 |
4 |
|
| 597 |
|
| OUTPUT: |
| 598 |
|
| RETVAL |
| 599 |
|
| |
| 600 |
|
| # The platform's sockaddr_un limit, so a refusal can name what it |
| 601 |
|
| # refused. Zero where UNIX sockets do not exist. |
| 602 |
|
| UV |
| 603 |
|
| cc__sun_path_max() |
| 604 |
|
| CODE: |
| 605 |
|
| #ifdef _WIN32 |
| 606 |
|
| RETVAL = 0; |
| 607 |
|
| #else |
| 608 |
15 |
▶ | RETVAL = (UV)CC_SUN_PATH_MAX; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = (UV)CC_SUN_PATH_MAX; |
0 |
15 |
15 |
|
| 609 |
|
| #endif |
| 610 |
|
| OUTPUT: |
| 611 |
|
| RETVAL |
| 612 |
|
| |
| 613 |
|
| MODULE = ClamAV::Clamd PACKAGE = ClamAV::Clamd::Verdict PREFIX = ccv_ |
| 614 |
|
| |
| 615 |
|
| PROTOTYPES: DISABLE |
| 616 |
|
| |
| 617 |
|
| # 'clean', 'infected', 'unscannable' or 'error'. |
| 618 |
|
| void |
| 619 |
|
| ccv_state(self) |
| 620 |
|
| SV *self |
| 621 |
|
| PREINIT: |
| 622 |
|
| SV *s; |
| 623 |
|
| PPCODE: |
| 624 |
91 |
| s = cc_vfield(aTHX_ self, "state", 5); |
| 625 |
89 |
▶ | if (!s) XSRETURN_UNDEF; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!s) XSRETURN_UNDEF; |
1 |
88 |
89 |
|
| 626 |
88 |
▶ | XPUSHs(sv_mortalcopy(s)); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(sv_mortalcopy(s)); |
0 |
88 |
88 |
|
| 627 |
|
| |
| 628 |
|
| # TRUE FOR EXACTLY ONE STATE. |
| 629 |
|
| # |
| 630 |
|
| # Everything else - infected, unscannable, and every failure to reach |
| 631 |
|
| # clamd at all - is false here. A caller who wants to accept an upload |
| 632 |
|
| # writes one short safe thing; a caller who wants to reject one has more |
| 633 |
|
| # to think about, which is the right way round. |
| 634 |
|
| void |
| 635 |
|
| ccv_is_clean(self) |
| 636 |
|
| SV *self |
| 637 |
|
| PPCODE: |
| 638 |
30 |
▶ | if (cc_vstate_is(aTHX_ self, "clean")) XSRETURN_YES; |
Branch: 1 branch
| Branch | True | False | Total |
| if (cc_vstate_is(aTHX_ self, "clean")) XSRETURN_YES; |
3 |
25 |
28 |
|
| 639 |
25 |
| XSRETURN_NO; |
| 640 |
|
| |
| 641 |
|
| void |
| 642 |
|
| ccv_is_infected(self) |
| 643 |
|
| SV *self |
| 644 |
|
| PPCODE: |
| 645 |
7 |
▶ | if (cc_vstate_is(aTHX_ self, "infected")) XSRETURN_YES; |
Branch: 1 branch
| Branch | True | False | Total |
| if (cc_vstate_is(aTHX_ self, "infected")) XSRETURN_YES; |
1 |
4 |
5 |
|
| 646 |
4 |
| XSRETURN_NO; |
| 647 |
|
| |
| 648 |
|
| # NOT scanned, or not scanned completely: over a size ceiling, nested |
| 649 |
|
| # past MaxRecursion, an encrypted archive clamd could not open. Never |
| 650 |
|
| # the same thing as clean, however much clamd's own reply looks like it. |
| 651 |
|
| void |
| 652 |
|
| ccv_is_unscannable(self) |
| 653 |
|
| SV *self |
| 654 |
|
| PPCODE: |
| 655 |
7 |
▶ | if (cc_vstate_is(aTHX_ self, "unscannable")) XSRETURN_YES; |
Branch: 1 branch
| Branch | True | False | Total |
| if (cc_vstate_is(aTHX_ self, "unscannable")) XSRETURN_YES; |
1 |
4 |
5 |
|
| 656 |
4 |
| XSRETURN_NO; |
| 657 |
|
| |
| 658 |
|
| void |
| 659 |
|
| ccv_is_error(self) |
| 660 |
|
| SV *self |
| 661 |
|
| PPCODE: |
| 662 |
10 |
▶ | if (cc_vstate_is(aTHX_ self, "error")) XSRETURN_YES; |
Branch: 1 branch
| Branch | True | False | Total |
| if (cc_vstate_is(aTHX_ self, "error")) XSRETURN_YES; |
1 |
7 |
8 |
|
| 663 |
7 |
| XSRETURN_NO; |
| 664 |
|
| |
| 665 |
|
| # The signature clamd named, or undef. |
| 666 |
|
| # |
| 667 |
|
| # THIS IS REMOTE INPUT. A file crafted to match a chosen signature |
| 668 |
|
| # chooses the string that comes back. It is length-bounded, and it |
| 669 |
|
| # belongs in a log, not in a response body. |
| 670 |
|
| void |
| 671 |
|
| ccv_signature(self) |
| 672 |
|
| SV *self |
| 673 |
|
| PREINIT: |
| 674 |
|
| SV *s; |
| 675 |
|
| PPCODE: |
| 676 |
28 |
| s = cc_vfield(aTHX_ self, "signature", 9); |
| 677 |
26 |
▶ | if (!s) XSRETURN_UNDEF; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!s) XSRETURN_UNDEF; |
9 |
17 |
26 |
|
| 678 |
17 |
▶ | XPUSHs(sv_mortalcopy(s)); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(sv_mortalcopy(s)); |
0 |
17 |
17 |
|
| 679 |
|
| |
| 680 |
|
| # Why it could not be scanned: 'MaxFileSize', 'MaxRecursion', |
| 681 |
|
| # 'StreamMaxLength', 'Encrypted', 'max_size'. Undef unless unscannable. |
| 682 |
|
| void |
| 683 |
|
| ccv_reason(self) |
| 684 |
|
| SV *self |
| 685 |
|
| PREINIT: |
| 686 |
|
| SV *s; |
| 687 |
|
| PPCODE: |
| 688 |
32 |
| s = cc_vfield(aTHX_ self, "reason", 6); |
| 689 |
30 |
▶ | if (!s) XSRETURN_UNDEF; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!s) XSRETURN_UNDEF; |
10 |
20 |
30 |
|
| 690 |
20 |
▶ | XPUSHs(sv_mortalcopy(s)); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(sv_mortalcopy(s)); |
0 |
20 |
20 |
|
| 691 |
|
| |
| 692 |
|
| # 'fildes' or 'instream'. |
| 693 |
|
| void |
| 694 |
|
| ccv_transport(self) |
| 695 |
|
| SV *self |
| 696 |
|
| PREINIT: |
| 697 |
|
| SV *s; |
| 698 |
|
| PPCODE: |
| 699 |
10 |
| s = cc_vfield(aTHX_ self, "transport", 9); |
| 700 |
8 |
▶ | if (!s) XSRETURN_UNDEF; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!s) XSRETURN_UNDEF; |
2 |
6 |
8 |
|
| 701 |
6 |
▶ | XPUSHs(sv_mortalcopy(s)); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(sv_mortalcopy(s)); |
0 |
6 |
6 |
|
| 702 |
|
| |
| 703 |
|
| # What went wrong, when nothing usable came back. |
| 704 |
|
| void |
| 705 |
|
| ccv_error(self) |
| 706 |
|
| SV *self |
| 707 |
|
| PREINIT: |
| 708 |
|
| SV *s; |
| 709 |
|
| PPCODE: |
| 710 |
15 |
| s = cc_vfield(aTHX_ self, "error", 5); |
| 711 |
13 |
▶ | if (!s) XSRETURN_UNDEF; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!s) XSRETURN_UNDEF; |
2 |
11 |
13 |
|
| 712 |
11 |
▶ | XPUSHs(sv_mortalcopy(s)); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(sv_mortalcopy(s)); |
0 |
11 |
11 |
|
| 713 |
|
| |
| 714 |
|
| # clamd's reply verbatim, for logging something the parser did not |
| 715 |
|
| # anticipate. |
| 716 |
|
| void |
| 717 |
|
| ccv_raw(self) |
| 718 |
|
| SV *self |
| 719 |
|
| PREINIT: |
| 720 |
|
| SV *s; |
| 721 |
|
| PPCODE: |
| 722 |
6 |
| s = cc_vfield(aTHX_ self, "raw", 3); |
| 723 |
4 |
▶ | if (!s) XSRETURN_UNDEF; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!s) XSRETURN_UNDEF; |
2 |
2 |
4 |
|
| 724 |
2 |
▶ | XPUSHs(sv_mortalcopy(s)); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(sv_mortalcopy(s)); |
0 |
2 |
2 |
|
| 725 |
|
| |
| 726 |
|
| # --- overloading, registered from XS --------------------------------- |
| 727 |
|
| # |
| 728 |
|
| # An object is always true, so the most dangerous plausible misuse of |
| 729 |
|
| # this API is |
| 730 |
|
| # |
| 731 |
|
| # "if (\$clamd->scan(\$file)) { accept() }" |
| 732 |
|
| # |
| 733 |
|
| # which would accept every infected file there is. Wiring bool to |
| 734 |
|
| # is_clean turns that from a silent catastrophe into the correct |
| 735 |
|
| # behaviour, and it costs a caller who wanted the object nothing. |
| 736 |
|
| # |
| 737 |
|
| # Stringification gives the state, so a log line reads "infected" rather |
| 738 |
|
| # than an address. |
| 739 |
|
| |
| 740 |
|
| void |
| 741 |
|
| _ovl_nil(...) |
| 742 |
|
| PPCODE: |
| 743 |
|
| PERL_UNUSED_VAR(items); |
| 744 |
1 |
| XSRETURN_UNDEF; |
| 745 |
|
| |
| 746 |
|
| void |
| 747 |
|
| _ovl_bool(self, ...) |
| 748 |
|
| SV *self |
| 749 |
|
| PPCODE: |
| 750 |
|
| PERL_UNUSED_VAR(items); |
| 751 |
6 |
▶ | if (cc_vstate_is(aTHX_ self, "clean")) XSRETURN_YES; |
Branch: 1 branch
| Branch | True | False | Total |
| if (cc_vstate_is(aTHX_ self, "clean")) XSRETURN_YES; |
1 |
4 |
5 |
|
| 752 |
4 |
| XSRETURN_NO; |
| 753 |
|
| |
| 754 |
|
| void |
| 755 |
|
| _ovl_str(self, ...) |
| 756 |
|
| SV *self |
| 757 |
|
| PREINIT: |
| 758 |
|
| SV *s; |
| 759 |
|
| PPCODE: |
| 760 |
|
| PERL_UNUSED_VAR(items); |
| 761 |
2 |
| s = cc_vfield(aTHX_ self, "state", 5); |
| 762 |
2 |
▶ | if (!s) s = sv_2mortal(newSVpvs("error")); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!s) s = sv_2mortal(newSVpvs("error")); |
1 |
1 |
2 |
|
| 763 |
2 |
▶ | XPUSHs(sv_mortalcopy(s)); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(sv_mortalcopy(s)); |
0 |
2 |
2 |
|
| 764 |
|
| |
| 765 |
|
| BOOT: |
| 766 |
|
| { |
| 767 |
18 |
| HV *vst = gv_stashpvs("ClamAV::Clamd::Verdict", GV_ADD); |
| 768 |
18 |
| newXS("ClamAV::Clamd::Verdict::()", |
| 769 |
|
| XS_ClamAV__Clamd__Verdict__ovl_nil, __FILE__); |
| 770 |
18 |
| newXS("ClamAV::Clamd::Verdict::(bool", |
| 771 |
|
| XS_ClamAV__Clamd__Verdict__ovl_bool, __FILE__); |
| 772 |
18 |
| newXS("ClamAV::Clamd::Verdict::(\"\"", |
| 773 |
|
| XS_ClamAV__Clamd__Verdict__ovl_str, __FILE__); |
| 774 |
|
| /* the () glob's scalar carries the fallback setting */ |
| 775 |
18 |
| sv_setiv(GvSV(gv_fetchpvs("ClamAV::Clamd::Verdict::()", |
| 776 |
|
| GV_ADD|GV_ADDMULTI, SVt_PV)), 1); |
| 777 |
18 |
| mro_method_changed_in(vst); |
| 778 |
|
| } |
| 779 |
|
| |
| 780 |
|
| MODULE = ClamAV::Clamd PACKAGE = ClamAV::Clamd PREFIX = cca_ |
| 781 |
|
| |
| 782 |
|
| PROTOTYPES: DISABLE |
| 783 |
|
| |
| 784 |
|
| # Start a scan without waiting for it. |
| 785 |
|
| # |
| 786 |
|
| # Returns a ClamAV::Clamd::Scan: a socket to register with whatever loop |
| 787 |
|
| # you have, a readiness to wait for, and a step to call. This dist owns |
| 788 |
|
| # no loop and depends on none. |
| 789 |
|
| # |
| 790 |
|
| # The handle keeps a reference to whatever the scan reads from - the byte |
| 791 |
|
| # scalar, or the filehandle - because the scan outlives the call that |
| 792 |
|
| # started it and a freed PV would be read after free. |
| 793 |
|
| SV * |
| 794 |
|
| cca_start_scan(self, what, ...) |
| 795 |
|
| SV *self |
| 796 |
|
| SV *what |
| 797 |
|
| PREINIT: |
| 798 |
|
| HV *hv, *h; |
| 799 |
|
| cc_target t; |
| 800 |
|
| cc_scan *sc; |
| 801 |
54 |
| int mode, fd = -1; |
| 802 |
|
| const char *kind; |
| 803 |
54 |
| STRLEN dlen = 0; |
| 804 |
54 |
| const char *dp = NULL; |
| 805 |
54 |
| SV *keep = NULL; |
| 806 |
|
| CODE: |
| 807 |
54 |
| hv = cc_self_hv(aTHX_ self, "start_scan"); |
| 808 |
52 |
| cc_clear_error(aTHX_ hv); |
| 809 |
52 |
| cc_target_from_hv(aTHX_ hv, &t); |
| 810 |
|
| |
| 811 |
60 |
▶ | kind = (items > 2) ? SvPV_nolen(ST(2)) : "bytes"; |
Branch: 1 branch
| Branch | True | False | Total |
| kind = (items > 2) ? SvPV_nolen(ST(2)) : "bytes"; |
8 |
44 |
52 |
|
| 812 |
|
| |
| 813 |
52 |
| sc = cc_scan_alloc(aTHX); |
| 814 |
|
| |
| 815 |
52 |
▶ | if (strEQ(kind, "path")) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (strEQ(kind, "path")) { |
4 |
48 |
52 |
|
| 816 |
4 |
| const char *path = SvPV_nolen(what); |
| 817 |
4 |
| fd = cc_open_ro(path); |
| 818 |
4 |
▶ | if (fd < 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (fd < 0) { |
1 |
3 |
4 |
|
| 819 |
1 |
| cc_err_set(&sc->err, CC_ERR_IO, "open", strerror(errno)); |
| 820 |
1 |
| sc->rc = CC_ERR_IO; sc->phase = CC_PH_DONE; |
| 821 |
1 |
| goto made; |
| 822 |
|
| } |
| 823 |
3 |
▶ | mode = (CC_HAVE_FD_PASSING && t.path) ? CC_TRANSPORT_FILDES : CC_TRANSPORT_INSTREAM; |
Branch: 1 branch
| Branch | True | False | Total |
| mode = (CC_HAVE_FD_PASSING && t.path) ? CC_TRANSPORT_FILDES : CC_TRANSPORT_INSTREAM; |
1 |
2 |
3 |
|
| 824 |
3 |
▶ | if (mode == CC_TRANSPORT_FILDES) |
Branch: 1 branch
| Branch | True | False | Total |
| if (mode == CC_TRANSPORT_FILDES) |
1 |
2 |
3 |
|
| 825 |
1 |
| (void)cc_scan_start(sc, &t, mode, fd, 1, NULL, 0, -1); |
| 826 |
|
| else |
| 827 |
2 |
| (void)cc_scan_start(sc, &t, mode, -1, 1, NULL, 0, fd); |
| 828 |
|
| } |
| 829 |
48 |
▶ | else if (strEQ(kind, "fd")) { |
Branch: 1 branch
| Branch | True | False | Total |
| else if (strEQ(kind, "fd")) { |
4 |
44 |
48 |
|
| 830 |
4 |
| fd = cc_fileno(aTHX_ what); |
| 831 |
4 |
▶ | if (fd < 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (fd < 0) { |
1 |
3 |
4 |
|
| 832 |
1 |
| cc_err_set(&sc->err, CC_ERR_CONFIG, |
| 833 |
|
| "start_scan needs an open filehandle or descriptor", NULL); |
| 834 |
1 |
| sc->rc = CC_ERR_CONFIG; sc->phase = CC_PH_DONE; |
| 835 |
1 |
| goto made; |
| 836 |
|
| } |
| 837 |
3 |
| keep = newSVsv(what); |
| 838 |
3 |
▶ | mode = (CC_HAVE_FD_PASSING && t.path) ? CC_TRANSPORT_FILDES : CC_TRANSPORT_INSTREAM; |
Branch: 1 branch
| Branch | True | False | Total |
| mode = (CC_HAVE_FD_PASSING && t.path) ? CC_TRANSPORT_FILDES : CC_TRANSPORT_INSTREAM; |
1 |
2 |
3 |
|
| 839 |
3 |
▶ | if (mode == CC_TRANSPORT_FILDES) |
Branch: 1 branch
| Branch | True | False | Total |
| if (mode == CC_TRANSPORT_FILDES) |
1 |
2 |
3 |
|
| 840 |
1 |
| (void)cc_scan_start(sc, &t, mode, fd, 0, NULL, 0, -1); |
| 841 |
|
| else |
| 842 |
2 |
| (void)cc_scan_start(sc, &t, mode, -1, 0, NULL, 0, fd); |
| 843 |
|
| } |
| 844 |
|
| else { |
| 845 |
44 |
▶ | if (!SvOK(what)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!SvOK(what)) { |
1 |
43 |
44 |
|
| 846 |
1 |
| cc_err_set(&sc->err, CC_ERR_CONFIG, "start_scan needs bytes", NULL); |
| 847 |
1 |
| sc->rc = CC_ERR_CONFIG; sc->phase = CC_PH_DONE; |
| 848 |
1 |
| goto made; |
| 849 |
|
| } |
| 850 |
|
| /* The bytes are read from the copy the handle keeps, never from |
| 851 |
|
| * the scalar given: that may be a temporary, gone before the |
| 852 |
|
| * first step, and a large one is unmapped memory by then. */ |
| 853 |
43 |
| keep = newSVsv(what); |
| 854 |
43 |
▶ | if (DO_UTF8(keep) && !sv_utf8_downgrade(keep, 1)) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (DO_UTF8(keep) && !sv_utf8_downgrade(keep, 1)) { |
1 |
42 |
43 |
| if (DO_UTF8(keep) && !sv_utf8_downgrade(keep, 1)) { |
1 |
0 |
1 |
| if (DO_UTF8(keep) && !sv_utf8_downgrade(keep, 1)) { |
1 |
0 |
1 |
|
| 855 |
1 |
| SvREFCNT_dec(keep); keep = NULL; |
| 856 |
1 |
| cc_err_set(&sc->err, CC_ERR_CONFIG, |
| 857 |
|
| "start_scan needs bytes, not wide characters", NULL); |
| 858 |
1 |
| sc->rc = CC_ERR_CONFIG; sc->phase = CC_PH_DONE; |
| 859 |
1 |
| goto made; |
| 860 |
|
| } |
| 861 |
42 |
| dp = SvPV_const(keep, dlen); |
| 862 |
42 |
▶ | if (t.max_size && (size_t)dlen > t.max_size) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (t.max_size && (size_t)dlen > t.max_size) { |
2 |
40 |
42 |
| if (t.max_size && (size_t)dlen > t.max_size) { |
1 |
1 |
2 |
|
| 863 |
1 |
| cc_err_set(&sc->err, CC_ERR_TOOBIGLOC, |
| 864 |
|
| "larger than max_size; refused without scanning", NULL); |
| 865 |
1 |
| sc->rc = CC_ERR_TOOBIGLOC; sc->phase = CC_PH_DONE; |
| 866 |
1 |
| goto made; |
| 867 |
|
| } |
| 868 |
41 |
| (void)cc_scan_start(sc, &t, CC_TRANSPORT_INSTREAM, -1, 0, dp, (size_t)dlen, -1); |
| 869 |
|
| } |
| 870 |
|
| |
| 871 |
52 |
| made: |
| 872 |
52 |
| h = newHV(); |
| 873 |
52 |
| (void)hv_stores(h, "_ptr", newSViv(PTR2IV(sc))); |
| 874 |
|
| /* Hold the source alive for as long as the scan can read it. */ |
| 875 |
52 |
▶ | if (keep) (void)hv_stores(h, "_keep", keep); |
Branch: 1 branch
| Branch | True | False | Total |
| if (keep) (void)hv_stores(h, "_keep", keep); |
45 |
7 |
52 |
|
| 876 |
52 |
| RETVAL = sv_bless(newRV_noinc((SV *)h), |
| 877 |
|
| gv_stashpvs("ClamAV::Clamd::Scan", GV_ADD)); |
| 878 |
|
| OUTPUT: |
| 879 |
|
| RETVAL |
| 880 |
|
| |
| 881 |
|
| MODULE = ClamAV::Clamd PACKAGE = ClamAV::Clamd::Scan PREFIX = ccs_ |
| 882 |
|
| |
| 883 |
|
| PROTOTYPES: DISABLE |
| 884 |
|
| |
| 885 |
|
| # The socket to register with a loop. Undef once finished - there is |
| 886 |
|
| # nothing left to watch, and watching a closed descriptor is how a loop |
| 887 |
|
| # ends up dispatching on somebody else's connection. |
| 888 |
|
| void |
| 889 |
|
| ccs_fd(self) |
| 890 |
|
| SV *self |
| 891 |
|
| PREINIT: |
| 892 |
|
| cc_scan *sc; |
| 893 |
|
| PPCODE: |
| 894 |
45 |
| sc = cc_scan_of(aTHX_ self); |
| 895 |
43 |
▶ | if (!sc || sc->sock == CC_INVALID_SOCK) XSRETURN_UNDEF; |
Branch: 2 branches
| Branch | True | False | Total |
| if (!sc || sc->sock == CC_INVALID_SOCK) XSRETURN_UNDEF; |
41 |
2 |
43 |
| if (!sc || sc->sock == CC_INVALID_SOCK) XSRETURN_UNDEF; |
2 |
39 |
41 |
|
| 896 |
39 |
▶ | XPUSHs(sv_2mortal(newSViv(sc->sock))); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(sv_2mortal(newSViv(sc->sock))); |
0 |
39 |
39 |
|
| 897 |
|
| |
| 898 |
|
| # 'read', 'write', or undef when finished. |
| 899 |
|
| void |
| 900 |
|
| ccs_want(self) |
| 901 |
|
| SV *self |
| 902 |
|
| PREINIT: |
| 903 |
|
| cc_scan *sc; |
| 904 |
|
| const char *name; |
| 905 |
|
| PPCODE: |
| 906 |
48 |
| sc = cc_scan_of(aTHX_ self); |
| 907 |
46 |
▶ | if (!sc || sc->phase == CC_PH_DONE) XSRETURN_UNDEF; |
Branch: 2 branches
| Branch | True | False | Total |
| if (!sc || sc->phase == CC_PH_DONE) XSRETURN_UNDEF; |
44 |
2 |
46 |
| if (!sc || sc->phase == CC_PH_DONE) XSRETURN_UNDEF; |
1 |
43 |
44 |
|
| 908 |
43 |
▶ | name = (sc->want == CC_WANT_READ) ? "read" : "write"; |
Branch: 1 branch
| Branch | True | False | Total |
| name = (sc->want == CC_WANT_READ) ? "read" : "write"; |
8 |
35 |
43 |
|
| 909 |
43 |
▶ | XPUSHs(sv_2mortal(newSVpv(name, 0))); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(sv_2mortal(newSVpv(name, 0))); |
0 |
43 |
43 |
|
| 910 |
|
| |
| 911 |
|
| # Advance as far as possible without blocking. True when finished. |
| 912 |
|
| void |
| 913 |
|
| ccs_step(self) |
| 914 |
|
| SV *self |
| 915 |
|
| PREINIT: |
| 916 |
|
| cc_scan *sc; |
| 917 |
|
| PPCODE: |
| 918 |
10054 |
| sc = cc_scan_of(aTHX_ self); |
| 919 |
10052 |
▶ | if (!sc) XSRETURN_YES; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!sc) XSRETURN_YES; |
2 |
10050 |
10052 |
|
| 920 |
10050 |
▶ | if (cc_scan_step(sc) == CC_STEP_DONE) XSRETURN_YES; |
Branch: 1 branch
| Branch | True | False | Total |
| if (cc_scan_step(sc) == CC_STEP_DONE) XSRETURN_YES; |
25 |
10025 |
10050 |
|
| 921 |
10025 |
| XSRETURN_NO; |
| 922 |
|
| |
| 923 |
|
| void |
| 924 |
|
| ccs_is_done(self) |
| 925 |
|
| SV *self |
| 926 |
|
| PREINIT: |
| 927 |
|
| cc_scan *sc; |
| 928 |
|
| PPCODE: |
| 929 |
81 |
| sc = cc_scan_of(aTHX_ self); |
| 930 |
79 |
▶ | if (!sc || sc->phase == CC_PH_DONE) XSRETURN_YES; |
Branch: 2 branches
| Branch | True | False | Total |
| if (!sc || sc->phase == CC_PH_DONE) XSRETURN_YES; |
77 |
2 |
79 |
| if (!sc || sc->phase == CC_PH_DONE) XSRETURN_YES; |
31 |
46 |
77 |
|
| 931 |
46 |
| XSRETURN_NO; |
| 932 |
|
| |
| 933 |
|
| # The verdict, once finished. Undef while the scan is still running - |
| 934 |
|
| # asking early is a question with no answer, not a clean one. |
| 935 |
|
| # |
| 936 |
|
| # Built once and kept. cc_scan_result consumes the reply buffer, so |
| 937 |
|
| # rebuilding on a second call would parse an empty string and quietly |
| 938 |
|
| # return a DIFFERENT verdict from the first - an accessor that changes |
| 939 |
|
| # its answer when you ask twice. |
| 940 |
|
| void |
| 941 |
|
| ccs_verdict(self) |
| 942 |
|
| SV *self |
| 943 |
|
| PREINIT: |
| 944 |
|
| cc_scan *sc; |
| 945 |
|
| HV *h, *dummy; |
| 946 |
|
| SV **cached; |
| 947 |
|
| SV *v; |
| 948 |
|
| PPCODE: |
| 949 |
60 |
▶ | if (!SvROK(self) || SvTYPE(SvRV(self)) != SVt_PVHV) |
Branch: 2 branches
| Branch | True | False | Total |
| if (!SvROK(self) || SvTYPE(SvRV(self)) != SVt_PVHV) |
59 |
1 |
60 |
| if (!SvROK(self) || SvTYPE(SvRV(self)) != SVt_PVHV) |
1 |
58 |
59 |
|
| 950 |
2 |
| croak("ClamAV::Clamd::Scan: not a scan handle"); |
| 951 |
58 |
| h = (HV *)SvRV(self); |
| 952 |
|
| |
| 953 |
58 |
| cached = hv_fetchs(h, "_verdict", 0); |
| 954 |
58 |
▶ | if (cached) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (cached) { |
24 |
34 |
58 |
|
| 955 |
24 |
▶ | XPUSHs(sv_mortalcopy(*cached)); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(sv_mortalcopy(*cached)); |
0 |
24 |
24 |
|
| 956 |
24 |
| XSRETURN(1); |
| 957 |
|
| } |
| 958 |
|
| |
| 959 |
34 |
| sc = cc_scan_of(aTHX_ self); |
| 960 |
34 |
▶ | if (!sc || sc->phase != CC_PH_DONE) XSRETURN_UNDEF; |
Branch: 2 branches
| Branch | True | False | Total |
| if (!sc || sc->phase != CC_PH_DONE) XSRETURN_UNDEF; |
32 |
2 |
34 |
| if (!sc || sc->phase != CC_PH_DONE) XSRETURN_UNDEF; |
1 |
31 |
32 |
|
| 961 |
|
| |
| 962 |
31 |
| dummy = newHV(); |
| 963 |
31 |
| sv_2mortal(newRV_noinc((SV *)dummy)); |
| 964 |
31 |
| v = cc_scan_result(aTHX_ dummy, sc->rc, sc->reply, sc->replylen, |
| 965 |
|
| sc->transport, &sc->err); |
| 966 |
31 |
| sc->reply = NULL; /* cc_scan_result took it */ |
| 967 |
|
| |
| 968 |
31 |
| (void)hv_stores(h, "_verdict", newSVsv(v)); |
| 969 |
31 |
▶ | XPUSHs(v); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(v); |
0 |
31 |
31 |
|
| 970 |
|
| |
| 971 |
|
| # Abandon a scan in flight. |
| 972 |
|
| # |
| 973 |
|
| # The connection is CLOSED, never kept. clamd is still going to answer, |
| 974 |
|
| # and a connection carrying an unread verdict would hand that verdict to |
| 975 |
|
| # whichever scan picked it up next. |
| 976 |
|
| void |
| 977 |
|
| ccs_cancel(self) |
| 978 |
|
| SV *self |
| 979 |
|
| PREINIT: |
| 980 |
|
| cc_scan *sc; |
| 981 |
|
| PPCODE: |
| 982 |
8 |
| sc = cc_scan_of(aTHX_ self); |
| 983 |
6 |
▶ | if (sc) cc_scan_cancel(sc); |
Branch: 1 branch
| Branch | True | False | Total |
| if (sc) cc_scan_cancel(sc); |
4 |
2 |
6 |
|
| 984 |
6 |
| XSRETURN_EMPTY; |
| 985 |
|
| |
| 986 |
|
| MODULE = ClamAV::Clamd PACKAGE = ClamAV::Clamd PREFIX = ccab_ |
| 987 |
|
| |
| 988 |
|
| # Every entry of the table, driven the way a consumer drives it, and every |
| 989 |
|
| # refusal it can give. Private, for the suite: a consumer built outside this |
| 990 |
|
| # dist is somebody else's failing smoker, and the table has to be proven here. |
| 991 |
|
| # |
| 992 |
|
| # Takes a hash: socket or host and port for the target, bytes or fd for the |
| 993 |
|
| # scan, async to drive it on poll, cancel to abandon it first, nolen to ask |
| 994 |
|
| # for the strings without their lengths, and connect_timeout, reply_timeout, |
| 995 |
|
| # reply_max, chunk and max_size as given. Returns key, value pairs. With |
| 996 |
|
| # null set, every entry is called with no handle and the answers come back. |
| 997 |
|
| void |
| 998 |
|
| ccab__abi_probe(opt) |
| 999 |
|
| HV *opt |
| 1000 |
|
| PREINIT: |
| 1001 |
29 |
| const clamd_abi *abi = &CLAMD_ABI; |
| 1002 |
|
| SV **e; |
| 1003 |
29 |
| const char *path = NULL, *host = NULL, *bp = NULL, *str; |
| 1004 |
29 |
| STRLEN blen = 0; |
| 1005 |
29 |
| int port = 0, fd = -1, use_fd = 0, async = 0, cancel = 0, nolen = 0; |
| 1006 |
29 |
| int steps = 0, socket0 = -2, want0 = -1, done0 = -1; |
| 1007 |
29 |
| size_t len = 0, *lp; |
| 1008 |
|
| void *target, *scan; |
| 1009 |
|
| PPCODE: |
| 1010 |
29 |
▶ | if ((e = hv_fetchs(opt, "null", 0)) && SvTRUE(*e)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if ((e = hv_fetchs(opt, "null", 0)) && SvTRUE(*e)) { |
2 |
27 |
29 |
| if ((e = hv_fetchs(opt, "null", 0)) && SvTRUE(*e)) { |
1 |
1 |
2 |
|
| 1011 |
1 |
| abi->target_timeouts(aTHX_ NULL, 1.0, 1.0); |
| 1012 |
1 |
| abi->target_limits(aTHX_ NULL, 1, 1, 1); |
| 1013 |
1 |
| abi->target_free(aTHX_ NULL); |
| 1014 |
1 |
| abi->scan_cancel(aTHX_ NULL); |
| 1015 |
1 |
| abi->scan_free(aTHX_ NULL); |
| 1016 |
1 |
▶ | EXTEND(SP, 11); |
Branch: 1 branch
| Branch | True | False | Total |
| EXTEND(SP, 11); |
0 |
1 |
1 |
|
| 1017 |
1 |
| mPUSHi(abi->scan_socket(aTHX_ NULL)); |
| 1018 |
1 |
| mPUSHi(abi->scan_want(aTHX_ NULL)); |
| 1019 |
1 |
| mPUSHi(abi->scan_step(aTHX_ NULL)); |
| 1020 |
1 |
| mPUSHi(abi->scan_done(aTHX_ NULL)); |
| 1021 |
1 |
| mPUSHi(abi->verdict_state(aTHX_ NULL)); |
| 1022 |
1 |
| mPUSHi(abi->verdict_signature(aTHX_ NULL, NULL) == NULL); |
| 1023 |
1 |
| mPUSHi(abi->verdict_reason(aTHX_ NULL, NULL) == NULL); |
| 1024 |
1 |
| mPUSHi(abi->verdict_error(aTHX_ NULL, NULL) == NULL); |
| 1025 |
1 |
| mPUSHi(abi->verdict_transport(aTHX_ NULL)); |
| 1026 |
1 |
| mPUSHi(abi->scan_fd(aTHX_ NULL, 0) == NULL); |
| 1027 |
1 |
| mPUSHi(abi->scan_mem(aTHX_ NULL, "x", 1) == NULL); |
| 1028 |
1 |
| XSRETURN(11); |
| 1029 |
|
| } |
| 1030 |
|
| |
| 1031 |
51 |
▶ | if ((e = hv_fetchs(opt, "socket", 0)) && SvOK(*e)) path = SvPV_nolen(*e); |
Branch: 2 branches
| Branch | True | False | Total |
| if ((e = hv_fetchs(opt, "socket", 0)) && SvOK(*e)) path = SvPV_nolen(*e); |
24 |
4 |
28 |
| if ((e = hv_fetchs(opt, "socket", 0)) && SvOK(*e)) path = SvPV_nolen(*e); |
23 |
1 |
24 |
|
| 1032 |
33 |
▶ | if ((e = hv_fetchs(opt, "host", 0)) && SvOK(*e)) host = SvPV_nolen(*e); |
Branch: 2 branches
| Branch | True | False | Total |
| if ((e = hv_fetchs(opt, "host", 0)) && SvOK(*e)) host = SvPV_nolen(*e); |
6 |
22 |
28 |
| if ((e = hv_fetchs(opt, "host", 0)) && SvOK(*e)) host = SvPV_nolen(*e); |
5 |
1 |
6 |
|
| 1033 |
28 |
▶ | if ((e = hv_fetchs(opt, "port", 0)) && SvOK(*e)) port = (int)SvIV(*e); |
Branch: 2 branches
| Branch | True | False | Total |
| if ((e = hv_fetchs(opt, "port", 0)) && SvOK(*e)) port = (int)SvIV(*e); |
5 |
23 |
28 |
| if ((e = hv_fetchs(opt, "port", 0)) && SvOK(*e)) port = (int)SvIV(*e); |
4 |
1 |
5 |
|
| 1034 |
28 |
| target = abi->target_new(aTHX_ path, host, port); |
| 1035 |
28 |
▶ | if (!target) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!target) { |
3 |
25 |
28 |
|
| 1036 |
3 |
| mPUSHp("target", 6); |
| 1037 |
3 |
| mPUSHi(0); |
| 1038 |
3 |
| XSRETURN(2); |
| 1039 |
|
| } |
| 1040 |
|
| { |
| 1041 |
25 |
| double ct = 0, rt = 0; |
| 1042 |
25 |
| size_t reply_max = 0, chunk = 0, max_size = 0; |
| 1043 |
25 |
▶ | if ((e = hv_fetchs(opt, "connect_timeout", 0)) && SvOK(*e)) ct = SvNV(*e); |
Branch: 2 branches
| Branch | True | False | Total |
| if ((e = hv_fetchs(opt, "connect_timeout", 0)) && SvOK(*e)) ct = SvNV(*e); |
3 |
22 |
25 |
| if ((e = hv_fetchs(opt, "connect_timeout", 0)) && SvOK(*e)) ct = SvNV(*e); |
2 |
1 |
3 |
|
| 1044 |
25 |
▶ | if ((e = hv_fetchs(opt, "reply_timeout", 0)) && SvOK(*e)) rt = SvNV(*e); |
Branch: 2 branches
| Branch | True | False | Total |
| if ((e = hv_fetchs(opt, "reply_timeout", 0)) && SvOK(*e)) rt = SvNV(*e); |
2 |
23 |
25 |
| if ((e = hv_fetchs(opt, "reply_timeout", 0)) && SvOK(*e)) rt = SvNV(*e); |
1 |
1 |
2 |
|
| 1045 |
25 |
▶ | if ((e = hv_fetchs(opt, "reply_max", 0)) && SvOK(*e)) reply_max = (size_t)SvUV(*e); |
Branch: 2 branches
| Branch | True | False | Total |
| if ((e = hv_fetchs(opt, "reply_max", 0)) && SvOK(*e)) reply_max = (size_t)SvUV(*e); |
2 |
23 |
25 |
| if ((e = hv_fetchs(opt, "reply_max", 0)) && SvOK(*e)) reply_max = (size_t)SvUV(*e); |
1 |
1 |
2 |
|
| 1046 |
25 |
▶ | if ((e = hv_fetchs(opt, "chunk", 0)) && SvOK(*e)) chunk = (size_t)SvUV(*e); |
Branch: 2 branches
| Branch | True | False | Total |
| if ((e = hv_fetchs(opt, "chunk", 0)) && SvOK(*e)) chunk = (size_t)SvUV(*e); |
2 |
23 |
25 |
| if ((e = hv_fetchs(opt, "chunk", 0)) && SvOK(*e)) chunk = (size_t)SvUV(*e); |
1 |
1 |
2 |
|
| 1047 |
25 |
▶ | if ((e = hv_fetchs(opt, "max_size", 0)) && SvOK(*e)) max_size = (size_t)SvUV(*e); |
Branch: 2 branches
| Branch | True | False | Total |
| if ((e = hv_fetchs(opt, "max_size", 0)) && SvOK(*e)) max_size = (size_t)SvUV(*e); |
6 |
19 |
25 |
| if ((e = hv_fetchs(opt, "max_size", 0)) && SvOK(*e)) max_size = (size_t)SvUV(*e); |
5 |
1 |
6 |
|
| 1048 |
25 |
| abi->target_timeouts(aTHX_ target, ct, rt); |
| 1049 |
25 |
| abi->target_limits(aTHX_ target, reply_max, chunk, max_size); |
| 1050 |
|
| } |
| 1051 |
25 |
▶ | if ((e = hv_fetchs(opt, "fd", 0)) && SvOK(*e)) { use_fd = 1; fd = (int)SvIV(*e); } |
Branch: 2 branches
| Branch | True | False | Total |
| if ((e = hv_fetchs(opt, "fd", 0)) && SvOK(*e)) { use_fd = 1; fd = (int)SvIV(*e); } |
9 |
16 |
25 |
| if ((e = hv_fetchs(opt, "fd", 0)) && SvOK(*e)) { use_fd = 1; fd = (int)SvIV(*e); } |
8 |
1 |
9 |
|
| 1052 |
42 |
▶ | if ((e = hv_fetchs(opt, "bytes", 0)) && SvOK(*e)) bp = SvPV(*e, blen); |
Branch: 2 branches
| Branch | True | False | Total |
| if ((e = hv_fetchs(opt, "bytes", 0)) && SvOK(*e)) bp = SvPV(*e, blen); |
18 |
7 |
25 |
| if ((e = hv_fetchs(opt, "bytes", 0)) && SvOK(*e)) bp = SvPV(*e, blen); |
17 |
1 |
18 |
|
| 1053 |
25 |
▶ | async = (e = hv_fetchs(opt, "async", 0)) && SvTRUE(*e); |
Branch: 2 branches
| Branch | True | False | Total |
| async = (e = hv_fetchs(opt, "async", 0)) && SvTRUE(*e); |
4 |
21 |
25 |
| async = (e = hv_fetchs(opt, "async", 0)) && SvTRUE(*e); |
3 |
1 |
4 |
|
| 1054 |
25 |
▶ | cancel = (e = hv_fetchs(opt, "cancel", 0)) && SvTRUE(*e); |
Branch: 2 branches
| Branch | True | False | Total |
| cancel = (e = hv_fetchs(opt, "cancel", 0)) && SvTRUE(*e); |
2 |
23 |
25 |
| cancel = (e = hv_fetchs(opt, "cancel", 0)) && SvTRUE(*e); |
1 |
1 |
2 |
|
| 1055 |
25 |
▶ | nolen = (e = hv_fetchs(opt, "nolen", 0)) && SvTRUE(*e); |
Branch: 2 branches
| Branch | True | False | Total |
| nolen = (e = hv_fetchs(opt, "nolen", 0)) && SvTRUE(*e); |
4 |
21 |
25 |
| nolen = (e = hv_fetchs(opt, "nolen", 0)) && SvTRUE(*e); |
3 |
1 |
4 |
|
| 1056 |
|
| |
| 1057 |
33 |
▶ | if (use_fd) scan = async ? abi->scan_start_fd(aTHX_ target, fd) |
Branch: 1 branch
| Branch | True | False | Total |
| if (use_fd) scan = async ? abi->scan_start_fd(aTHX_ target, fd) |
8 |
17 |
25 |
|
| 1058 |
8 |
▶ | : abi->scan_fd(aTHX_ target, fd); |
Branch: 1 branch
| Branch | True | False | Total |
| : abi->scan_fd(aTHX_ target, fd); |
1 |
7 |
8 |
|
| 1059 |
17 |
| else scan = async ? abi->scan_start_mem(aTHX_ target, bp, (size_t)blen) |
| 1060 |
17 |
▶ | : abi->scan_mem(aTHX_ target, bp, (size_t)blen); |
Branch: 1 branch
| Branch | True | False | Total |
| : abi->scan_mem(aTHX_ target, bp, (size_t)blen); |
2 |
15 |
17 |
|
| 1061 |
25 |
| scan = cc_abi_scan_or_croak(aTHX_ scan, target, "_abi_probe"); |
| 1062 |
|
| |
| 1063 |
25 |
▶ | if (async) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (async) { |
3 |
22 |
25 |
|
| 1064 |
3 |
| socket0 = abi->scan_socket(aTHX_ scan); |
| 1065 |
3 |
| want0 = abi->scan_want(aTHX_ scan); |
| 1066 |
3 |
| done0 = abi->scan_done(aTHX_ scan); |
| 1067 |
3 |
▶ | if (cancel) abi->scan_cancel(aTHX_ scan); |
Branch: 1 branch
| Branch | True | False | Total |
| if (cancel) abi->scan_cancel(aTHX_ scan); |
1 |
2 |
3 |
|
| 1068 |
3 |
| steps = cc_abi_drive(aTHX_ scan); |
| 1069 |
|
| } |
| 1070 |
|
| |
| 1071 |
25 |
▶ | lp = nolen ? NULL : &len; |
Branch: 1 branch
| Branch | True | False | Total |
| lp = nolen ? NULL : &len; |
22 |
3 |
25 |
|
| 1072 |
25 |
▶ | EXTEND(SP, 24); |
Branch: 1 branch
| Branch | True | False | Total |
| EXTEND(SP, 24); |
0 |
25 |
25 |
|
| 1073 |
25 |
| mPUSHp("want_after", 10); mPUSHi(abi->scan_want(aTHX_ scan)); |
| 1074 |
25 |
| mPUSHp("target", 6); mPUSHi(1); |
| 1075 |
25 |
| mPUSHp("state", 5); mPUSHi(abi->verdict_state(aTHX_ scan)); |
| 1076 |
25 |
| mPUSHp("signature", 9); |
| 1077 |
25 |
| str = abi->verdict_signature(aTHX_ scan, lp); |
| 1078 |
25 |
▶ | PUSHs(str ? sv_2mortal(newSVpvn(str, lp ? len : strlen(str))) : &PL_sv_undef); |
Branch: 2 branches
| Branch | True | False | Total |
| PUSHs(str ? sv_2mortal(newSVpvn(str, lp ? len : strlen(str))) : &PL_sv_undef); |
4 |
21 |
25 |
| PUSHs(str ? sv_2mortal(newSVpvn(str, lp ? len : strlen(str))) : &PL_sv_undef); |
2 |
2 |
4 |
|
| 1079 |
25 |
| mPUSHp("reason", 6); |
| 1080 |
25 |
| str = abi->verdict_reason(aTHX_ scan, lp); |
| 1081 |
25 |
▶ | PUSHs(str ? sv_2mortal(newSVpvn(str, lp ? len : strlen(str))) : &PL_sv_undef); |
Branch: 2 branches
| Branch | True | False | Total |
| PUSHs(str ? sv_2mortal(newSVpvn(str, lp ? len : strlen(str))) : &PL_sv_undef); |
5 |
20 |
25 |
| PUSHs(str ? sv_2mortal(newSVpvn(str, lp ? len : strlen(str))) : &PL_sv_undef); |
2 |
3 |
5 |
|
| 1082 |
25 |
| mPUSHp("error", 5); |
| 1083 |
25 |
| str = abi->verdict_error(aTHX_ scan, lp); |
| 1084 |
25 |
▶ | PUSHs(str ? sv_2mortal(newSVpvn(str, lp ? len : strlen(str))) : &PL_sv_undef); |
Branch: 2 branches
| Branch | True | False | Total |
| PUSHs(str ? sv_2mortal(newSVpvn(str, lp ? len : strlen(str))) : &PL_sv_undef); |
10 |
15 |
25 |
| PUSHs(str ? sv_2mortal(newSVpvn(str, lp ? len : strlen(str))) : &PL_sv_undef); |
1 |
9 |
10 |
|
| 1085 |
25 |
| mPUSHp("transport", 9); mPUSHi(abi->verdict_transport(aTHX_ scan)); |
| 1086 |
25 |
| mPUSHp("steps", 5); mPUSHi(steps); |
| 1087 |
25 |
| mPUSHp("socket", 6); mPUSHi(socket0); |
| 1088 |
25 |
| mPUSHp("want", 4); mPUSHi(want0); |
| 1089 |
25 |
| mPUSHp("done", 4); mPUSHi(done0); |
| 1090 |
25 |
| mPUSHp("finished", 8); mPUSHi(abi->scan_done(aTHX_ scan)); |
| 1091 |
|
| |
| 1092 |
25 |
| abi->scan_free(aTHX_ scan); |
| 1093 |
25 |
| abi->target_free(aTHX_ target); |
| 1094 |
|
| |
| 1095 |
|
| MODULE = ClamAV::Clamd PACKAGE = ClamAV::Clamd::Scan PREFIX = ccs_ |
| 1096 |
|
| |
| 1097 |
|
| void |
| 1098 |
|
| ccs_DESTROY(self) |
| 1099 |
|
| SV *self |
| 1100 |
|
| PREINIT: |
| 1101 |
|
| cc_scan *sc; |
| 1102 |
|
| HV *h; |
| 1103 |
|
| PPCODE: |
| 1104 |
56 |
▶ | if (!SvROK(self) || SvTYPE(SvRV(self)) != SVt_PVHV) XSRETURN_EMPTY; |
Branch: 2 branches
| Branch | True | False | Total |
| if (!SvROK(self) || SvTYPE(SvRV(self)) != SVt_PVHV) XSRETURN_EMPTY; |
55 |
1 |
56 |
| if (!SvROK(self) || SvTYPE(SvRV(self)) != SVt_PVHV) XSRETURN_EMPTY; |
1 |
54 |
55 |
|
| 1105 |
54 |
| h = (HV *)SvRV(self); |
| 1106 |
54 |
| sc = cc_scan_of(aTHX_ self); |
| 1107 |
54 |
▶ | if (sc) { cc_scan_free(sc); free(sc); } |
Branch: 1 branch
| Branch | True | False | Total |
| if (sc) { cc_scan_free(sc); free(sc); } |
52 |
2 |
54 |
|
| 1108 |
54 |
| (void)hv_delete(h, "_ptr", 4, G_DISCARD); |
| 1109 |
|
| |
| 1110 |
|
| MODULE = ClamAV::Clamd PACKAGE = ClamAV::Clamd PREFIX = ccab_ |
| 1111 |
|
| |
| 1112 |
|
| PROTOTYPES: DISABLE |
| 1113 |
|
| |
| 1114 |
|
| # The ABI table's address. Private - not public API. |
| 1115 |
|
| # |
| 1116 |
|
| # UV, not IV. An address is unsigned, and PTR2IV hands back a NEGATIVE |
| 1117 |
|
| # integer wherever the shared object maps with the top bit set, so a |
| 1118 |
|
| # consumer's "$ptr > 0" sanity check fails on a perfectly usable pointer. |
| 1119 |
|
| UV |
| 1120 |
|
| ccab__abi_ptr() |
| 1121 |
|
| CODE: |
| 1122 |
4 |
▶ | RETVAL = PTR2UV(&CLAMD_ABI); |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = PTR2UV(&CLAMD_ABI); |
0 |
4 |
4 |
|
| 1123 |
|
| OUTPUT: |
| 1124 |
|
| RETVAL |
| 1125 |
|
| |
| 1126 |
|
| # Drive the table through its own function pointers, so this dist's own |
| 1127 |
|
| # suite exercises the ABI the way a consumer does rather than the way the |
| 1128 |
|
| # XS above happens to. |
| 1129 |
|
| void |
| 1130 |
|
| ccab__abi_selftest(socket_path, bytes) |
| 1131 |
|
| SV *socket_path |
| 1132 |
|
| SV *bytes |
| 1133 |
|
| PREINIT: |
| 1134 |
6 |
| const clamd_abi *abi = &CLAMD_ABI; |
| 1135 |
|
| void *target, *scan; |
| 1136 |
|
| const char *sig; |
| 1137 |
6 |
| size_t siglen = 0; |
| 1138 |
|
| STRLEN blen; |
| 1139 |
|
| const char *bp; |
| 1140 |
|
| PPCODE: |
| 1141 |
6 |
▶ | if (!SvOK(socket_path)) croak("_abi_selftest: need a socket path"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!SvOK(socket_path)) croak("_abi_selftest: need a socket path"); |
1 |
5 |
6 |
|
| 1142 |
5 |
| bp = SvPV(bytes, blen); |
| 1143 |
|
| |
| 1144 |
10 |
▶ | target = abi->target_new(aTHX_ SvPV_nolen(socket_path), NULL, 0); |
Branch: 1 branch
| Branch | True | False | Total |
| target = abi->target_new(aTHX_ SvPV_nolen(socket_path), NULL, 0); |
5 |
0 |
5 |
|
| 1145 |
5 |
▶ | if (!target) croak("_abi_selftest: target_new failed"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!target) croak("_abi_selftest: target_new failed"); |
1 |
4 |
5 |
|
| 1146 |
4 |
| abi->target_timeouts(aTHX_ target, 5.0, 30.0); |
| 1147 |
|
| |
| 1148 |
4 |
| scan = cc_abi_scan_or_croak(aTHX_ abi->scan_mem(aTHX_ target, bp, (size_t)blen), target, "_abi_selftest"); |
| 1149 |
|
| |
| 1150 |
4 |
| sig = abi->verdict_signature(aTHX_ scan, &siglen); |
| 1151 |
|
| |
| 1152 |
4 |
▶ | EXTEND(SP, 4); |
Branch: 1 branch
| Branch | True | False | Total |
| EXTEND(SP, 4); |
0 |
4 |
4 |
|
| 1153 |
4 |
| PUSHs(sv_2mortal(newSViv(abi->abi_version))); |
| 1154 |
4 |
| PUSHs(sv_2mortal(newSViv(abi->verdict_state(aTHX_ scan)))); |
| 1155 |
4 |
▶ | PUSHs(sig ? sv_2mortal(newSVpvn(sig, siglen)) : &PL_sv_undef); |
Branch: 1 branch
| Branch | True | False | Total |
| PUSHs(sig ? sv_2mortal(newSVpvn(sig, siglen)) : &PL_sv_undef); |
2 |
2 |
4 |
|
| 1156 |
4 |
| PUSHs(sv_2mortal(newSViv(abi->verdict_transport(aTHX_ scan)))); |
| 1157 |
|
| |
| 1158 |
4 |
| abi->scan_free(aTHX_ scan); |
| 1159 |
4 |
| abi->target_free(aTHX_ target); |