File: fuzz_kms.c

package info (click to toggle)
libmongocrypt 1.17.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 12,572 kB
  • sloc: ansic: 70,067; python: 4,547; cpp: 615; sh: 460; makefile: 44; awk: 8
file content (43 lines) | stat: -rw-r--r-- 1,186 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include "kms_message/kms_message.h"
#include "kms_message_private.h"
#include <src/hexlify.h>
#include <src/kms_kv_list.h>
#include <src/kms_message/kms_b64.h>
#include <src/kms_port.h>
#include <src/kms_request_str.h>
#include <stdio.h>
#include <stdlib.h>

/* Fuzzer for targeted the kms_response_parser_feed and
 * kms_request_new functions.
 */
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
    kms_response_parser_t *parser = NULL;
    parser = kms_response_parser_new();
    if (parser != NULL) {
        kms_response_parser_feed(parser, data, size);
        kms_response_parser_destroy(parser);
    }

    if (size > 50) {
        /* Create two null-terminated strings */
        char *method = malloc(25);
        memcpy(method, data, 24);
        method[24] = '\0';
        data += 24;
        size -= 24;

        char *uri_path = malloc(25);
        memcpy(uri_path, data, 24);
        uri_path[24] = '\0';

        kms_request_t *request = NULL;
        request = kms_request_new(method, uri_path, NULL);
        if (request != NULL) {
            kms_request_destroy(request);
        }
        free(method);
        free(uri_path);
    }
    return 0;
}