Coverage Report

Created: 2025-07-12 06:36

/src/gpsd/fuzzer/FuzzPacket.c
Line
Count
Source
1
/* Copyright 2022 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 "gpsd_config.h"  /* must be before all includes */
14
15
#include <stdio.h>
16
#include <stdlib.h>
17
#include <fcntl.h>
18
#include <unistd.h>
19
20
#include "gpsd.h"
21
22
11.4k
#define kMinInputLength 10
23
5.70k
#define kMaxInputLength 9216
24
25
extern int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) 
26
5.70k
{//gpsd/tests//test_packet.c
27
28
5.70k
    if (Size < kMinInputLength || Size > kMaxInputLength){
29
24
        return 0;
30
24
    }
31
32
5.68k
    {
33
5.68k
        struct gpsd_errout_t errout;
34
5.68k
        struct gps_lexer_t lexer;
35
36
5.68k
        lexer_init(&lexer, &errout);
37
5.68k
        lexer.errout.debug = 0;
38
39
5.68k
        memcpy(lexer.inbufptr = lexer.inbuffer, Data, Size);
40
5.68k
        lexer.inbuflen = Size;
41
42
5.68k
        packet_parse(&lexer);
43
5.68k
    }
44
5.68k
    {
45
5.68k
        struct gpsd_errout_t errout;
46
5.68k
        struct gps_lexer_t lexer;
47
5.68k
        int nullfd = open("/dev/null", O_RDONLY);
48
5.68k
        ssize_t st;
49
50
5.68k
        lexer_init(&lexer, &errout);
51
5.68k
        lexer.errout.debug = 0;
52
53
5.68k
        memcpy(lexer.inbufptr = lexer.inbuffer, Data, Size);
54
5.68k
        lexer.inbuflen = Size;
55
56
55.1k
        do {
57
55.1k
            st = packet_get(nullfd, &lexer);
58
55.1k
        } while (st > 0);
59
60
5.68k
        close(nullfd);
61
5.68k
    }
62
63
5.68k
    return 0;
64
5.70k
}