summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorValerie Bubb Fenwick <Valerie.Fenwick@Sun.COM>2009-05-18 15:11:14 -0700
committerValerie Bubb Fenwick <Valerie.Fenwick@Sun.COM>2009-05-18 15:11:14 -0700
commit9a2817adf6e93c27bdf78dc64c63ff8f40127cb5 (patch)
treeca0275f8499e91791fe08a5f23d5b8a9c85a8851
parentfd98d3e52b00305aadaac37b6dfa25b6ec26d537 (diff)
downloadillumos-gate-9a2817adf6e93c27bdf78dc64c63ff8f40127cb5.tar.gz
6823839 encrypt utility can cause loss of data
-rw-r--r--usr/src/cmd/cmd-crypto/decrypt/decrypt.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/usr/src/cmd/cmd-crypto/decrypt/decrypt.c b/usr/src/cmd/cmd-crypto/decrypt/decrypt.c
index 831ccf05d5..0f6ef25169 100644
--- a/usr/src/cmd/cmd-crypto/decrypt/decrypt.c
+++ b/usr/src/cmd/cmd-crypto/decrypt/decrypt.c
@@ -433,6 +433,7 @@ execute_cmd(struct CommandInfo *cmd, char *algo_str)
char *outfilename = NULL;
boolean_t errflag = B_TRUE;
boolean_t inoutsame = B_FALSE; /* if both input & output are same */
+ boolean_t leavefilealone = B_FALSE;
CK_BYTE_PTR pivbuf = NULL_PTR;
CK_ULONG ivlen = 0L;
int mech_match = 0;
@@ -717,6 +718,8 @@ execute_cmd(struct CommandInfo *cmd, char *algo_str)
cryptoerror(LOG_STDERR, gettext(
"cannot open output file %s"),
outfilename);
+ /* Cannot open file, should leave it alone */
+ leavefilealone = B_TRUE;
goto cleanup;
}
}
@@ -977,8 +980,8 @@ cleanup:
}
}
- /* If error occurred, remove the output file */
- if (errflag && outfilename != NULL) {
+ /* If error occurred and the file was new, remove the output file */
+ if (errflag && (outfilename != NULL) && !leavefilealone) {
(void) unlink(outfilename);
}