From 02dac1130808c621ec6381d0693cfad69dd9024e Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Mon, 7 Feb 2022 21:38:36 +0100 Subject: [PATCH] Forbid empty and flag-looking network names --- user.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/user.go b/user.go index 777eb27..a1ff2d9 100644 --- a/user.go +++ b/user.go @@ -9,6 +9,7 @@ import ( "math/big" "net" "sort" + "strings" "time" "gopkg.in/irc.v3" @@ -830,6 +831,14 @@ func (u *user) checkNetwork(record *Network) error { return fmt.Errorf("unknown URL scheme %q", url.Scheme) } + if record.GetName() == "" { + return fmt.Errorf("network name cannot be empty") + } + if strings.HasPrefix(record.GetName(), "-") { + // Can be mixed up with flags when sending commands to the service + return fmt.Errorf("network name cannot start with a dash character") + } + for _, net := range u.networks { if net.GetName() == record.GetName() && net.ID != record.ID { return fmt.Errorf("a network with the name %q already exists", record.GetName())