xref: /freebsd/crypto/openssh/regress/misc/fuzz-harness/sshsigopt_fuzz.cc (revision 19261079b74319502c6ffa1249920079f0f69a72)
1*19261079SEd Maste #include <stddef.h>
2*19261079SEd Maste #include <stdio.h>
3*19261079SEd Maste #include <stdint.h>
4*19261079SEd Maste #include <string.h>
5*19261079SEd Maste #include <stdlib.h>
6*19261079SEd Maste 
7*19261079SEd Maste extern "C" {
8*19261079SEd Maste 
9*19261079SEd Maste #include "sshsig.h"
10*19261079SEd Maste 
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)11*19261079SEd Maste int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
12*19261079SEd Maste {
13*19261079SEd Maste 	char *cp = (char *)malloc(size + 1);
14*19261079SEd Maste 	struct sshsigopt *opts = NULL;
15*19261079SEd Maste 
16*19261079SEd Maste 	if (cp == NULL)
17*19261079SEd Maste 		goto out;
18*19261079SEd Maste 	memcpy(cp, data, size);
19*19261079SEd Maste 	cp[size] = '\0';
20*19261079SEd Maste 	if ((opts = sshsigopt_parse(cp, "libfuzzer", 0, NULL)) == NULL)
21*19261079SEd Maste 		goto out;
22*19261079SEd Maste 
23*19261079SEd Maste  out:
24*19261079SEd Maste 	free(cp);
25*19261079SEd Maste 	sshsigopt_free(opts);
26*19261079SEd Maste 	return 0;
27*19261079SEd Maste }
28*19261079SEd Maste 
29*19261079SEd Maste } // extern "C"
30