Fix segault in ntfy pub

This commit is contained in:
binwiederhier 2023-06-01 14:08:51 -04:00
parent 04cc71af90
commit dc8932cd95
5 changed files with 13 additions and 2 deletions

View file

@ -29,6 +29,7 @@ var flagsDefault = []cli.Flag{
var (
logLevelOverrideRegex = regexp.MustCompile(`(?i)^([^=\s]+)(?:\s*=\s*(\S+))?\s*->\s*(TRACE|DEBUG|INFO|WARN|ERROR)$`)
topicRegex = regexp.MustCompile(`^[-_A-Za-z0-9]{1,64}$`) // Same as in server/server.go
)
// New creates a new CLI application

View file

@ -249,6 +249,10 @@ func parseTopicMessageCommand(c *cli.Context) (topic string, message string, com
if c.String("message") != "" {
message = c.String("message")
}
if !topicRegex.MatchString(topic) {
err = fmt.Errorf("topic %s contains invalid characters", topic)
return
}
return
}

View file

@ -72,7 +72,7 @@ ntfy subscribe TOPIC COMMAND
$NTFY_TITLE $title, $t Message title
$NTFY_PRIORITY $priority, $prio, $p Message priority (1=min, 5=max)
$NTFY_TAGS $tags, $tag, $ta Message tags (comma separated list)
$NTFY_RAW $raw Raw JSON message
$NTFY_RAW $raw Raw JSON message
Examples:
ntfy sub mytopic 'notify-send "$m"' # Execute command for incoming messages
@ -108,6 +108,8 @@ func execSubscribe(c *cli.Context) error {
// Checks
if user != "" && token != "" {
return errors.New("cannot set both --user and --token")
} else if !topicRegex.MatchString(topic) {
return fmt.Errorf("topic %s contains invalid characters", topic)
}
if !fromConfig {