diff options
| author | Julien Phalip <jphalip@gmail.com> | 2012-02-11 09:31:18 +0000 |
|---|---|---|
| committer | Julien Phalip <jphalip@gmail.com> | 2012-02-11 09:31:18 +0000 |
| commit | 995f7a16a8bf539caf076a7744441a383e9a38b2 (patch) | |
| tree | 8181ab890022da6db89795cd6d22ebd2b5813801 /django/utils/log.py | |
| parent | a77679dfaa963361b6daad6de0d7de1b53d4f104 (diff) | |
Fixed #17281 -- Prevented `AdminErrorHandler` from silently failing if the log message contains newlines. Thanks to Russell Keith-Magee for the report and to Bartolome Sanchez Salado and Marcin Wróbel for the patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17501 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/utils/log.py')
| -rw-r--r-- | django/utils/log.py | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/django/utils/log.py b/django/utils/log.py index 8ce37f5309..16ad5f05de 100644 --- a/django/utils/log.py +++ b/django/utils/log.py @@ -47,18 +47,20 @@ class AdminEmailHandler(logging.Handler): request = record.request subject = '%s (%s IP): %s' % ( record.levelname, - (request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS and 'internal' or 'EXTERNAL'), + (request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS + and 'internal' or 'EXTERNAL'), record.msg ) filter = get_exception_reporter_filter(request) request_repr = filter.get_request_repr(request) - except: + except Exception: subject = '%s: %s' % ( record.levelname, record.getMessage() ) request = None request_repr = "Request repr() unavailable." + subject = self.format_subject(subject) if record.exc_info: exc_info = record.exc_info @@ -72,6 +74,15 @@ class AdminEmailHandler(logging.Handler): html_message = self.include_html and reporter.get_traceback_html() or None mail.mail_admins(subject, message, fail_silently=True, html_message=html_message) + def format_subject(self, subject): + """ + Escape CR and LF characters, and limit length. + RFC 2822's hard limit is 998 characters per line. So, minus "Subject: " + the actual subject must be no longer than 989 characters. + """ + formatted_subject = subject.replace('\n', '\\n').replace('\r', '\\r') + return formatted_subject[:989] + class CallbackFilter(logging.Filter): """ |
