Skip to content

WIP: certtool: Handle output file as late as possible

Because the code handling the --outfile option creates and opens the file early in the argument parsing process, the empty file will be left over in case of an error. This is seemingly never useful.

$ file foo
foo: cannot open `foo' (No such file or directory)
$ certtool --generate-request --load-privkey=foo --outfile=bar
Generating a PKCS #10 certificate request...
reading --load-privkey: foo
$ echo $?
1
$ file bar
bar: empty

Here we move the processing of the option after the processing of many options that may exit without cleanup (notably --load-privkey).

This might not be a conclusive fix, but it is cheap and easy for the scenarios it does cover.

Note that the resulting outfile variable is used for the processing of other options, so we cannot push this further down.

Discussion: https://lists.gnupg.org/pipermail/gnutls-devel/2016-September/008178.html
Signed-off-by: Thibault Nélis tn@osimis.io

Merge request reports