/src/gpsd/fuzzer/FuzzClient.c
Line | Count | Source |
1 | | /* Copyright 2026 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 <stdint.h> |
14 | | #include <stddef.h> |
15 | | #include <string.h> |
16 | | #include <stdlib.h> |
17 | | #include "gpsd_config.h" |
18 | | #include "gpsd.h" |
19 | | #include "gps_json.h" |
20 | | |
21 | 1.53k | int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { |
22 | | /* Production uses null-terminated buffers from recv() - replicate that here */ |
23 | 1.53k | char *input = (char *)malloc(Size + 1); |
24 | 1.53k | if (!input) return 0; |
25 | 1.53k | memcpy(input, Data, Size); |
26 | 1.53k | input[Size] = '\0'; |
27 | | |
28 | | /* Allocate structures for parsed data */ |
29 | 1.53k | struct gps_policy_t policy; |
30 | 1.53k | struct devconfig_t devconf; |
31 | 1.53k | memset(&policy, 0, sizeof(policy)); |
32 | 1.53k | memset(&devconf, 0, sizeof(devconf)); |
33 | | |
34 | | /* Test json_watch_read() - parses ?WATCH command JSON */ |
35 | 1.53k | json_watch_read(input, &policy, NULL); |
36 | | |
37 | | /* Test json_device_read() - parses ?DEVICE command JSON */ |
38 | 1.53k | json_device_read(input, &devconf, NULL); |
39 | | |
40 | | /* Test parse_uri_dest() - if device path was populated */ |
41 | 1.53k | if (strlen(policy.devpath) > 0) { |
42 | 46 | char uri[GPS_PATH_MAX]; |
43 | 46 | char *h = NULL, *s = NULL, *d = NULL; |
44 | 46 | strlcpy(uri, policy.devpath, sizeof(uri)); |
45 | 46 | parse_uri_dest(uri, &h, &s, &d); |
46 | 46 | } |
47 | | |
48 | 1.53k | free(input); |
49 | 1.53k | return 0; |
50 | 1.53k | } |