Coverage Report

Created: 2025-11-24 07:11

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
12.2k
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
2.76M
{
25
2.76M
    return realloc(ptr, size);
26
2.76M
}
27
28
int lre_check_timeout(void *opaque)
29
0
 {
30
0
    nbinterrupts++;
31
0
    return (nbinterrupts > 100);
32
0
 }
33
34
12
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
35
12
    int len, ret, i;
36
12
    uint8_t *bc;
37
12
    char error_msg[64];
38
12
    const uint8_t *input;
39
12
    uint8_t *capture[255 * 2];
40
12
    size_t size1 = size;
41
42
    //Splits buffer into 2 sub buffers delimited by null character
43
1.26M
    for (i = 0; i < size; i++) {
44
1.26M
        if (data[i] == 0) {
45
10
            size1 = i;
46
10
            break;
47
10
        }
48
1.26M
    }
49
12
    if (size1 == size) {
50
        //missing delimiter
51
2
        return 0;
52
2
    }
53
10
    bc = lre_compile(&len, error_msg, sizeof(error_msg), (const char *) data,
54
10
                     size1, 0, NULL);
55
10
    if (!bc) {
56
5
        return 0;
57
5
    }
58
5
    input = data + size1 + 1;
59
5
    ret = lre_exec(capture, bc, input, 0, size - (size1 + 1), 0, NULL);
60
5
    if (ret == 1) {
61
5
        lre_get_capture_count(bc);
62
5
    }
63
5
    free(bc);
64
65
5
    return 0;
66
10
}