Skip to content

Commit

Permalink
Add fuzz host target that does not provide any protocols
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Johansson committed Apr 18, 2018
1 parent 3d158f8 commit 97ef162
Show file tree
Hide file tree
Showing 17 changed files with 77 additions and 1 deletion.
3 changes: 2 additions & 1 deletion fuzz-tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ endmacro(add_fuzz)

add_fuzz(fuzz_client)
add_fuzz(fuzz_a2_client)
add_fuzz(fuzz_host)
add_fuzz(fuzz_a1a2_host)
add_fuzz(fuzz_no_a1a2_host)
add_fuzz(fuzz_read_parse)

File renamed without changes.
75 changes: 75 additions & 0 deletions fuzz-tests/fuzz_no_a1a2_host.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#include <unistd.h>
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>

#include "salt.h"
#include "util.h"
#include "test_data.h"

#define MAX_READ_SIZE 8192

int main(void) {

salt_channel_t channel;
salt_ret_t ret;
uint8_t hndsk_buffer[SALT_HNDSHK_BUFFER_SIZE + 1];
memset(hndsk_buffer, 0xcc, sizeof(hndsk_buffer));

salt_create(&channel, SALT_SERVER, fuzz_write, fuzz_read, &mock_time);
salt_set_delay_threshold(&channel, 1000);
salt_set_signature(&channel, salt_example_session_1_data.client_sk_sec);
salt_init_session_using_key(&channel,
hndsk_buffer,
SALT_HNDSHK_BUFFER_SIZE,
salt_example_session_1_data.host_ek_pub,
salt_example_session_1_data.host_ek_sec);

do {
ret = salt_handshake(&channel, NULL);
} while (ret == SALT_PENDING);

assert(hndsk_buffer[SALT_HNDSHK_BUFFER_SIZE] == 0xcc);

if (ret == SALT_ERROR) {
return -1;
}

salt_msg_t read_msg;

uint16_t num_messages = 0;

do {
uint8_t *buffer = malloc(MAX_READ_SIZE);

if (buffer == NULL) {
return -1;
}

do {
ret = salt_read_begin(&channel, buffer, MAX_READ_SIZE, &read_msg);
} while (ret == SALT_PENDING);

if (ret == SALT_SUCCESS) {

do {
printf("Message %d: ", num_messages);
hexprint(read_msg.read.p_payload, read_msg.read.message_size);
printf("\r\n");
num_messages++;
} while (salt_read_next(&read_msg) == SALT_SUCCESS);
ret = SALT_SUCCESS;
}

free(buffer);
} while (ret == SALT_SUCCESS);

printf("err_code: 0x%02x\r\n", channel.err_code);
if (channel.err_code == SALT_ERR_DELAY_DETECTED) {
printf("delay detected.\r\n");
}
printf("num_messages: %d\r\n", num_messages);

return (num_messages > 0 && channel.read_channel.err_code == SALT_ERR_CONNECTION_CLOSED) ? 0 : -1;
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file added fuzz-tests/input/fuzz_no_a1a2_host/valid_a1
Binary file not shown.
Binary file added fuzz-tests/input/fuzz_no_a1a2_host/valid_a1m1
Binary file not shown.
Binary file added fuzz-tests/input/fuzz_no_a1a2_host/valid_a1m1m4
Binary file not shown.
Binary file added fuzz-tests/input/fuzz_no_a1a2_host/valid_m1
Binary file not shown.
Binary file added fuzz-tests/input/fuzz_no_a1a2_host/valid_m1m4
Binary file not shown.
Binary file added fuzz-tests/input/fuzz_no_a1a2_host/valid_m1m4app
Binary file not shown.
Binary file not shown.

0 comments on commit 97ef162

Please sign in to comment.