1
0
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:
Pascal S. de Kloe
2021-03-12 14:30:24 +01:00
parent fbc3958c3f
commit ca1df581db

View File

@@ -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)