Prevent sql scanning into nil value in accounts_table

Signed-off-by: Andrew Morgan <andrewm@matrix.org>
This commit is contained in:
Andrew Morgan 2018-06-04 16:00:04 +01:00
parent 241b1b5ace
commit c7430ec403

View file

@ -22,6 +22,8 @@ import (
"github.com/matrix-org/dendrite/clientapi/auth/authtypes"
"github.com/matrix-org/dendrite/clientapi/userutil"
"github.com/matrix-org/gomatrixserverlib"
log "github.com/sirupsen/logrus"
)
const accountsSchema = `
@ -121,14 +123,27 @@ func (s *accountsStatements) selectPasswordHash(
func (s *accountsStatements) selectAccountByLocalpart(
ctx context.Context, localpart string,
) (acc *authtypes.Account, err error) {
) (*authtypes.Account, error) {
var localpartPtr, appserviceIDPtr sql.NullString
var acc authtypes.Account
stmt := s.selectAccountByLocalpartStmt
err = stmt.QueryRowContext(ctx, localpart).Scan(&acc.Localpart, &acc.AppServiceID)
if err == nil {
acc.UserID = userutil.MakeUserID(localpart, s.serverName)
acc.ServerName = s.serverName
err := stmt.QueryRowContext(ctx, localpart).Scan(&localpartPtr, &appserviceIDPtr)
if err != nil {
log.WithError(err).Error("Unable to retrieve user from the db")
return nil, err
}
return
if appserviceIDPtr.Valid {
acc.AppServiceID = appserviceIDPtr.String
}
if localpartPtr.Valid {
acc.Localpart = localpartPtr.String
}
acc.UserID = userutil.MakeUserID(localpart, s.serverName)
acc.ServerName = s.serverName
return &acc, nil
}
func (s *accountsStatements) selectNewNumericLocalpart(