unpickle_account: Add error checking to the harness.
This commit is contained in:
parent
0a8bbde361
commit
34974551ab
1 changed files with 36 additions and 7 deletions
|
@ -1,16 +1,45 @@
|
||||||
#include "olm/account.hh"
|
|
||||||
#include "fuzzing.hh"
|
#include "fuzzing.hh"
|
||||||
|
#include "olm/account.hh"
|
||||||
|
#include "olm/olm.h"
|
||||||
|
|
||||||
|
size_t fuzz_unpickle_account(
|
||||||
|
OlmAccount * account, void * pickled, size_t pickled_length
|
||||||
|
) {
|
||||||
|
olm::Account & object = *reinterpret_cast<olm::Account *>(account);
|
||||||
|
std::uint8_t * const pos = reinterpret_cast<std::uint8_t *>(pickled);
|
||||||
|
std::uint8_t * const end = pos + pickled_length;
|
||||||
|
|
||||||
|
/* On success unpickle will return (pos + raw_length). If unpickling
|
||||||
|
* terminates too soon then it will return a pointer before
|
||||||
|
* (pos + raw_length). On error unpickle will return (pos + raw_length + 1).
|
||||||
|
*/
|
||||||
|
if (end != unpickle(pos, end + 1, object)) {
|
||||||
|
if (object.last_error == OlmErrorCode::OLM_SUCCESS) {
|
||||||
|
object.last_error = OlmErrorCode::OLM_CORRUPTED_PICKLE;
|
||||||
|
}
|
||||||
|
return std::size_t(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return pickled_length;
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, const char * argv[]) {
|
int main(int argc, const char * argv[]) {
|
||||||
int pickle_fd = STDIN_FILENO;
|
int pickle_fd = STDIN_FILENO;
|
||||||
uint8_t * pickle_buffer;
|
uint8_t * pickle_buffer;
|
||||||
ssize_t pickle_length = check_errno(
|
ssize_t pickle_length = check_errno(
|
||||||
"Error reading pickle file", read_file(pickle_fd, &pickle_buffer)
|
"Error reading pickle file", read_file(pickle_fd, &pickle_buffer));
|
||||||
);
|
|
||||||
olm::Account * account = new olm::Account;
|
void * account_buf = malloc(olm_account_size());
|
||||||
unpickle(pickle_buffer, pickle_buffer + pickle_length, *account);
|
if (!account_buf) {
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
OlmAccount * account = olm_account(account_buf);
|
||||||
|
|
||||||
|
check_error(olm_account_last_error, account, "Error unpickling account",
|
||||||
|
fuzz_unpickle_account(account, pickle_buffer, pickle_length));
|
||||||
|
|
||||||
free(pickle_buffer);
|
free(pickle_buffer);
|
||||||
delete account;
|
free(account);
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue