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>
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/> <storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
<storageModule moduleId="refreshScope"/> <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"> <storageModule moduleId="scannerConfiguration">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/> <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"> <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=""/> <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
</scannerConfigBuildInfo> </scannerConfigBuildInfo>
</storageModule> </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> </cproject>

View file

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

View file

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

View file

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