-
Notifications
You must be signed in to change notification settings - Fork 28
test-associate for a Unassociated Database Causes NullReferenceException #64
Copy link
Copy link
Closed
Labels
Description
In handler TestAssociate, the plugin tries to get the client id from the database. However, if the id is not present, a null key-value pair is returned, which then causes an exception.
Checking the return value should fix the problem.
// Handlers.cs
private Response TestAssociate(Request req)
{
var entry = _ext.GetConfigEntry(false);
if (entry != null)
{
if (req.TryDecrypt())
{
var msg = req.Message;
var x = entry.Strings.FirstOrDefault(e => e.Key.Equals(KeePassNatMsgExt.AssociateKeyPrefix + msg.GetString("id")));
// *** x may be a null pair ***
var key = x.Value;
var reqKey = msg.GetBytes("key");
var id = msg.GetString("id");
var dbKey = Convert.FromBase64String(key.ReadString());
// *** the above line throws an NullReferenceException ***
if (dbKey.SequenceEqual(reqKey) && !string.IsNullOrWhiteSpace(id))
{
var resp = req.GetResponse();
resp.Message.Add("id", id);
return resp;
}
return new ErrorResponse(req, ErrorType.AssociationFailed);
}
return new ErrorResponse(req, ErrorType.CannotDecryptMessage);
}
return new ErrorResponse(req, ErrorType.AssociationFailed);
}Reactions are currently unavailable