Line | Count | Source (jump to first uncovered line) |
1 | | /* Copyright 2021 Google LLC |
2 | | Licensed under the Apache License, Version 2.0 (the "License"); |
3 | | you may not use this file except in compliance with the License. |
4 | | You may obtain a copy of the License at |
5 | | http://www.apache.org/licenses/LICENSE-2.0 |
6 | | Unless required by applicable law or agreed to in writing, software |
7 | | distributed under the License is distributed on an "AS IS" BASIS, |
8 | | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
9 | | See the License for the specific language governing permissions and |
10 | | limitations under the License. |
11 | | */ |
12 | | |
13 | | #include <sys_defs.h> |
14 | | #include <stdarg.h> |
15 | | #include <ctype.h> |
16 | | #include <string.h> |
17 | | |
18 | | #include <mymalloc.h> |
19 | | #include <msg.h> |
20 | | #include <vstring.h> |
21 | | |
22 | | #include <rec_type.h> |
23 | | #include <is_header.h> |
24 | | #include <header_opts.h> |
25 | | #include <mail_params.h> |
26 | | #include <header_token.h> |
27 | | #include <lex_822.h> |
28 | | #include <mime_state.h> |
29 | | |
30 | | #include <stdlib.h> |
31 | | #include <stdint.h> |
32 | | #include <stringops.h> |
33 | | #include <vstream.h> |
34 | | #include <msg_vstream.h> |
35 | | #include <rec_streamlf.h> |
36 | | |
37 | | int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size); |
38 | | |
39 | | // Define empty callback functions |
40 | | static void head_out(void *context, int class, const HEADER_OPTS *unused_info, |
41 | 0 | VSTRING *buf, off_t offset) {} |
42 | 84 | static void head_end(void *context) {} |
43 | 0 | static void body_end(void *context) {} |
44 | | static void err_print(void *unused_context, int err_flag, const char *text, |
45 | 36 | ssize_t len) {} |
46 | | static void body_out(void *context, int rec_type, const char *buf, ssize_t len, |
47 | 168 | off_t offset) {} |
48 | | |
49 | 1.95k | int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { |
50 | 1.95k | char *new_str = (char *)malloc(size + 1); |
51 | 1.95k | if (new_str == NULL) { |
52 | 0 | return 0; |
53 | 0 | } |
54 | 1.95k | memcpy(new_str, data, size); |
55 | 1.95k | new_str[size] = '\0'; |
56 | | |
57 | 1.95k | #define MIME_OPTIONS \ |
58 | 1.95k | (MIME_OPT_REPORT_8BIT_IN_7BIT_BODY | MIME_OPT_REPORT_8BIT_IN_HEADER | \ |
59 | 1.95k | MIME_OPT_REPORT_ENCODING_DOMAIN | MIME_OPT_REPORT_TRUNC_HEADER | \ |
60 | 1.95k | MIME_OPT_REPORT_NESTING | MIME_OPT_DOWNGRADE) |
61 | | |
62 | 1.95k | int rec_type = REC_TYPE_NORM; |
63 | 1.95k | int err; |
64 | | |
65 | | // Simple single call of mime_state_update for now. |
66 | 1.95k | MIME_STATE *state; |
67 | 1.95k | msg_vstream_init("fuzz_mime", VSTREAM_OUT); |
68 | 1.95k | state = mime_state_alloc(MIME_OPTIONS, head_out, head_end, body_out, body_end, |
69 | 1.95k | err_print, (void *)VSTREAM_OUT); |
70 | 1.95k | mime_state_update(state, rec_type, new_str, size); |
71 | 1.95k | mime_state_free(state); |
72 | | |
73 | 1.95k | free(new_str); |
74 | 1.95k | return 0; |
75 | 1.95k | } |