mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-11 06:29:29 +01:00
Merge pull request #1226 from slingamn/websocket_dos
mitigate a potential DoS against websocket listeners
This commit is contained in:
commit
88b09e5919
@ -124,16 +124,18 @@ func (wc IRCWSConn) WriteLines(buffers [][]byte) (err error) {
|
||||
}
|
||||
|
||||
func (wc IRCWSConn) ReadLine() (line []byte, err error) {
|
||||
for {
|
||||
var messageType int
|
||||
messageType, line, err = wc.conn.ReadMessage()
|
||||
// on empty message or non-text message, try again, block if necessary
|
||||
if err != nil || (messageType == websocket.TextMessage && len(line) != 0) {
|
||||
if err == websocket.ErrReadLimit {
|
||||
err = errReadQ
|
||||
}
|
||||
return
|
||||
messageType, line, err := wc.conn.ReadMessage()
|
||||
if err == nil {
|
||||
if messageType == websocket.TextMessage {
|
||||
return line, nil
|
||||
} else {
|
||||
// for purposes of fakelag, treat non-text message as an empty line
|
||||
return nil, nil
|
||||
}
|
||||
} else if err == websocket.ErrReadLimit {
|
||||
return line, errReadQ
|
||||
} else {
|
||||
return line, err
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user