mirror of
https://github.com/openssl/openssl.git
synced 2024-11-21 01:15:20 +08:00
APPS/dsaparam: fix case where infile and outfile are the same
Reviewed-by: Viktor Dukhovni <viktor@openssl.org> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/25552)
This commit is contained in:
parent
9ae1e6596f
commit
32189981a3
@ -150,10 +150,6 @@ int dsaparam_main(int argc, char **argv)
|
||||
numbits = num;
|
||||
private = genkey ? 1 : 0;
|
||||
|
||||
out = bio_open_owner(outfile, outformat, private);
|
||||
if (out == NULL)
|
||||
goto end;
|
||||
|
||||
ctx = EVP_PKEY_CTX_new_from_name(app_get0_libctx(), "DSA", app_get0_propq());
|
||||
if (ctx == NULL) {
|
||||
BIO_printf(bio_err,
|
||||
@ -200,6 +196,10 @@ int dsaparam_main(int argc, char **argv)
|
||||
goto end;
|
||||
}
|
||||
|
||||
out = bio_open_owner(outfile, outformat, private);
|
||||
if (out == NULL)
|
||||
goto end;
|
||||
|
||||
if (text) {
|
||||
EVP_PKEY_print_params(out, params, 0, NULL);
|
||||
}
|
||||
|
@ -53,15 +53,17 @@ This is compatible with RFC 2459 B<DSS-Parms> structure.
|
||||
|
||||
=item B<-in> I<filename>
|
||||
|
||||
This specifies the input filename to read parameters from or standard input if
|
||||
This specifies the input file to read parameters from or standard input if
|
||||
this option is not specified. If the I<numbits> parameter is included then
|
||||
this option will be ignored.
|
||||
|
||||
=item B<-out> I<filename>
|
||||
|
||||
This specifies the output filename parameters to. Standard output is used
|
||||
if this option is not present. The output filename should B<not> be the same
|
||||
as the input filename.
|
||||
This specifies the output file to write parameters to. Standard output is used
|
||||
if this option is not present.
|
||||
The output filename can be the same as the input filename,
|
||||
which leads to replacing the file contents.
|
||||
Note that file I/O is not atomic. The output file is truncated and then written.
|
||||
|
||||
=item B<-noout>
|
||||
|
||||
|
@ -10,6 +10,8 @@ use strict;
|
||||
use warnings;
|
||||
|
||||
use File::Spec;
|
||||
use File::Copy;
|
||||
use File::Compare qw/compare/;
|
||||
use OpenSSL::Glob;
|
||||
use OpenSSL::Test qw/:DEFAULT data_file/;
|
||||
use OpenSSL::Test::Utils;
|
||||
@ -66,7 +68,7 @@ plan skip_all => "DSA isn't supported in this build"
|
||||
my @valid = glob(data_file("valid", "*.pem"));
|
||||
my @invalid = glob(data_file("invalid", "*.pem"));
|
||||
|
||||
my $num_tests = scalar @valid + scalar @invalid;
|
||||
my $num_tests = scalar @valid + scalar @invalid + 2;
|
||||
plan tests => $num_tests;
|
||||
|
||||
foreach (@valid) {
|
||||
@ -76,3 +78,10 @@ foreach (@valid) {
|
||||
foreach (@invalid) {
|
||||
ok(!run(app([qw{openssl pkeyparam -noout -check -in}, $_])));
|
||||
}
|
||||
|
||||
my $input = data_file("valid", "p3072_q256_t1864.pem");
|
||||
my $inout = "inout.pem";
|
||||
copy($input, $inout);
|
||||
ok(run(app(['openssl', 'dsaparam', '-in', $inout, '-out', $inout])),
|
||||
"identical infile and outfile");
|
||||
ok(!compare($input, $inout), "converted file $inout did not change");
|
||||
|
Loading…
Reference in New Issue
Block a user