Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c91d60a

Browse files
committed
Changes to protect servers against broken clients
1 parent 424c673 commit c91d60a

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

Demo/rpc/xdr.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ def unpack_uint(self):
8989
i = self.pos
9090
self.pos = j = i+4
9191
data = self.buf[i:j]
92+
if len(data) < 4:
93+
raise EOFError
9294
x = long(ord(data[0]))<<24 | ord(data[1])<<16 | \
9395
ord(data[2])<<8 | ord(data[3])
9496
# Return a Python long only if the value is not representable
@@ -99,7 +101,10 @@ def unpack_uint(self):
99101
def unpack_uint(self):
100102
i = self.pos
101103
self.pos = j = i+4
102-
return struct.unpack('l', self.buf[i:j])
104+
data = self.buf[i:j]
105+
if len(data) < 4:
106+
raise EOFError
107+
return struct.unpack('l', data)
103108

104109
def unpack_int(self):
105110
x = self.unpack_uint()
@@ -126,7 +131,7 @@ def unpack_fstring(self, n):
126131
i = self.pos
127132
j = i + (n+3)/4*4
128133
if j > len(self.buf):
129-
raise RuntimeError, 'buffer overrun'
134+
raise EOFError
130135
self.pos = j
131136
return self.buf[i:i+n]
132137

0 commit comments

Comments
 (0)