1
0
Fork 0
mirror of https://github.com/binwiederhier/ntfy.git synced 2024-11-22 03:13:33 +01:00

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

@ -97,7 +97,10 @@ func (c *Client) Publish(topic, message string, options ...PublishOption) (*Mess
// WithNoFirebase, and the generic WithHeader.
func (c *Client) PublishReader(topic string, body io.Reader, options ...PublishOption) (*Message, error) {
topicURL := c.expandTopicURL(topic)
req, _ := http.NewRequest("POST", topicURL, body)
req, err := http.NewRequest("POST", topicURL, body)
if err != nil {
return nil, err
}
for _, option := range options {
if err := option(req); err != nil {
return nil, err

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

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

View file

@ -1226,6 +1226,7 @@ and the [ntfy Android app](https://github.com/binwiederhier/ntfy-android/release
* Support encoding any header as RFC 2047 ([#737](https://github.com/binwiederhier/ntfy/issues/737), thanks to [@cfouche3005](https://github.com/cfouche3005) for reporting)
* Do not forward poll requests for UnifiedPush messages (no ticket, thanks to NoName for reporting)
* Fix `ntfy pub %` segfaulting ([#760](https://github.com/binwiederhier/ntfy/issues/760), thanks to [@clesmian](https://github.com/clesmian) for reporting)
**Maintenance:**