Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Lib/test/test_imaplib.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,14 @@ def handle(self):
self.assertRaises(imaplib.IMAP4.abort,
self.imap_class, *server.server_address)

@reap_threads
def test_control_characters(self):
with self.reaped_server(SimpleIMAPHandler) as server:
client = self.imap_class(*server.server_address)
for c0 in [chr(c) for c in range(0x20)] + ['\x7f']:
self.assertRaises(ValueError, client.login, 'user%s' % c0, 'pass')
client.shutdown()


class ThreadedNetworkedTests(BaseThreadedNetworkedTests):

Expand Down
3 changes: 3 additions & 0 deletions lib-python/2.7/imaplib.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
Response_code = re.compile(r'\[(?P<type>[A-Z-]+)( (?P<data>[^\]]*))?\]')
Untagged_response = re.compile(r'\* (?P<type>[A-Z-]+)( (?P<data>.*))?')
Untagged_status = re.compile(r'\* (?P<data>\d+) (?P<type>[A-Z-]+)( (?P<data2>.*))?')
_control_chars = re.compile(r'[\x00-\x1F\x7F]')



Expand Down Expand Up @@ -848,6 +849,8 @@ def _command(self, name, *args):
data = '%s %s' % (tag, name)
for arg in args:
if arg is None: continue
if isinstance(arg, basestring) and _control_chars.search(arg):
raise ValueError("Control characters not allowed in commands")
data = '%s %s' % (data, self._checkquote(arg))

literal = self.literal
Expand Down
2 changes: 2 additions & 0 deletions lib-python/2.7/poplib.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ def _putline(self, line):

def _putcmd(self, line):
if self._debugging: print '*cmd*', repr(line)
if re.search(r'[\x00-\x1F\x7F]', line):
raise ValueError('Control characters not allowed in commands')
self._putline(line)


Expand Down
5 changes: 5 additions & 0 deletions lib-python/2.7/test/test_poplib.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,11 @@ def test_pass_(self):
self.assertOK(self.client.pass_('python'))
self.assertRaises(poplib.error_proto, self.client.user, 'invalid')

def test_control_characters(self):
for c0 in [chr(c) for c in range(0x20)] + ['\x7f']:
self.assertRaises(ValueError, self.client.user, 'user%s' % c0)
self.assertRaises(ValueError, self.client.pass_, '%spass' % c0)

def test_stat(self):
self.assertEqual(self.client.stat(), (10, 100))

Expand Down
Loading