From 68118136f23560a729cb68d28de3f566892779cb Mon Sep 17 00:00:00 2001 From: Chris Sexton Date: Sun, 20 Oct 2019 10:39:31 -0400 Subject: [PATCH] fuck: stop he-who-must-not-be-named's antics * verify instruction limit setting * truncate output buffer --- plugins/fuck/fuck.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/plugins/fuck/fuck.go b/plugins/fuck/fuck.go index 94054c1..4171757 100644 --- a/plugins/fuck/fuck.go +++ b/plugins/fuck/fuck.go @@ -58,8 +58,16 @@ func (p *Fuck) message(c bot.Connector, kind bot.Kind, message msg.Message, args m := gofuck.New(stdin, stdout) m.InstructionLimit = p.c.GetInt("fuck.limit.instr", 100000) + if m.InstructionLimit < 1 { + m.InstructionLimit = 1 + } + maxOut := p.c.GetInt("fuck.limit.output", 1000) - if err := m.Run([]byte(pgm)); err != nil { + err := m.Run([]byte(pgm)) + if stdout.Len() > maxOut { + stdout.Truncate(maxOut) + } + if err != nil { p.b.Send(c, bot.Message, message.Channel, fmt.Sprintf("Error running program: %s", err)) if stdout.Len() > 0 { p.b.Send(c, bot.Message, message.Channel,