Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
1e5c5f8f
Kaydet (Commit)
1e5c5f8f
authored
Ara 03, 2010
tarafından
Georg Brandl
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
#1745035: add limits for command and data size to smtpd; patch by Savio Sena.
üst
106a54d7
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
0 deletions
+45
-0
smtpd.py
Lib/smtpd.py
+24
-0
test_smtpd.py
Lib/test/test_smtpd.py
+18
-0
NEWS
Misc/NEWS
+3
-0
No files found.
Lib/smtpd.py
Dosyayı görüntüle @
1e5c5f8f
...
...
@@ -109,6 +109,9 @@ class SMTPChannel(asynchat.async_chat):
COMMAND
=
0
DATA
=
1
data_size_limit
=
33554432
command_size_limit
=
512
def
__init__
(
self
,
server
,
conn
,
addr
):
asynchat
.
async_chat
.
__init__
(
self
,
conn
)
self
.
smtp_server
=
server
...
...
@@ -121,6 +124,7 @@ class SMTPChannel(asynchat.async_chat):
self
.
rcpttos
=
[]
self
.
received_data
=
''
self
.
fqdn
=
socket
.
getfqdn
()
self
.
num_bytes
=
0
try
:
self
.
peer
=
conn
.
getpeername
()
except
socket
.
error
as
err
:
...
...
@@ -262,6 +266,15 @@ class SMTPChannel(asynchat.async_chat):
# Implementation of base class abstract method
def
collect_incoming_data
(
self
,
data
):
limit
=
None
if
self
.
smtp_state
==
self
.
COMMAND
:
limit
=
self
.
command_size_limit
elif
self
.
smtp_state
==
self
.
DATA
:
limit
=
self
.
data_size_limit
if
limit
and
self
.
num_bytes
>
limit
:
return
elif
limit
:
self
.
num_bytes
+=
len
(
data
)
self
.
received_lines
.
append
(
str
(
data
,
"utf8"
))
# Implementation of base class abstract method
...
...
@@ -270,6 +283,11 @@ class SMTPChannel(asynchat.async_chat):
print
(
'Data:'
,
repr
(
line
),
file
=
DEBUGSTREAM
)
self
.
received_lines
=
[]
if
self
.
smtp_state
==
self
.
COMMAND
:
if
self
.
num_bytes
>
self
.
command_size_limit
:
self
.
push
(
'500 Error: line too long'
)
self
.
num_bytes
=
0
return
self
.
num_bytes
=
0
if
not
line
:
self
.
push
(
'500 Error: bad syntax'
)
return
...
...
@@ -290,6 +308,11 @@ class SMTPChannel(asynchat.async_chat):
else
:
if
self
.
smtp_state
!=
self
.
DATA
:
self
.
push
(
'451 Internal confusion'
)
self
.
num_bytes
=
0
return
if
self
.
num_bytes
>
self
.
data_size_limit
:
self
.
push
(
'552 Error: Too much mail data'
)
self
.
num_bytes
=
0
return
# Remove extraneous carriage returns and de-transparency according
# to RFC 821, Section 4.5.2.
...
...
@@ -307,6 +330,7 @@ class SMTPChannel(asynchat.async_chat):
self
.
rcpttos
=
[]
self
.
mailfrom
=
None
self
.
smtp_state
=
self
.
COMMAND
self
.
num_bytes
=
0
self
.
set_terminator
(
b
'
\r\n
'
)
if
not
status
:
self
.
push
(
'250 Ok'
)
...
...
Lib/test/test_smtpd.py
Dosyayı görüntüle @
1e5c5f8f
...
...
@@ -121,6 +121,24 @@ class SMTPDChannelTest(TestCase):
self
.
assertEqual
(
self
.
channel
.
socket
.
last
,
b
'451 Internal confusion
\r\n
'
)
def
test_command_too_long
(
self
):
self
.
write_line
(
b
'MAIL from '
+
b
'a'
*
self
.
channel
.
command_size_limit
+
b
'@example'
)
self
.
assertEqual
(
self
.
channel
.
socket
.
last
,
b
'500 Error: line too long
\r\n
'
)
def
test_data_too_long
(
self
):
# Small hack. Setting limit to 2K octets here will save us some time.
self
.
channel
.
data_size_limit
=
2048
self
.
write_line
(
b
'MAIL From:eggs@example'
)
self
.
write_line
(
b
'RCPT To:spam@example'
)
self
.
write_line
(
b
'DATA'
)
self
.
write_line
(
b
'A'
*
self
.
channel
.
data_size_limit
+
b
'A
\r\n
.'
)
self
.
assertEqual
(
self
.
channel
.
socket
.
last
,
b
'552 Error: Too much mail data
\r\n
'
)
def
test_need_MAIL
(
self
):
self
.
write_line
(
b
'RCPT to:spam@example'
)
self
.
assertEqual
(
self
.
channel
.
socket
.
last
,
...
...
Misc/NEWS
Dosyayı görüntüle @
1e5c5f8f
...
...
@@ -33,6 +33,9 @@ Core and Builtins
Library
-------
- Issue #1745035: Add a command size and data size limit to smtpd.py, to
prevent DoS attacks. Patch by Savio Sena.
- Issue #4925: Add filename to error message when executable can't be found in
subprocess.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment