1
0
Fork 0
mirror of https://github.com/FrankerFaceZ/FrankerFaceZ.git synced 2025-08-06 06:10:54 +00:00

Close the connection if we get corrupted commands.

This commit is contained in:
Kane York 2015-11-19 16:55:03 -08:00
parent cf238bf650
commit 62c9659430
4 changed files with 23 additions and 9 deletions

View file

@ -99,7 +99,8 @@ func HTTPBackendUncachedPublish(w http.ResponseWriter, r *http.Request) {
count = PublishToMultiple(strings.Split(channel, ","), cm) count = PublishToMultiple(strings.Split(channel, ","), cm)
case MsgTargetTypeGlobal: case MsgTargetTypeGlobal:
count = PublishToAll(cm) count = PublishToAll(cm)
case MsgTargetTypeInvalid: fallthrough case MsgTargetTypeInvalid:
fallthrough
default: default:
w.WriteHeader(422) w.WriteHeader(422)
fmt.Fprint(w, "Invalid 'scope'. must be chat, multichat, channel, or global") fmt.Fprint(w, "Invalid 'scope'. must be chat, multichat, channel, or global")

View file

@ -15,6 +15,7 @@ import (
"sync" "sync"
"sync/atomic" "sync/atomic"
"time" "time"
"unicode/utf8"
) )
// SuccessCommand is a Reply Command to indicate success in reply to a C2S Command. // SuccessCommand is a Reply Command to indicate success in reply to a C2S Command.
@ -179,6 +180,11 @@ var CloseFirstMessageNotHello = websocket.CloseError{
Code: websocket.ClosePolicyViolation, Code: websocket.ClosePolicyViolation,
} }
var CloseNonUTF8Data = websocket.CloseError{
Code: 4001,
Text: "Non UTF8 data recieved. Network corruption likely.",
}
const sendMessageBufferLength = 125 const sendMessageBufferLength = 125
const sendMessageAbortLength = 50 const sendMessageAbortLength = 50
@ -298,6 +304,13 @@ RunLoop:
break RunLoop break RunLoop
} }
for _, char := range msg.Command {
if char == utf8.RuneError {
closeReason = CloseNonUTF8Data
break RunLoop
}
}
DispatchC2SCommand(conn, &client, msg) DispatchC2SCommand(conn, &client, msg)
case msg := <-serverMessageChan: case msg := <-serverMessageChan:

View file

@ -6,9 +6,9 @@ import (
"net/http" "net/http"
"sort" "sort"
"strconv" "strconv"
"strings"
"sync" "sync"
"time" "time"
"strings"
) )
type PushCommandCacheInfo struct { type PushCommandCacheInfo struct {