Commit b7de76b7 authored by Dr. Stephen Henson's avatar Dr. Stephen Henson
Browse files

Add support for memory leak checking in fips_algvs.

Fix many memory leaks in algorithm test utilities.
parent 8ab0d50c
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -535,7 +535,7 @@ static int do_mct(char *amode,
		}
	    }
	}
    
    FIPS_cipher_ctx_cleanup(&ctx);
    return ret;
    }

@@ -850,6 +850,7 @@ static int proc_file(char *rqfile, char *rspfile)
	fclose(rfp);
    if (afp)
	fclose(afp);
    FIPS_cipher_ctx_cleanup(&ctx);
    return err;
    }

+6 −0
Original line number Diff line number Diff line
@@ -261,6 +261,7 @@ static void gcmtest(FILE *in, FILE *out, int encrypt)
			iv = aad = ct = pt = key = tag = NULL;
			}
		}
	FIPS_cipher_ctx_cleanup(&ctx);	
	}

static void xtstest(FILE *in, FILE *out)
@@ -335,6 +336,7 @@ static void xtstest(FILE *in, FILE *out)
			iv = key = inbuf = outbuf = NULL;
			}	
		}
	FIPS_cipher_ctx_cleanup(&ctx);	
	}

static void ccmtest(FILE *in, FILE *out)
@@ -428,6 +430,8 @@ static void ccmtest(FILE *in, FILE *out)
			}
		else if (!strcmp(keyword,"Adata"))
			{
			if (Adata)
				OPENSSL_free(Adata);
			Adata = hex2bin_m(value, &l);
			if (Alen && l != Alen)
				{
@@ -493,6 +497,8 @@ static void ccmtest(FILE *in, FILE *out)
		OPENSSL_free(Key);
	if (Nonce)
		OPENSSL_free(Nonce);
	if (Adata)
		OPENSSL_free(Adata);
	FIPS_cipher_ctx_cleanup(&ctx);
	}

+2 −0
Original line number Diff line number Diff line
@@ -263,6 +263,7 @@ static int do_tmct(char *amode,
	if(imode == TOFB)
	    for(n=0 ; n < 8 ; ++n)
		text[n]=text0[n]^old_iv[n];
	FIPS_cipher_ctx_cleanup(&ctx);
	}
    return 1;
    }
@@ -622,6 +623,7 @@ static int tproc_file(char *rqfile, char *rspfile)
	fclose(rfp);
    if (afp)
	fclose(afp);
    FIPS_cipher_ctx_cleanup(&ctx);
    return err;
    }

+23 −6
Original line number Diff line number Diff line
@@ -199,6 +199,7 @@ static void pqg(FILE *in, FILE *out)
			{
			fprintf(out, "counter = %d" RESP_EOL RESP_EOL, counter);
			}
		FIPS_dsa_free(dsa);
		}
	    }
	else if(!strcmp(keyword,"P"))
@@ -519,6 +520,8 @@ static void keyver(FILE *in, FILE *out)
	    BN_free(g);
	if (Y2)
	    BN_free(Y2);
	if (ctx)
	    BN_CTX_free(ctx);
    }

static void keypair(FILE *in, FILE *out)
@@ -575,6 +578,8 @@ static void keypair(FILE *in, FILE *out)
		do_bn_print_name(out, "Y",dsa->pub_key);
	    	fputs(RESP_EOL, out);
		}
	    if (dsa)
		FIPS_dsa_free(dsa);
	    }
	}
    }
@@ -687,15 +692,15 @@ static void sigver(FILE *in, FILE *out)
	    dsa = FIPS_dsa_new();
	    }
	else if(!strcmp(keyword,"P"))
	    dsa->p=hex2bn(value);
	    do_hex2bn(&dsa->p, value);
	else if(!strcmp(keyword,"Q"))
	    dsa->q=hex2bn(value);
	    do_hex2bn(&dsa->q, value);
	else if(!strcmp(keyword,"G"))
	    dsa->g=hex2bn(value);
	    do_hex2bn(&dsa->g, value);
	else if(!strcmp(keyword,"Msg"))
	    n=hex2bin(value,msg);
	else if(!strcmp(keyword,"Y"))
	    dsa->pub_key=hex2bn(value);
	    do_hex2bn(&dsa->pub_key, value);
	else if(!strcmp(keyword,"R"))
	    sig->r=hex2bn(value);
	else if(!strcmp(keyword,"S"))
@@ -711,10 +716,22 @@ static void sigver(FILE *in, FILE *out)
	    r = FIPS_dsa_verify_ctx(dsa, &mctx, sig);
	    no_err = 0;
	    FIPS_md_ctx_cleanup(&mctx);
	    if (sig->s)
		{
		BN_free(sig->s);
		sig->s = NULL;
		}
	    if (sig->r)
		{
		BN_free(sig->r);
		sig->r = NULL;
		}
	
	    fprintf(out, "Result = %c" RESP_EOL RESP_EOL, r == 1 ? 'P' : 'F');
	    }
	}
	if (dsa)
	    FIPS_dsa_free(dsa);
    }

#ifdef FIPS_ALGVS
+17 −3
Original line number Diff line number Diff line
@@ -319,6 +319,7 @@ int main(int argc, char **argv)
	EC_GROUP *group = NULL;
	char *keyword = NULL, *value = NULL;
	int do_verify = -1, exout = 0;
	int rv = 1;

	int curve_nids[5] = {0,0,0,0,0};
	int param_set = -1;
@@ -463,10 +464,23 @@ int main(int argc, char **argv)
					md, rhash, rhashlen);
			}
		}
	return 0;
	rv = 0;
	parse_error:
	if (id)
		BN_free(id);
	if (ix)
		BN_free(ix);
	if (iy)
		BN_free(iy);
	if (cx)
		BN_free(cx);
	if (cy)
		BN_free(cy);
	if (group)
		EC_GROUP_free(group);
	if (rv)
		fprintf(stderr, "Error Parsing request file\n");
	exit(1);
	return rv;
	}

#endif
Loading