summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHarsh Shandilya <me@msfjarvis.dev>2021-01-27 11:12:23 +0530
committerHarsh Shandilya <me@msfjarvis.dev>2021-03-06 13:45:41 +0530
commit3b55a14acbf8845067f0ab0789a14c6faff8601e (patch)
tree5d167dd60e15c6f188591e482aab1ba80c5b4a6e
parent66e17fdf68238b73d53cf9487d145319ff6c3f89 (diff)
Disallow overwriting passwords when editing (#1286)
Co-authored-by: Aditya Wasan <adityawasan55@gmail.com> (cherry picked from commit 1f8db46ade8a7c25deb568b8a5988ee7b340b9c1)
-rw-r--r--CHANGELOG.md5
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/crypto/PasswordCreationActivity.kt5
2 files changed, 9 insertions, 1 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 89a07c0f..9ece3189 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
## [Unreleased]
+### Fixed
+
+- Editing a password allowed accidentally overwriting an existing one
+
+
## [1.13.2] - 2020-12-20
### Added
diff --git a/app/src/main/java/com/zeapo/pwdstore/crypto/PasswordCreationActivity.kt b/app/src/main/java/com/zeapo/pwdstore/crypto/PasswordCreationActivity.kt
index 94a32ea4..baabfbf5 100644
--- a/app/src/main/java/com/zeapo/pwdstore/crypto/PasswordCreationActivity.kt
+++ b/app/src/main/java/com/zeapo/pwdstore/crypto/PasswordCreationActivity.kt
@@ -397,7 +397,10 @@ class PasswordCreationActivity : BasePgpActivity(), OpenPgpServiceConnection.OnB
runCatching {
val file = File(path)
// If we're not editing, this file should not already exist!
- if (!editing && file.exists()) {
+ // Additionally, if we were editing and the incoming and outgoing
+ // filenames differ, it means we renamed. Ensure that the target
+ // doesn't already exist to prevent an accidental overwrite.
+ if ((!editing || (editing && suggestedName != file.nameWithoutExtension)) && file.exists()) {
snackbar(message = getString(R.string.password_creation_duplicate_error))
return@executeApiAsync
}