mirror of
https://github.com/go-mqtt/mqtt.git
synced 2025-08-07 11:42:52 +03:00
Limit mqttc input size.
This commit is contained in:
@@ -18,6 +18,8 @@ import (
|
||||
"github.com/pascaldekloe/mqtt"
|
||||
)
|
||||
|
||||
const messageMax = 256 * 1024 * 1024
|
||||
|
||||
// ANSI escape codes for markup.
|
||||
const (
|
||||
bold = "\x1b[1m"
|
||||
@@ -148,9 +150,12 @@ func main() {
|
||||
go func() {
|
||||
if *publishFlag != "" {
|
||||
// publish standard input
|
||||
message, err := io.ReadAll(os.Stdin)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
message, err := io.ReadAll(io.LimitReader(os.Stdin, messageMax))
|
||||
switch {
|
||||
case err != nil:
|
||||
log.Fatal(name, ": ", err)
|
||||
case len(message) >= messageMax:
|
||||
log.Fatalf("%s: standard input reached %d byte limit", name, messageMax)
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), *timeoutFlag)
|
||||
|
Reference in New Issue
Block a user