mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-05 17:00:58 +01:00
Escape null bytes
This commit is contained in:
parent
e572c85532
commit
a96dedc296
2 changed files with 24 additions and 0 deletions
15
news/nullsub.rst
Normal file
15
news/nullsub.rst
Normal file
|
@ -0,0 +1,15 @@
|
|||
**Added:** None
|
||||
|
||||
**Changed:** None
|
||||
|
||||
**Deprecated:** None
|
||||
|
||||
**Removed:** None
|
||||
|
||||
**Fixed:**
|
||||
|
||||
* Null bytes handed to Popen are now automatically escaped prior
|
||||
to running a subprocess. This preevents Popen from issuing
|
||||
embedded null byte exceptions.
|
||||
|
||||
**Security:** None
|
|
@ -498,6 +498,7 @@ class SubprocSpec:
|
|||
kwargs.pop('preexec_fn')
|
||||
p = self.cls(self.alias, self.cmd, **kwargs)
|
||||
else:
|
||||
self._fix_null_cmd_bytes()
|
||||
p = self._run_binary(kwargs)
|
||||
p.spec = self
|
||||
p.last_in_pipeline = self.last_in_pipeline
|
||||
|
@ -546,6 +547,14 @@ class SubprocSpec:
|
|||
signal.signal(signal.SIGTSTP, default_signal_pauser)
|
||||
kwargs['preexec_fn'] = xonsh_preexec_fn
|
||||
|
||||
def _fix_null_cmd_bytes(self):
|
||||
# Popen does not accept null bytes in its input commands.
|
||||
# that doesn;t stop some subproces from using them. Here we
|
||||
# escape them just in case.
|
||||
cmd = self.cmd
|
||||
for i in range(len(cmd)):
|
||||
cmd[i] = cmd[i].replace('\0', '\\0')
|
||||
|
||||
#
|
||||
# Building methods
|
||||
#
|
||||
|
|
Loading…
Add table
Reference in a new issue