From 11df0fe3c9f9e6cedeba6e5f5f8a0176ba2ff4c0 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Thu, 4 Aug 2016 15:35:48 +0100 Subject: [PATCH] Decode the realm JSON before calling methods on it --- src/github.com/matrix-org/go-neb/database/schema.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/github.com/matrix-org/go-neb/database/schema.go b/src/github.com/matrix-org/go-neb/database/schema.go index 0dab250..41afea6 100644 --- a/src/github.com/matrix-org/go-neb/database/schema.go +++ b/src/github.com/matrix-org/go-neb/database/schema.go @@ -298,22 +298,26 @@ func insertAuthSessionTxn(txn *sql.Tx, now time.Time, session types.AuthSession) } const selectAuthSessionSQL = ` -SELECT realm_type, session_json FROM auth_sessions +SELECT realm_type, realm_json, session_json FROM auth_sessions JOIN auth_realms ON auth_sessions.realm_id = auth_realms.realm_id WHERE auth_sessions.realm_id = $1 AND auth_sessions.user_id = $2 ` func selectAuthSessionTxn(txn *sql.Tx, realmID, userID string) (types.AuthSession, error) { var realmType string + var realmJSON []byte var sessionJSON []byte row := txn.QueryRow(selectAuthSessionSQL, realmID, userID) - if err := row.Scan(&realmType, &sessionJSON); err != nil { + if err := row.Scan(&realmType, &realmJSON, &sessionJSON); err != nil { return nil, err } realm := types.CreateAuthRealm(realmID, realmType) if realm == nil { return nil, fmt.Errorf("Cannot create realm of type %s", realmType) } + if err := json.Unmarshal(realmJSON, realm); err != nil { + return nil, err + } session := realm.AuthSession(userID, json.RawMessage(sessionJSON)) if session == nil { return nil, fmt.Errorf("Cannot create session for given realm")