/src/yaml_write_handler.h
Line | Count | Source |
1 | | // Copyright 2020 Google LLC |
2 | | // |
3 | | // Licensed under the Apache License, Version 2.0 (the "License"); |
4 | | // you may not use this file except in compliance with the License. |
5 | | // You may obtain a copy of the License at |
6 | | // |
7 | | // http://www.apache.org/licenses/LICENSE-2.0 |
8 | | // |
9 | | // Unless required by applicable law or agreed to in writing, software |
10 | | // distributed under the License is distributed on an "AS IS" BASIS, |
11 | | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | | // See the License for the specific language governing permissions and |
13 | | // limitations under the License. |
14 | | |
15 | | #ifndef YAML_WRITE_HANDLER_H_ |
16 | | #define YAML_WRITE_HANDLER_H_ |
17 | | |
18 | | typedef struct yaml_output_buffer { |
19 | | unsigned char *buf; |
20 | | size_t size; |
21 | | size_t capacity; |
22 | | } yaml_output_buffer_t; |
23 | | |
24 | 928k | static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) { |
25 | 928k | size_t newsize; |
26 | 928k | yaml_output_buffer_t *out = (yaml_output_buffer_t *)data; |
27 | | |
28 | | /* Double buffer size whenever necessary */ |
29 | 928k | if (out->size + size >= out->capacity) { |
30 | 34.4k | newsize = out->capacity << 1; |
31 | 34.4k | if (newsize < out->size + size) { |
32 | 8.69k | newsize = out->size + size; |
33 | 8.69k | } |
34 | 34.4k | out->buf = (unsigned char *)realloc(out->buf, newsize); |
35 | 34.4k | out->capacity = newsize; |
36 | 34.4k | } |
37 | 928k | if (!out->buf) { |
38 | 24.1k | out->size = 0; |
39 | 24.1k | return 0; |
40 | 24.1k | } |
41 | | |
42 | 903k | memcpy(out->buf + out->size, buffer, size); |
43 | 903k | out->size += size; |
44 | 903k | return 1; |
45 | 928k | } libyaml_reformatter_alt_fuzzer.c:yaml_write_handler Line | Count | Source | 24 | 248k | static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) { | 25 | 248k | size_t newsize; | 26 | 248k | yaml_output_buffer_t *out = (yaml_output_buffer_t *)data; | 27 | | | 28 | | /* Double buffer size whenever necessary */ | 29 | 248k | if (out->size + size >= out->capacity) { | 30 | 6.45k | newsize = out->capacity << 1; | 31 | 6.45k | if (newsize < out->size + size) { | 32 | 1.32k | newsize = out->size + size; | 33 | 1.32k | } | 34 | 6.45k | out->buf = (unsigned char *)realloc(out->buf, newsize); | 35 | 6.45k | out->capacity = newsize; | 36 | 6.45k | } | 37 | 248k | if (!out->buf) { | 38 | 5.25k | out->size = 0; | 39 | 5.25k | return 0; | 40 | 5.25k | } | 41 | | | 42 | 243k | memcpy(out->buf + out->size, buffer, size); | 43 | 243k | out->size += size; | 44 | 243k | return 1; | 45 | 248k | } |
libyaml_deconstructor_alt_fuzzer.c:yaml_write_handler Line | Count | Source | 24 | 36.8k | static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) { | 25 | 36.8k | size_t newsize; | 26 | 36.8k | yaml_output_buffer_t *out = (yaml_output_buffer_t *)data; | 27 | | | 28 | | /* Double buffer size whenever necessary */ | 29 | 36.8k | if (out->size + size >= out->capacity) { | 30 | 5.16k | newsize = out->capacity << 1; | 31 | 5.16k | if (newsize < out->size + size) { | 32 | 1.68k | newsize = out->size + size; | 33 | 1.68k | } | 34 | 5.16k | out->buf = (unsigned char *)realloc(out->buf, newsize); | 35 | 5.16k | out->capacity = newsize; | 36 | 5.16k | } | 37 | 36.8k | if (!out->buf) { | 38 | 2.59k | out->size = 0; | 39 | 2.59k | return 0; | 40 | 2.59k | } | 41 | | | 42 | 34.2k | memcpy(out->buf + out->size, buffer, size); | 43 | 34.2k | out->size += size; | 44 | 34.2k | return 1; | 45 | 36.8k | } |
libyaml_reformatter_fuzzer.c:yaml_write_handler Line | Count | Source | 24 | 396k | static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) { | 25 | 396k | size_t newsize; | 26 | 396k | yaml_output_buffer_t *out = (yaml_output_buffer_t *)data; | 27 | | | 28 | | /* Double buffer size whenever necessary */ | 29 | 396k | if (out->size + size >= out->capacity) { | 30 | 5.65k | newsize = out->capacity << 1; | 31 | 5.65k | if (newsize < out->size + size) { | 32 | 1.24k | newsize = out->size + size; | 33 | 1.24k | } | 34 | 5.65k | out->buf = (unsigned char *)realloc(out->buf, newsize); | 35 | 5.65k | out->capacity = newsize; | 36 | 5.65k | } | 37 | 396k | if (!out->buf) { | 38 | 4.45k | out->size = 0; | 39 | 4.45k | return 0; | 40 | 4.45k | } | 41 | | | 42 | 392k | memcpy(out->buf + out->size, buffer, size); | 43 | 392k | out->size += size; | 44 | 392k | return 1; | 45 | 396k | } |
libyaml_deconstructor_fuzzer.c:yaml_write_handler Line | Count | Source | 24 | 28.7k | static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) { | 25 | 28.7k | size_t newsize; | 26 | 28.7k | yaml_output_buffer_t *out = (yaml_output_buffer_t *)data; | 27 | | | 28 | | /* Double buffer size whenever necessary */ | 29 | 28.7k | if (out->size + size >= out->capacity) { | 30 | 4.06k | newsize = out->capacity << 1; | 31 | 4.06k | if (newsize < out->size + size) { | 32 | 1.35k | newsize = out->size + size; | 33 | 1.35k | } | 34 | 4.06k | out->buf = (unsigned char *)realloc(out->buf, newsize); | 35 | 4.06k | out->capacity = newsize; | 36 | 4.06k | } | 37 | 28.7k | if (!out->buf) { | 38 | 2.60k | out->size = 0; | 39 | 2.60k | return 0; | 40 | 2.60k | } | 41 | | | 42 | 26.1k | memcpy(out->buf + out->size, buffer, size); | 43 | 26.1k | out->size += size; | 44 | 26.1k | return 1; | 45 | 28.7k | } |
libyaml_dumper_fuzzer.c:yaml_write_handler Line | Count | Source | 24 | 99.1k | static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) { | 25 | 99.1k | size_t newsize; | 26 | 99.1k | yaml_output_buffer_t *out = (yaml_output_buffer_t *)data; | 27 | | | 28 | | /* Double buffer size whenever necessary */ | 29 | 99.1k | if (out->size + size >= out->capacity) { | 30 | 7.18k | newsize = out->capacity << 1; | 31 | 7.18k | if (newsize < out->size + size) { | 32 | 1.67k | newsize = out->size + size; | 33 | 1.67k | } | 34 | 7.18k | out->buf = (unsigned char *)realloc(out->buf, newsize); | 35 | 7.18k | out->capacity = newsize; | 36 | 7.18k | } | 37 | 99.1k | if (!out->buf) { | 38 | 5.22k | out->size = 0; | 39 | 5.22k | return 0; | 40 | 5.22k | } | 41 | | | 42 | 93.9k | memcpy(out->buf + out->size, buffer, size); | 43 | 93.9k | out->size += size; | 44 | 93.9k | return 1; | 45 | 99.1k | } |
libyaml_emitter_fuzzer.c:yaml_write_handler Line | Count | Source | 24 | 117k | static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) { | 25 | 117k | size_t newsize; | 26 | 117k | yaml_output_buffer_t *out = (yaml_output_buffer_t *)data; | 27 | | | 28 | | /* Double buffer size whenever necessary */ | 29 | 117k | if (out->size + size >= out->capacity) { | 30 | 5.96k | newsize = out->capacity << 1; | 31 | 5.96k | if (newsize < out->size + size) { | 32 | 1.41k | newsize = out->size + size; | 33 | 1.41k | } | 34 | 5.96k | out->buf = (unsigned char *)realloc(out->buf, newsize); | 35 | 5.96k | out->capacity = newsize; | 36 | 5.96k | } | 37 | 117k | if (!out->buf) { | 38 | 3.99k | out->size = 0; | 39 | 3.99k | return 0; | 40 | 3.99k | } | 41 | | | 42 | 113k | memcpy(out->buf + out->size, buffer, size); | 43 | 113k | out->size += size; | 44 | 113k | return 1; | 45 | 117k | } |
|
46 | | |
47 | | #endif // YAML_WRITE_HANDLER_H_ |