mirror of
https://github.com/FrankerFaceZ/FrankerFaceZ.git
synced 2025-08-03 16:38:31 +00:00
Close the connection if we get corrupted commands.
This commit is contained in:
parent
cf238bf650
commit
62c9659430
4 changed files with 23 additions and 9 deletions
|
@ -99,7 +99,8 @@ func HTTPBackendUncachedPublish(w http.ResponseWriter, r *http.Request) {
|
|||
count = PublishToMultiple(strings.Split(channel, ","), cm)
|
||||
case MsgTargetTypeGlobal:
|
||||
count = PublishToAll(cm)
|
||||
case MsgTargetTypeInvalid: fallthrough
|
||||
case MsgTargetTypeInvalid:
|
||||
fallthrough
|
||||
default:
|
||||
w.WriteHeader(422)
|
||||
fmt.Fprint(w, "Invalid 'scope'. must be chat, multichat, channel, or global")
|
||||
|
|
|
@ -15,6 +15,7 @@ import (
|
|||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
// 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,
|
||||
}
|
||||
|
||||
var CloseNonUTF8Data = websocket.CloseError{
|
||||
Code: 4001,
|
||||
Text: "Non UTF8 data recieved. Network corruption likely.",
|
||||
}
|
||||
|
||||
const sendMessageBufferLength = 125
|
||||
const sendMessageAbortLength = 50
|
||||
|
||||
|
@ -298,6 +304,13 @@ RunLoop:
|
|||
break RunLoop
|
||||
}
|
||||
|
||||
for _, char := range msg.Command {
|
||||
if char == utf8.RuneError {
|
||||
closeReason = CloseNonUTF8Data
|
||||
break RunLoop
|
||||
}
|
||||
}
|
||||
|
||||
DispatchC2SCommand(conn, &client, msg)
|
||||
|
||||
case msg := <-serverMessageChan:
|
||||
|
|
|
@ -6,9 +6,9 @@ import (
|
|||
"net/http"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type PushCommandCacheInfo struct {
|
||||
|
|
|
@ -141,19 +141,19 @@ func TCheckResponse(tb testing.TB, resp *http.Response, expected string, desc st
|
|||
}
|
||||
|
||||
type TURLs struct {
|
||||
Websocket string
|
||||
Origin string
|
||||
Websocket string
|
||||
Origin string
|
||||
UncachedPubMsg string // uncached_pub
|
||||
SavePubMsg string // cached_pub
|
||||
SavePubMsg string // cached_pub
|
||||
}
|
||||
|
||||
func TGetUrls(testserver *httptest.Server) TURLs {
|
||||
addr := testserver.Listener.Addr().String()
|
||||
return TURLs{
|
||||
Websocket: fmt.Sprintf("ws://%s/", addr),
|
||||
Origin: fmt.Sprintf("http://%s", addr),
|
||||
UncachedPubMsg: fmt.Sprintf("http://%s/uncached_pub", addr),
|
||||
SavePubMsg: fmt.Sprintf("http://%s/cached_pub", addr),
|
||||
Websocket: fmt.Sprintf("ws://%s/", addr),
|
||||
Origin: fmt.Sprintf("http://%s", addr),
|
||||
UncachedPubMsg: fmt.Sprintf("http://%s/uncached_pub", addr),
|
||||
SavePubMsg: fmt.Sprintf("http://%s/cached_pub", addr),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue