/src/xmlsec/apps/oss-fuzz/xmlsec_target.c
Line | Count | Source |
1 | | #include <stdint.h> |
2 | | #include <stddef.h> |
3 | | |
4 | | #include <xmlsec/buffer.h> |
5 | | #include <xmlsec/parser.h> |
6 | | |
7 | | int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size); |
8 | | |
9 | 2.41M | static void ignore(void* ctx, const char* msg, ...) { |
10 | | /* Error handler to avoid spam of error messages from libxml parser. */ |
11 | 2.41M | (void)ctx; |
12 | 2.41M | (void)msg; |
13 | 2.41M | } |
14 | | |
15 | 20.6k | int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { |
16 | 20.6k | xmlSetGenericErrorFunc(NULL, &ignore); |
17 | 20.6k | xmlSecBufferPtr buf = xmlSecBufferCreate(size); |
18 | 20.6k | if(buf == NULL) { |
19 | 0 | return 0; |
20 | 0 | } |
21 | 20.6k | if(xmlSecBufferSetData(buf, data, size) < 0) { |
22 | 0 | xmlSecBufferDestroy(buf); |
23 | 0 | return 0; |
24 | 0 | } |
25 | 20.6k | xmlDocPtr doc = xmlSecParseMemory(xmlSecBufferGetData(buf), |
26 | 20.6k | xmlSecBufferGetSize(buf), 0); |
27 | | |
28 | 20.6k | if (doc != NULL) xmlFreeDoc(doc); |
29 | 20.6k | xmlSecBufferDestroy(buf); |
30 | 20.6k | return 0; |
31 | 20.6k | } |