Bug 966143 - Don't attempt to process a malformed password record. r=nalexander

This commit is contained in:
Richard Newman 2014-03-04 14:38:11 -08:00
parent a014dcaea3
commit eea1085ad4
2 changed files with 28 additions and 0 deletions

View File

@ -327,6 +327,13 @@ public class PasswordsRepositorySession extends
}
// End deletion logic.
// Validate the incoming record.
if (!remoteRecord.isValid()) {
Logger.warn(LOG_TAG, "Incoming record is invalid. Reporting store failed.");
delegate.onRecordStoreFailed(new RuntimeException("Can't store invalid password record."), record.guid);
return;
}
// Now we're processing a non-deleted incoming record.
if (existingRecord == null) {
trace("Looking up match for record " + remoteRecord.guid);

View File

@ -181,4 +181,25 @@ public class PasswordRecord extends Record {
+ "timePasswordChanged: " + this.timePasswordChanged + ", "
+ "timesUsed: " + this.timesUsed;
}
/**
* A PasswordRecord is considered valid if it abides by the database
* constraints of the PasswordsProvider (moz_logins).
*
* See toolkit/components/passwordmgr/storage-mozStorage.js for the
* definitions:
*
* http://hg.mozilla.org/mozilla-central/file/00955d61cc94/toolkit/components/passwordmgr/storage-mozStorage.js#l98
*/
public boolean isValid() {
if (this.deleted) {
return true;
}
return this.hostname != null &&
this.encryptedUsername != null &&
this.encryptedPassword != null &&
this.usernameField != null &&
this.passwordField != null;
}
}