mirror of
https://git.libssh.org/projects/libssh.git
synced 2025-07-31 00:03:07 +03:00
fuzz: Use ssh_writen to avoid short reads
Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Sahana Prasad <sahana@redhat.com> Reviewed-by: Eshan Kelkar <eshankelkar@galorithm.com>
This commit is contained in:
committed by
Sahana Prasad
parent
edb04af5be
commit
9f2b42382c
@ -13,6 +13,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@ -20,18 +21,19 @@
|
|||||||
|
|
||||||
#define LIBSSH_STATIC 1
|
#define LIBSSH_STATIC 1
|
||||||
#include "libssh/libssh.h"
|
#include "libssh/libssh.h"
|
||||||
|
#include "libssh/misc.h"
|
||||||
|
|
||||||
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
|
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
|
||||||
{
|
{
|
||||||
ssh_key pkey = NULL;
|
ssh_key pkey = NULL;
|
||||||
const char *template = "/tmp/libssh_pubkey_XXXXXX";
|
char *filename = NULL;
|
||||||
char *filename = strdup(template);
|
|
||||||
int fd;
|
int fd;
|
||||||
int rc;
|
int rc;
|
||||||
ssize_t sz;
|
ssize_t sz;
|
||||||
|
|
||||||
ssh_init();
|
ssh_init();
|
||||||
|
|
||||||
|
filename = strdup("/tmp/libssh_pubkey_XXXXXX");
|
||||||
if (filename == NULL) {
|
if (filename == NULL) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -41,9 +43,9 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
|
|||||||
close(fd);
|
close(fd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
sz = write(fd, data, size);
|
sz = ssh_writen(fd, data, size);
|
||||||
close(fd);
|
close(fd);
|
||||||
if ((size_t)sz != size) {
|
if (sz == SSH_ERROR) {
|
||||||
unlink(filename);
|
unlink(filename);
|
||||||
free(filename);
|
free(filename);
|
||||||
return -1;
|
return -1;
|
||||||
|
Reference in New Issue
Block a user