Skip to content

Commit d47c31a

Browse files
committed
Properly quote the %(body)s and %(from)s used in the simple_notify plugin.
1 parent 73b8add commit d47c31a

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

doc/en/plugins/simple_notify.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ command = notify-send -i /path/to/poezio/data/poezio_80.png "New message from %(
2020
[source,conf]
2121
---------------------------------------------------------------------
2222
[simple_notify]
23-
command = echo %{from}s\> %{body}s >> some.fifo
23+
command = echo \\<%{from}s\\> %{body}s >> some.fifo
2424
delay = 3
25-
after_command echo = >> some.fifo
25+
after_command = echo >> some.fifo
2626
---------------------------------------------------------------------
2727

2828
You can put any command, instead of these ones. You can also use the

plugins/simple_notify.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from plugin import BasePlugin
22
from xhtml import clean_text, get_body_from_message_stanza
33
from timed_events import DelayedEvent
4+
import pipes
45

56
class Plugin(BasePlugin):
67
def init(self):
@@ -28,9 +29,10 @@ def do_notify(self, message, fro):
2829
if not command:
2930
self.core.information('No notification command was provided in the configuration file', 'Warning')
3031
return
31-
self.core.exec_command(command % {'body':body, 'from':fro})
32+
self.core.exec_command(command % {'body':pipes.quote(body), 'from':pipes.quote(fro)})
3233
after_command = self.config.get('after_command', '').strip()
3334
if not after_command:
3435
return
35-
delayed_event = DelayedEvent(self.config.get('delay', 1), self.core.exec_command, after_command % {'body':body, 'from':fro})
36+
delayed_event = DelayedEvent(self.config.get('delay', 1), self.core.exec_command, after_command % {'body':pipes.quote(body), 'from':pipes.quote(fro)})
3637
self.core.add_timed_event(delayed_event)
38+
4

src/daemon.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,19 @@
2929

3030
class Executor(threading.Thread):
3131
"""
32-
Just a class to execute commands in a thread.
33-
This way, the execution can totally fail, we don’t care,
34-
and we can start commands without having to wait for them
35-
to return
32+
Just a class to execute commands in a thread. This way, the execution
33+
can totally fail, we don’t care, and we can start commands without
34+
having to wait for them to return.
35+
WARNING: Be careful to properly escape what is untrusted by using
36+
pipes.quote (or shlex.quote with python 3.3) for example.
3637
"""
3738
def __init__(self, command):
3839
threading.Thread.__init__(self)
3940
self.command = command
4041

4142
def run(self):
42-
log.info('executing %s' % (self.command.strip(),))
43-
command = shlex.split('sh -c "%s"' % self.command)
44-
subprocess.call(command)
43+
log.info('executing %s' % (self.command,))
44+
subprocess.call(['sh', '-c', self.command])
4545

4646
def main():
4747
while True:

0 commit comments

Comments
 (0)