• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 # Copyright 2021 Google LLC
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 #      http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 #
16 ################################################################################
17 */
18 
19 #include <stdint.h>
20 #include <stdlib.h>
21 #include <string.h>
22 
23 #include "xmlnode.h"
24 #include "caps.h"
25 
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)26 int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
27   char *malicious_xml = (char *)malloc(size + 1);
28   if (malicious_xml == NULL) {
29     return 0;
30   }
31   memcpy(malicious_xml, data, size);
32   malicious_xml[size] = '\0';
33 
34   xmlnode *isc = xmlnode_from_str(malicious_xml, size+1);
35   if (isc != NULL) {
36     xmlnode_set_attrib(isc, "name", "query");
37 
38     // Parse Jabber caps
39     JabberCapsClientInfo *info = jabber_caps_parse_client_info(isc);
40     gchar *got_hash = jabber_caps_calculate_hash(info, ("sha1"));
41 
42     // Insert a child
43     xmlnode *child = xmlnode_new_child(isc, "query");
44     xmlnode_insert_child(isc, child);
45 
46     // Get data
47     char *retrieved_data = xmlnode_get_data(isc);
48     char *retrieved_data_unescaped = xmlnode_get_data_unescaped(isc);
49 
50     xmlnode_free(isc);
51   }
52 
53   free(malicious_xml);
54   return 0;
55 }