Explorar el Código

improve nick and channel length validation

tags/v2.0.0-rc1
Shivaram Lingamneni hace 4 años
padre
commit
8123e3c08f
Se han modificado 3 ficheros con 19 adiciones y 9 borrados
  1. 2
    2
      irc/client_lookup_set.go
  2. 6
    0
      irc/config.go
  3. 11
    7
      irc/mysql/history.go

+ 2
- 2
irc/client_lookup_set.go Ver fichero

@@ -115,11 +115,12 @@ func (clients *ClientManager) Resume(oldClient *Client, session *Session) (err e
115 115
 
116 116
 // SetNick sets a client's nickname, validating it against nicknames in use
117 117
 func (clients *ClientManager) SetNick(client *Client, session *Session, newNick string) (setNick string, err error) {
118
+	config := client.server.Config()
118 119
 	newcfnick, err := CasefoldName(newNick)
119 120
 	if err != nil {
120 121
 		return "", errNicknameInvalid
121 122
 	}
122
-	if len(newcfnick) > client.server.Config().Limits.NickLen {
123
+	if len(newNick) > config.Limits.NickLen || len(newcfnick) > config.Limits.NickLen {
123 124
 		return "", errNicknameInvalid
124 125
 	}
125 126
 	newSkeleton, err := Skeleton(newNick)
@@ -132,7 +133,6 @@ func (clients *ClientManager) SetNick(client *Client, session *Session, newNick
132 133
 	}
133 134
 
134 135
 	reservedAccount, method := client.server.accounts.EnforcementStatus(newcfnick, newSkeleton)
135
-	config := client.server.Config()
136 136
 	client.stateMutex.RLock()
137 137
 	account := client.account
138 138
 	accountName := client.accountName

+ 6
- 0
irc/config.go Ver fichero

@@ -28,6 +28,7 @@ import (
28 28
 	"github.com/oragono/oragono/irc/ldap"
29 29
 	"github.com/oragono/oragono/irc/logger"
30 30
 	"github.com/oragono/oragono/irc/modes"
31
+	"github.com/oragono/oragono/irc/mysql"
31 32
 	"github.com/oragono/oragono/irc/passwd"
32 33
 	"github.com/oragono/oragono/irc/utils"
33 34
 	"gopkg.in/yaml.v2"
@@ -817,6 +818,11 @@ func LoadConfig(filename string) (config *Config, err error) {
817 818
 	if config.Limits.RegistrationMessages == 0 {
818 819
 		config.Limits.RegistrationMessages = 1024
819 820
 	}
821
+	if config.Datastore.MySQL.Enabled {
822
+		if config.Limits.NickLen > mysql.MaxTargetLength || config.Limits.ChannelLen > mysql.MaxTargetLength {
823
+			return nil, fmt.Errorf("to use MySQL, nick and channel length limits must be %d or lower", mysql.MaxTargetLength)
824
+		}
825
+	}
820 826
 
821 827
 	config.Server.supportedCaps = caps.NewCompleteSet()
822 828
 	config.Server.capValues = make(caps.Values)

+ 11
- 7
irc/mysql/history.go Ver fichero

@@ -15,6 +15,10 @@ import (
15 15
 )
16 16
 
17 17
 const (
18
+	// maximum length in bytes of any message target (nickname or channel name) in its
19
+	// canonicalized (i.e., casefolded) state:
20
+	MaxTargetLength = 64
21
+
18 22
 	// latest schema of the db
19 23
 	latestDbSchema   = "1"
20 24
 	keySchemaVersion = "db.version"
@@ -120,27 +124,27 @@ func (mysql *MySQL) createTables() (err error) {
120 124
 		return err
121 125
 	}
122 126
 
123
-	_, err = mysql.db.Exec(`CREATE TABLE sequence (
127
+	_, err = mysql.db.Exec(fmt.Sprintf(`CREATE TABLE sequence (
124 128
 		id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
125
-		target VARBINARY(64) NOT NULL,
129
+		target VARBINARY(%[1]d) NOT NULL,
126 130
 		nanotime BIGINT UNSIGNED NOT NULL,
127 131
 		history_id BIGINT NOT NULL,
128 132
 		KEY (target, nanotime),
129 133
 		KEY (history_id)
130
-	) CHARSET=ascii COLLATE=ascii_bin;`)
134
+	) CHARSET=ascii COLLATE=ascii_bin;`, MaxTargetLength))
131 135
 	if err != nil {
132 136
 		return err
133 137
 	}
134 138
 
135
-	_, err = mysql.db.Exec(`CREATE TABLE conversations (
139
+	_, err = mysql.db.Exec(fmt.Sprintf(`CREATE TABLE conversations (
136 140
 		id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
137
-		lower_target VARBINARY(64) NOT NULL,
138
-		upper_target VARBINARY(64) NOT NULL,
141
+		lower_target VARBINARY(%[1]d) NOT NULL,
142
+		upper_target VARBINARY(%[1]d) NOT NULL,
139 143
 		nanotime BIGINT UNSIGNED NOT NULL,
140 144
 		history_id BIGINT NOT NULL,
141 145
 		KEY (lower_target, upper_target, nanotime),
142 146
 		KEY (history_id)
143
-	) CHARSET=ascii COLLATE=ascii_bin;`)
147
+	) CHARSET=ascii COLLATE=ascii_bin;`, MaxTargetLength))
144 148
 	if err != nil {
145 149
 		return err
146 150
 	}

Loading…
Cancelar
Guardar