forked from tarantool/tarantool
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test/fuzz: add fuzzing tests for IPROTO decoders
Examples of IPROTO decoding issues: tarantool#3900, tarantool#1928, tarantool#6781. Patch adds a number of fuzzing tests that covers IPROTO decoding: - xrow_decode_auth - xrow_decode_begin - xrow_decode_call - xrow_decode_dml - xrow_decode_id - xrow_decode_raft - xrow_decode_sql - xrow_decode_watch - xrow_greeting_decode NO_DOC=testing NO_CHANGELOG=testing (cherry picked from commit 46cacf3)
- Loading branch information
1 parent
96fa495
commit 28ac932
Showing
11 changed files
with
443 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#include "box/xrow.h" | ||
#include "box/iproto_constants.h" | ||
#include "fiber.h" | ||
#include "memory.h" | ||
|
||
void | ||
cord_on_yield(void) {} | ||
|
||
__attribute__((constructor)) | ||
static void | ||
setup(void) | ||
{ | ||
memory_init(); | ||
fiber_init(fiber_c_invoke); | ||
} | ||
|
||
__attribute__((destructor)) | ||
static void | ||
teardown(void) | ||
{ | ||
fiber_free(); | ||
memory_free(); | ||
} | ||
|
||
int | ||
LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) | ||
{ | ||
const char *d = (const char *)data; | ||
const char *end = (const char *)data + size; | ||
if (mp_check(&d, end) != 0) | ||
return -1; | ||
|
||
struct iovec body = {0}; | ||
body.iov_base = (void *)data; | ||
body.iov_len = size; | ||
struct xrow_header row = {0}; | ||
row.body[0] = body; | ||
row.bodycnt = 1; | ||
row.type = IPROTO_OK; | ||
|
||
struct auth_request request = {0}; | ||
xrow_decode_auth(&row, &request); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#include "box/xrow.h" | ||
#include "box/iproto_constants.h" | ||
#include "fiber.h" | ||
#include "memory.h" | ||
|
||
void | ||
cord_on_yield(void) {} | ||
|
||
__attribute__((constructor)) | ||
static void | ||
setup(void) | ||
{ | ||
memory_init(); | ||
fiber_init(fiber_c_invoke); | ||
} | ||
|
||
__attribute__((destructor)) | ||
static void | ||
teardown(void) | ||
{ | ||
fiber_free(); | ||
memory_free(); | ||
} | ||
|
||
int | ||
LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) | ||
{ | ||
const char *d = (const char *)data; | ||
const char *end = (const char *)data + size; | ||
if (mp_check(&d, end) != 0) | ||
return -1; | ||
|
||
struct iovec body = {0}; | ||
body.iov_base = (void *)data; | ||
body.iov_len = size; | ||
struct xrow_header row = {0}; | ||
row.body[0] = body; | ||
row.bodycnt = 1; | ||
row.type = IPROTO_BEGIN; | ||
|
||
struct begin_request request = {0}; | ||
if (xrow_decode_begin(&row, &request) == -1) | ||
return -1; | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#include "box/xrow.h" | ||
#include "box/iproto_constants.h" | ||
#include "fiber.h" | ||
#include "memory.h" | ||
|
||
void | ||
cord_on_yield(void) {} | ||
|
||
__attribute__((constructor)) | ||
static void | ||
setup(void) | ||
{ | ||
memory_init(); | ||
fiber_init(fiber_c_invoke); | ||
} | ||
|
||
__attribute__((destructor)) | ||
static void | ||
teardown(void) | ||
{ | ||
fiber_free(); | ||
memory_free(); | ||
} | ||
|
||
int | ||
LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) | ||
{ | ||
const char *d = (const char *)data; | ||
const char *end = (const char *)data + size; | ||
if (mp_check(&d, end) != 0) | ||
return -1; | ||
|
||
struct iovec body = {0}; | ||
body.iov_base = (void *)data; | ||
body.iov_len = size; | ||
|
||
struct xrow_header row = {0}; | ||
row.type = IPROTO_CALL; /* TODO: IPROTO_CALL_16 */ | ||
row.body[0] = body; | ||
row.bodycnt = 1; | ||
|
||
struct call_request request = {0}; | ||
xrow_decode_call(&row, &request); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#include "box/xrow.h" | ||
#include "box/iproto_constants.h" | ||
#include "fiber.h" | ||
#include "memory.h" | ||
|
||
void | ||
cord_on_yield(void) {} | ||
|
||
__attribute__((constructor)) | ||
static void | ||
setup(void) | ||
{ | ||
memory_init(); | ||
fiber_init(fiber_c_invoke); | ||
} | ||
|
||
__attribute__((destructor)) | ||
static void | ||
teardown(void) | ||
{ | ||
fiber_free(); | ||
memory_free(); | ||
} | ||
|
||
int | ||
LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) | ||
{ | ||
const char *d = (const char *)data; | ||
const char *end = (const char *)data + size; | ||
if (mp_check(&d, end) != 0) | ||
return -1; | ||
|
||
struct iovec body = {0}; | ||
body.iov_base = (void *)data; | ||
body.iov_len = size; | ||
|
||
struct xrow_header row = {0}; | ||
row.body[0] = body; | ||
row.bodycnt = 1; | ||
|
||
struct request request = {0}; | ||
if (xrow_decode_dml(&row, &request, 0) == -1) | ||
return -1; | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#include "box/xrow.h" | ||
#include "box/iproto_constants.h" | ||
#include "fiber.h" | ||
#include "memory.h" | ||
|
||
void | ||
cord_on_yield(void) {} | ||
|
||
__attribute__((constructor)) | ||
static void | ||
setup(void) | ||
{ | ||
memory_init(); | ||
fiber_init(fiber_c_invoke); | ||
} | ||
|
||
__attribute__((destructor)) | ||
static void | ||
teardown(void) | ||
{ | ||
fiber_free(); | ||
memory_free(); | ||
} | ||
|
||
int | ||
LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) | ||
{ | ||
const char *d = (const char *)data; | ||
const char *end = (const char *)data + size; | ||
if (mp_check(&d, end) != 0) | ||
return -1; | ||
|
||
struct iovec body = {0}; | ||
body.iov_base = (void *)data; | ||
body.iov_len = size; | ||
|
||
struct xrow_header row = {0}; | ||
row.body[0] = body; | ||
row.bodycnt = 1; | ||
|
||
struct id_request request = {0}; | ||
if (xrow_decode_id(&row, &request) == -1) | ||
return -1; | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#include "box/xrow.h" | ||
#include "box/iproto_constants.h" | ||
#include "fiber.h" | ||
#include "memory.h" | ||
|
||
void | ||
cord_on_yield(void) {} | ||
|
||
__attribute__((constructor)) | ||
static void | ||
setup(void) | ||
{ | ||
memory_init(); | ||
fiber_init(fiber_c_invoke); | ||
} | ||
|
||
__attribute__((destructor)) | ||
static void | ||
teardown(void) | ||
{ | ||
fiber_free(); | ||
memory_free(); | ||
} | ||
|
||
int | ||
LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) | ||
{ | ||
const char *d = (const char *)data; | ||
const char *end = (const char *)data + size; | ||
if (mp_check(&d, end) != 0) | ||
return -1; | ||
|
||
struct iovec body = {0}; | ||
body.iov_base = (void *)data; | ||
body.iov_len = size; | ||
|
||
struct xrow_header row = {0}; | ||
row.body[0] = body; | ||
row.bodycnt = 1; | ||
|
||
struct raft_request request = {0}; | ||
struct vclock vclock = {0}; | ||
xrow_decode_raft(&row, &request, &vclock); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#include "box/xrow.h" | ||
#include "box/iproto_constants.h" | ||
#include "fiber.h" | ||
#include "memory.h" | ||
|
||
void | ||
cord_on_yield(void) {} | ||
|
||
__attribute__((constructor)) | ||
static void | ||
setup(void) | ||
{ | ||
memory_init(); | ||
fiber_init(fiber_c_invoke); | ||
} | ||
|
||
__attribute__((destructor)) | ||
static void | ||
teardown(void) | ||
{ | ||
fiber_free(); | ||
memory_free(); | ||
} | ||
|
||
int | ||
LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) | ||
{ | ||
const char *d = (const char *)data; | ||
const char *end = (const char *)data + size; | ||
if (mp_check(&d, end) != 0) | ||
return -1; | ||
|
||
struct iovec body = {0}; | ||
body.iov_base = (void *)data; | ||
body.iov_len = size; | ||
|
||
struct xrow_header row = {0}; | ||
row.body[0] = body; | ||
row.bodycnt = 1; | ||
|
||
struct sql_request request = {0}; | ||
if (xrow_decode_sql(&row, &request) == -1) | ||
return -1; | ||
|
||
return 0; | ||
} |
Oops, something went wrong.