xref: /freebsd/crypto/openssh/regress/misc/fuzz-harness/authopt_fuzz.cc (revision ef1c128c05a64dc96083697fdbf6f045262f7844)
1*2f513db7SEd Maste #include <stddef.h>
2*2f513db7SEd Maste #include <stdio.h>
3*2f513db7SEd Maste #include <stdint.h>
4*2f513db7SEd Maste #include <string.h>
5*2f513db7SEd Maste #include <stdlib.h>
6*2f513db7SEd Maste 
7*2f513db7SEd Maste extern "C" {
8*2f513db7SEd Maste 
9*2f513db7SEd Maste #include "auth-options.h"
10*2f513db7SEd Maste 
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)11*2f513db7SEd Maste int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
12*2f513db7SEd Maste {
13*2f513db7SEd Maste 	char *cp = (char *)malloc(size + 1);
14*2f513db7SEd Maste 	struct sshauthopt *opts = NULL, *merge = NULL, *add = sshauthopt_new();
15*2f513db7SEd Maste 
16*2f513db7SEd Maste 	if (cp == NULL || add == NULL)
17*2f513db7SEd Maste 		goto out;
18*2f513db7SEd Maste 	memcpy(cp, data, size);
19*2f513db7SEd Maste 	cp[size] = '\0';
20*2f513db7SEd Maste 	if ((opts = sshauthopt_parse(cp, NULL)) == NULL)
21*2f513db7SEd Maste 		goto out;
22*2f513db7SEd Maste 	if ((merge = sshauthopt_merge(opts, add, NULL)) == NULL)
23*2f513db7SEd Maste 		goto out;
24*2f513db7SEd Maste 
25*2f513db7SEd Maste  out:
26*2f513db7SEd Maste 	free(cp);
27*2f513db7SEd Maste 	sshauthopt_free(add);
28*2f513db7SEd Maste 	sshauthopt_free(opts);
29*2f513db7SEd Maste 	sshauthopt_free(merge);
30*2f513db7SEd Maste 	return 0;
31*2f513db7SEd Maste }
32*2f513db7SEd Maste 
33*2f513db7SEd Maste } // extern "C"
34