Skip to content

Commit 27043f5

Browse files
sethmlarsonhroncok
authored andcommitted
pythongh-143923: Reject control characters in POP3 commands (cherry-picked from commit b234a2b)
1 parent 3b1b4dd commit 27043f5

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
@@ -117,6 +117,8 @@ def _putline(self, line):
117117
def _putcmd(self, line):
118118
if self._debugging: print('*cmd*', repr(line))
119119
line = bytes(line, self.encoding)
120+
if re.search(b'[\x00-\x1F\x7F]', line):
121+
raise ValueError('Control characters not allowed in commands')
120122
self._putline(line)
121123

122124

Lib/test/test_poplib.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
from unittest import TestCase, skipUnless
1414
from test import support as test_support
15+
from test.support import control_characters_c0
1516
threading = test_support.import_module('threading')
1617

1718
HOST = test_support.HOST
@@ -349,6 +350,13 @@ def test_quit(self):
349350
self.assertIsNone(self.client.sock)
350351
self.assertIsNone(self.client.file)
351352

353+
def test_control_characters(self):
354+
for c0 in control_characters_c0():
355+
with self.assertRaises(ValueError):
356+
self.client.user(f'user{c0}')
357+
with self.assertRaises(ValueError):
358+
self.client.pass_(f'{c0}pass')
359+
352360
@requires_ssl
353361
def test_stls_capa(self):
354362
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)