diff options
author | dusoleil <howcansocksbereal@gmail.com> | 2023-02-26 07:09:29 -0500 |
---|---|---|
committer | dusoleil <howcansocksbereal@gmail.com> | 2023-03-01 13:07:58 -0500 |
commit | 7e3387516d32c746cd1c6588be71a9ed0d70a02d (patch) | |
tree | 74102fa51f0291fb61a004f31d0fa9464c99f933 | |
parent | 4b80ca684eea86fb9e64d6ab5ec606bb403cb4cd (diff) | |
download | sploit-7e3387516d32c746cd1c6588be71a9ed0d70a02d.tar.gz sploit-7e3387516d32c746cd1c6588be71a9ed0d70a02d.zip |
Add special cases for read(size <= 0)
A read of 0 isn't particularly useful, but it is weird that it will
cause a BrokenPipeError. Instead, it makes more sense to just return an
empty string.
A read of <0 would normally read until EOF, but we already have that
feature in readall() and it wouldn't be particularly useful here. A
similar functionality of reading the entire current contents of the
buffer is useful, though. This is already implemented in
readall_nonblock() and this would be a nice user-facing way of calling
that.
Signed-off-by: dusoleil <howcansocksbereal@gmail.com>
-rw-r--r-- | sploit/comm.py | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/sploit/comm.py b/sploit/comm.py index e9ea53d..8078c9f 100644 --- a/sploit/comm.py +++ b/sploit/comm.py @@ -24,10 +24,15 @@ class Comm: except BrokenPipeError: pass - def read(self, size): - data = self.back.stdin.read(size) - if(data == b''): - raise BrokenPipeError('Tried to read on broken pipe') + def read(self, size=-1): + if size < 0: + return self.readall_nonblock() + elif size == 0: + data = b'' + else: + data = self.back.stdin.read(size) + if(data == b''): + raise BrokenPipeError('Tried to read on broken pipe') if self.logonread : ilog(data, file=sys.stdout, color=NORMAL) self.last = data return data |