Skip to content

Commit 3c5a0d1

Browse files
sethmlarsonhroncok
authored andcommitted
Reject control characters in POP3 commands
1 parent ae2cfac commit 3c5a0d1

3 files changed

Lines changed: 11 additions & 0 deletions

File tree

Lib/poplib.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ def _putline(self, line):
122122
def _putcmd(self, line):
123123
if self._debugging: print('*cmd*', repr(line))
124124
line = bytes(line, self.encoding)
125+
if re.search(b'[\x00-\x1F\x7F]', line):
126+
raise ValueError('Control characters not allowed in commands')
125127
self._putline(line)
126128

127129

Lib/test/test_poplib.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from test.support import asynchat
1919
from test.support import asyncore
2020
from test.support.testcase import ExtraAssertions
21+
from test.support import control_characters_c0
2122

2223

2324
test_support.requires_working_socket(module=True)
@@ -396,6 +397,13 @@ def test_quit(self):
396397
self.assertIsNone(self.client.sock)
397398
self.assertIsNone(self.client.file)
398399

400+
def test_control_characters(self):
401+
for c0 in control_characters_c0():
402+
with self.assertRaises(ValueError):
403+
self.client.user(f'user{c0}')
404+
with self.assertRaises(ValueError):
405+
self.client.pass_(f'{c0}pass')
406+
399407
@requires_ssl
400408
def test_stls_capa(self):
401409
capa = self.client.capa()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Reject control characters in POP3 commands.

0 commit comments

Comments
 (0)