/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 | 1.17M | static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) { |
25 | 1.17M | size_t newsize; |
26 | 1.17M | yaml_output_buffer_t *out = (yaml_output_buffer_t *)data; |
27 | | |
28 | | /* Double buffer size whenever necessary */ |
29 | 1.17M | if (out->size + size >= out->capacity) { |
30 | 34.4k | newsize = out->capacity << 1; |
31 | 34.4k | if (newsize < out->size + size) { |
32 | 8.47k | newsize = out->size + size; |
33 | 8.47k | } |
34 | 34.4k | out->buf = (unsigned char *)realloc(out->buf, newsize); |
35 | 34.4k | out->capacity = newsize; |
36 | 34.4k | } |
37 | 1.17M | if (!out->buf) { |
38 | 23.0k | out->size = 0; |
39 | 23.0k | return 0; |
40 | 23.0k | } |
41 | | |
42 | 1.15M | memcpy(out->buf + out->size, buffer, size); |
43 | 1.15M | out->size += size; |
44 | 1.15M | return 1; |
45 | 1.17M | } libyaml_reformatter_alt_fuzzer.c:yaml_write_handler Line | Count | Source | 24 | 315k | static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) { | 25 | 315k | size_t newsize; | 26 | 315k | yaml_output_buffer_t *out = (yaml_output_buffer_t *)data; | 27 | | | 28 | | /* Double buffer size whenever necessary */ | 29 | 315k | if (out->size + size >= out->capacity) { | 30 | 6.19k | newsize = out->capacity << 1; | 31 | 6.19k | if (newsize < out->size + size) { | 32 | 1.26k | newsize = out->size + size; | 33 | 1.26k | } | 34 | 6.19k | out->buf = (unsigned char *)realloc(out->buf, newsize); | 35 | 6.19k | out->capacity = newsize; | 36 | 6.19k | } | 37 | 315k | if (!out->buf) { | 38 | 4.95k | out->size = 0; | 39 | 4.95k | return 0; | 40 | 4.95k | } | 41 | | | 42 | 310k | memcpy(out->buf + out->size, buffer, size); | 43 | 310k | out->size += size; | 44 | 310k | return 1; | 45 | 315k | } |
libyaml_deconstructor_alt_fuzzer.c:yaml_write_handler Line | Count | Source | 24 | 40.1k | static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) { | 25 | 40.1k | size_t newsize; | 26 | 40.1k | yaml_output_buffer_t *out = (yaml_output_buffer_t *)data; | 27 | | | 28 | | /* Double buffer size whenever necessary */ | 29 | 40.1k | if (out->size + size >= out->capacity) { | 30 | 5.04k | newsize = out->capacity << 1; | 31 | 5.04k | if (newsize < out->size + size) { | 32 | 1.62k | newsize = out->size + size; | 33 | 1.62k | } | 34 | 5.04k | out->buf = (unsigned char *)realloc(out->buf, newsize); | 35 | 5.04k | out->capacity = newsize; | 36 | 5.04k | } | 37 | 40.1k | if (!out->buf) { | 38 | 2.46k | out->size = 0; | 39 | 2.46k | return 0; | 40 | 2.46k | } | 41 | | | 42 | 37.6k | memcpy(out->buf + out->size, buffer, size); | 43 | 37.6k | out->size += size; | 44 | 37.6k | return 1; | 45 | 40.1k | } |
libyaml_reformatter_fuzzer.c:yaml_write_handler Line | Count | Source | 24 | 467k | static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) { | 25 | 467k | size_t newsize; | 26 | 467k | yaml_output_buffer_t *out = (yaml_output_buffer_t *)data; | 27 | | | 28 | | /* Double buffer size whenever necessary */ | 29 | 467k | if (out->size + size >= out->capacity) { | 30 | 5.50k | newsize = out->capacity << 1; | 31 | 5.50k | if (newsize < out->size + size) { | 32 | 1.21k | newsize = out->size + size; | 33 | 1.21k | } | 34 | 5.50k | out->buf = (unsigned char *)realloc(out->buf, newsize); | 35 | 5.50k | out->capacity = newsize; | 36 | 5.50k | } | 37 | 467k | if (!out->buf) { | 38 | 4.26k | out->size = 0; | 39 | 4.26k | return 0; | 40 | 4.26k | } | 41 | | | 42 | 462k | memcpy(out->buf + out->size, buffer, size); | 43 | 462k | out->size += size; | 44 | 462k | return 1; | 45 | 467k | } |
libyaml_deconstructor_fuzzer.c:yaml_write_handler Line | Count | Source | 24 | 35.4k | static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) { | 25 | 35.4k | size_t newsize; | 26 | 35.4k | yaml_output_buffer_t *out = (yaml_output_buffer_t *)data; | 27 | | | 28 | | /* Double buffer size whenever necessary */ | 29 | 35.4k | if (out->size + size >= out->capacity) { | 30 | 4.08k | newsize = out->capacity << 1; | 31 | 4.08k | if (newsize < out->size + size) { | 32 | 1.30k | newsize = out->size + size; | 33 | 1.30k | } | 34 | 4.08k | out->buf = (unsigned char *)realloc(out->buf, newsize); | 35 | 4.08k | out->capacity = newsize; | 36 | 4.08k | } | 37 | 35.4k | if (!out->buf) { | 38 | 2.47k | out->size = 0; | 39 | 2.47k | return 0; | 40 | 2.47k | } | 41 | | | 42 | 32.9k | memcpy(out->buf + out->size, buffer, size); | 43 | 32.9k | out->size += size; | 44 | 32.9k | return 1; | 45 | 35.4k | } |
libyaml_dumper_fuzzer.c:yaml_write_handler Line | Count | Source | 24 | 144k | static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) { | 25 | 144k | size_t newsize; | 26 | 144k | yaml_output_buffer_t *out = (yaml_output_buffer_t *)data; | 27 | | | 28 | | /* Double buffer size whenever necessary */ | 29 | 144k | if (out->size + size >= out->capacity) { | 30 | 7.20k | newsize = out->capacity << 1; | 31 | 7.20k | if (newsize < out->size + size) { | 32 | 1.60k | newsize = out->size + size; | 33 | 1.60k | } | 34 | 7.20k | out->buf = (unsigned char *)realloc(out->buf, newsize); | 35 | 7.20k | out->capacity = newsize; | 36 | 7.20k | } | 37 | 144k | if (!out->buf) { | 38 | 4.75k | out->size = 0; | 39 | 4.75k | return 0; | 40 | 4.75k | } | 41 | | | 42 | 139k | memcpy(out->buf + out->size, buffer, size); | 43 | 139k | out->size += size; | 44 | 139k | return 1; | 45 | 144k | } |
libyaml_emitter_fuzzer.c:yaml_write_handler Line | Count | Source | 24 | 177k | static int yaml_write_handler(void *data, unsigned char *buffer, size_t size) { | 25 | 177k | size_t newsize; | 26 | 177k | yaml_output_buffer_t *out = (yaml_output_buffer_t *)data; | 27 | | | 28 | | /* Double buffer size whenever necessary */ | 29 | 177k | if (out->size + size >= out->capacity) { | 30 | 6.37k | newsize = out->capacity << 1; | 31 | 6.37k | if (newsize < out->size + size) { | 32 | 1.46k | newsize = out->size + size; | 33 | 1.46k | } | 34 | 6.37k | out->buf = (unsigned char *)realloc(out->buf, newsize); | 35 | 6.37k | out->capacity = newsize; | 36 | 6.37k | } | 37 | 177k | if (!out->buf) { | 38 | 4.11k | out->size = 0; | 39 | 4.11k | return 0; | 40 | 4.11k | } | 41 | | | 42 | 173k | memcpy(out->buf + out->size, buffer, size); | 43 | 173k | out->size += size; | 44 | 173k | return 1; | 45 | 177k | } |
|
46 | | |
47 | | #endif // YAML_WRITE_HANDLER_H_ |