Fixed possible memory leak in signature routine

This commit is contained in:
John Jones 2017-01-23 12:07:48 -05:00
parent 8bdc9332d4
commit d13a47d7d5
4 changed files with 125 additions and 46 deletions

View file

@ -51,32 +51,6 @@
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
<storageModule moduleId="refreshScope"/>
<storageModule moduleId="org.eclipse.cdt.make.core.buildtargets">
<buildTargets>
<target name="all" path="" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand>
<buildTarget>all</buildTarget>
<stopOnError>true</stopOnError>
<useDefaultCommand>false</useDefaultCommand>
<runAllBuilders>true</runAllBuilders>
</target>
<target name="clean" path="" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand>
<buildTarget>clean</buildTarget>
<stopOnError>true</stopOnError>
<useDefaultCommand>false</useDefaultCommand>
<runAllBuilders>true</runAllBuilders>
</target>
<target name="test" path="" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand>
<buildArguments/>
<buildTarget>test</buildTarget>
<stopOnError>true</stopOnError>
<useDefaultCommand>false</useDefaultCommand>
<runAllBuilders>true</runAllBuilders>
</target>
</buildTargets>
</storageModule>
<storageModule moduleId="scannerConfiguration">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
<scannerConfigBuildInfo instanceId="cdt.managedbuild.toolchain.gnu.base.330135696;cdt.managedbuild.toolchain.gnu.base.330135696.1121040948;cdt.managedbuild.tool.gnu.c.compiler.base.623347632;cdt.managedbuild.tool.gnu.c.compiler.input.1284958161">
@ -86,4 +60,39 @@
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
</scannerConfigBuildInfo>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.make.core.buildtargets">
<buildTargets>
<target name="all" path="" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand>
<buildArguments/>
<buildTarget>all</buildTarget>
<stopOnError>true</stopOnError>
<useDefaultCommand>false</useDefaultCommand>
<runAllBuilders>true</runAllBuilders>
</target>
<target name="clean" path="" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand>
<buildArguments/>
<buildTarget>clean</buildTarget>
<stopOnError>true</stopOnError>
<useDefaultCommand>false</useDefaultCommand>
<runAllBuilders>true</runAllBuilders>
</target>
<target name="test" path="" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand>
<buildTarget>test</buildTarget>
<stopOnError>true</stopOnError>
<useDefaultCommand>false</useDefaultCommand>
<runAllBuilders>true</runAllBuilders>
</target>
<target name="rebuild" path="" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand>
<buildArguments/>
<buildTarget>rebuild</buildTarget>
<stopOnError>true</stopOnError>
<useDefaultCommand>true</useDefaultCommand>
<runAllBuilders>true</runAllBuilders>
</target>
</buildTargets>
</storageModule>
</cproject>

View file

@ -15,6 +15,8 @@ compile:
test: compile
cd test; make all;
rebuild: clean all
all: test
clean:

View file

@ -252,6 +252,8 @@ int libp2p_crypto_rsa_sign(struct RsaPrivateKey* private_key, unsigned char* mes
32,
output,
result );
mbedtls_ctr_drbg_free(&ctr_drbg);
//mbetdls_rsa_free(ctx);
return retVal == 0;
}

View file

@ -7,6 +7,50 @@
#include "crypto/test_base32.h"
#include "test_mbedtls.h"
const char* names[] = {
"test_public_der_to_private_der",
"test_mbedtls_varint_128_binary",
"test_mbedtls_varint_128_string",
"test_crypto_rsa_private_key_der",
"test_crypto_rsa_public_key_to_peer_id",
"test_crypto_x509_der_to_private2",
"test_crypto_x509_der_to_private",
//"test_multihash_encode",
//"test_multihash_decode",
//"test_multihash_base58_encode_decode",
//"test_multihash_base58_decode",
//"test_multihash_size",
"test_base58_encode_decode",
"test_base58_size",
"test_base58_max_size",
"test_base58_peer_address",
//"test_mbedtls_pk_write_key_der",
//"test_crypto_rsa_sign",
"test_crypto_encoding_base32_encode"
};
int (*funcs[])(void) = {
test_public_der_to_private_der,
test_mbedtls_varint_128_binary,
test_mbedtls_varint_128_string,
test_crypto_rsa_private_key_der,
test_crypto_rsa_public_key_to_peer_id,
test_crypto_x509_der_to_private2,
test_crypto_x509_der_to_private,
//test_multihash_encode,
//test_multihash_decode,
//test_multihash_base58_encode_decode,
//test_multihash_base58_decode,
//test_multihash_size,
test_base58_encode_decode,
test_base58_size,
test_base58_max_size,
test_base58_peer_address,
//test_mbedtls_pk_write_key_der,
//test_crypto_rsa_sign,
test_crypto_encoding_base32_encode
};
int testit(const char* name, int (*func)(void)) {
printf("Testing %s...\n", name);
int retVal = func();
@ -18,26 +62,48 @@ int testit(const char* name, int (*func)(void)) {
}
int main(int argc, char** argv) {
/*
testit("test_public_der_to_private_der", test_public_der_to_private_der);
testit("test_mbedtls_varint_128_binary", test_mbedtls_varint_128_binary);
testit("test_mbedtls_varint_128_string", test_mbedtls_varint_128_string);
testit("test_crypto_rsa_private_key_der", test_crypto_rsa_private_key_der);
testit("test_crypto_rsa_public_key_to_peer_id", test_crypto_rsa_public_key_to_peer_id);
testit("test_crypto_x509_der_to_private2", test_crypto_x509_der_to_private2);
testit("test_crypto_x509_der_to_private", test_crypto_x509_der_to_private);
//testit("test_multihash_encode", test_multihash_encode);
//testit("test_multihash_decode", test_multihash_decode);
//testit("test_multihash_base58_encode_decode", test_multihash_base58_encode_decode);
//testit("test_multihash_base58_decode", test_multihash_base58_decode);
//testit("test_multihash_size", test_multihash_size);
testit("test_base58_encode_decode", test_base58_encode_decode);
testit("test_base58_size", test_base58_size);
testit("test_base58_max_size", test_base58_max_size);
testit("test_base58_peer_address", test_base58_peer_address);
//testit("test_mbedtls_pk_write_key_der", test_mbedtls_pk_write_key_der);
*/
testit("test_crypto_encoding_base32_encode", test_crypto_encoding_base32_encode);
int counter = 0;
int tests_ran = 0;
char* test_wanted;
int only_one = 0;
if(argc > 1) {
only_one = 1;
if (argv[1][0] == '\'') { // some shells put quotes around arguments
argv[1][strlen(argv[1])-1] = 0;
test_wanted = &(argv[1][1]);
}
else
test_wanted = argv[1];
}
int array_length = sizeof(funcs) / sizeof(funcs[0]);
int array2_length = sizeof(names) / sizeof(names[0]);
if (array_length != array2_length) {
printf("Test arrays are not of the same length. Funcs: %d, Names: %d\n", array_length, array2_length);
}
for (int i = 0; i < array_length; i++) {
if (only_one) {
const char* currName = names[i];
if (strcmp(currName, test_wanted) == 0) {
tests_ran++;
counter += testit(names[i], funcs[i]);
}
}
else
if (!only_one) {
tests_ran++;
counter += testit(names[i], funcs[i]);
}
}
if (tests_ran == 0)
printf("***** No tests found *****\n");
else {
if (counter > 0) {
printf("***** There were %d failed test(s) *****\n", counter);
} else {
printf("All %d tests passed\n", tests_ran);
}
}
return 1;
}