Coverage Report

Created: 2025-11-15 06:14

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/quickjs/fuzz/fuzz_regexp.c
Line
Count
Source
1
/* Copyright 2020 Google Inc.
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
16
#include "libregexp.h"
17
#include "quickjs-libc.h"
18
19
static int nbinterrupts = 0;
20
21
338k
int lre_check_stack_overflow(void *opaque, size_t alloca_size) { return 0; }
22
23
void *lre_realloc(void *opaque, void *ptr, size_t size)
24
3.43M
{
25
3.43M
    return realloc(ptr, size);
26
3.43M
}
27
28
int lre_check_timeout(void *opaque)
29
183
 {
30
183
    nbinterrupts++;
31
183
    return (nbinterrupts > 100);
32
183
 }
33
34
7.15k
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
35
7.15k
    int len, ret, i;
36
7.15k
    uint8_t *bc;
37
7.15k
    char error_msg[64];
38
7.15k
    const uint8_t *input;
39
7.15k
    uint8_t *capture[255 * 2];
40
7.15k
    size_t size1 = size;
41
42
    //Splits buffer into 2 sub buffers delimited by null character
43
2.66M
    for (i = 0; i < size; i++) {
44
2.66M
        if (data[i] == 0) {
45
7.14k
            size1 = i;
46
7.14k
            break;
47
7.14k
        }
48
2.66M
    }
49
7.15k
    if (size1 == size) {
50
        //missing delimiter
51
11
        return 0;
52
11
    }
53
7.14k
    bc = lre_compile(&len, error_msg, sizeof(error_msg), (const char *) data,
54
7.14k
                     size1, 0, NULL);
55
7.14k
    if (!bc) {
56
3.68k
        return 0;
57
3.68k
    }
58
3.46k
    input = data + size1 + 1;
59
3.46k
    ret = lre_exec(capture, bc, input, 0, size - (size1 + 1), 0, NULL);
60
3.46k
    if (ret == 1) {
61
738
        lre_get_capture_count(bc);
62
738
    }
63
3.46k
    free(bc);
64
65
3.46k
    return 0;
66
7.14k
}