From 9c63ed131500591aea40df4743156a05b1ada5fd Mon Sep 17 00:00:00 2001 From: John Jones Date: Thu, 5 Oct 2017 13:49:08 -0500 Subject: [PATCH] Bad alloc was not being checked --- test/scripts/test_1.sh | 2 +- unixfs/unixfs.c | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/test/scripts/test_1.sh b/test/scripts/test_1.sh index 70264e5..bc0c373 100755 --- a/test/scripts/test_1.sh +++ b/test/scripts/test_1.sh @@ -44,5 +44,5 @@ function body { fi kill -9 $daemon_id - exit $retVal + return $retVal } diff --git a/unixfs/unixfs.c b/unixfs/unixfs.c index e0d9a31..1bde4b6 100644 --- a/unixfs/unixfs.c +++ b/unixfs/unixfs.c @@ -141,6 +141,10 @@ int ipfs_unixfs_add_data(unsigned char* data, size_t data_length, struct UnixFS* // debug: display hash size_t b58size = 100; uint8_t *b58key = (uint8_t *) malloc(b58size); + if (b58key == NULL) { + libp2p_logger_error("unixfs", "add_data: Unable to allocate memory for key.\n"); + return 0; + } libp2p_crypto_encoding_base58_encode(unix_fs->hash, unix_fs->hash_length, &b58key, &b58size); libp2p_logger_debug("unixfs", "Saving hash of %s to unixfs object.\n", b58key); free(b58key);