Fix segault in ntfy pub
This commit is contained in:
parent
04cc71af90
commit
dc8932cd95
5 changed files with 13 additions and 2 deletions
|
@ -97,7 +97,10 @@ func (c *Client) Publish(topic, message string, options ...PublishOption) (*Mess
|
||||||
// WithNoFirebase, and the generic WithHeader.
|
// WithNoFirebase, and the generic WithHeader.
|
||||||
func (c *Client) PublishReader(topic string, body io.Reader, options ...PublishOption) (*Message, error) {
|
func (c *Client) PublishReader(topic string, body io.Reader, options ...PublishOption) (*Message, error) {
|
||||||
topicURL := c.expandTopicURL(topic)
|
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 {
|
for _, option := range options {
|
||||||
if err := option(req); err != nil {
|
if err := option(req); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
@ -29,6 +29,7 @@ var flagsDefault = []cli.Flag{
|
||||||
|
|
||||||
var (
|
var (
|
||||||
logLevelOverrideRegex = regexp.MustCompile(`(?i)^([^=\s]+)(?:\s*=\s*(\S+))?\s*->\s*(TRACE|DEBUG|INFO|WARN|ERROR)$`)
|
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
|
// New creates a new CLI application
|
||||||
|
|
|
@ -249,6 +249,10 @@ func parseTopicMessageCommand(c *cli.Context) (topic string, message string, com
|
||||||
if c.String("message") != "" {
|
if c.String("message") != "" {
|
||||||
message = c.String("message")
|
message = c.String("message")
|
||||||
}
|
}
|
||||||
|
if !topicRegex.MatchString(topic) {
|
||||||
|
err = fmt.Errorf("topic %s contains invalid characters", topic)
|
||||||
|
return
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -72,7 +72,7 @@ ntfy subscribe TOPIC COMMAND
|
||||||
$NTFY_TITLE $title, $t Message title
|
$NTFY_TITLE $title, $t Message title
|
||||||
$NTFY_PRIORITY $priority, $prio, $p Message priority (1=min, 5=max)
|
$NTFY_PRIORITY $priority, $prio, $p Message priority (1=min, 5=max)
|
||||||
$NTFY_TAGS $tags, $tag, $ta Message tags (comma separated list)
|
$NTFY_TAGS $tags, $tag, $ta Message tags (comma separated list)
|
||||||
$NTFY_RAW $raw Raw JSON message
|
$NTFY_RAW $raw Raw JSON message
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
ntfy sub mytopic 'notify-send "$m"' # Execute command for incoming messages
|
ntfy sub mytopic 'notify-send "$m"' # Execute command for incoming messages
|
||||||
|
@ -108,6 +108,8 @@ func execSubscribe(c *cli.Context) error {
|
||||||
// Checks
|
// Checks
|
||||||
if user != "" && token != "" {
|
if user != "" && token != "" {
|
||||||
return errors.New("cannot set both --user and --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 {
|
if !fromConfig {
|
||||||
|
|
|
@ -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)
|
* 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)
|
* 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:**
|
**Maintenance:**
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue