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"
|
"github.com/pascaldekloe/mqtt"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const messageMax = 256 * 1024 * 1024
|
||||||
|
|
||||||
// ANSI escape codes for markup.
|
// ANSI escape codes for markup.
|
||||||
const (
|
const (
|
||||||
bold = "\x1b[1m"
|
bold = "\x1b[1m"
|
||||||
@@ -148,9 +150,12 @@ func main() {
|
|||||||
go func() {
|
go func() {
|
||||||
if *publishFlag != "" {
|
if *publishFlag != "" {
|
||||||
// publish standard input
|
// publish standard input
|
||||||
message, err := io.ReadAll(os.Stdin)
|
message, err := io.ReadAll(io.LimitReader(os.Stdin, messageMax))
|
||||||
if err != nil {
|
switch {
|
||||||
log.Fatal(err)
|
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)
|
ctx, cancel := context.WithTimeout(context.Background(), *timeoutFlag)
|
||||||
|
Reference in New Issue
Block a user