#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define LIBSSH_STATIC 1
#include "libssh/libssh.h"
#include "libssh/misc.h"
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
ssh_key pkey = NULL;
char *filename = NULL;
int fd;
int rc;
ssize_t sz;
ssh_init();
filename = strdup("/tmp/libssh_pubkey_XXXXXX");
if (filename == NULL) {
return -1;
}
fd = mkstemp(filename);
if (fd == -1) {
free(filename);
close(fd);
return -1;
}
sz = ssh_writen(fd, data, size);
close(fd);
if (sz == SSH_ERROR) {
unlink(filename);
free(filename);
return -1;
}
rc = ssh_pki_import_pubkey_file(filename, &pkey);
if (rc != SSH_OK) {
unlink(filename);
free(filename);
return 1;
}
ssh_key_free(pkey);
unlink(filename);
free(filename);
ssh_finalize();
return 0;
}