Patchwork [patchbot] patchbot: do not crash for malicious mails without message-id

login
register
mail settings
Submitter Jun Wu
Date Nov. 17, 2016, 3:16 a.m.
Message ID <7ecfbdf2460df04c1c26.1479352603@x1c>
Download mbox | patch
Permalink /patch/17611/
State Accepted
Headers show

Comments

Jun Wu - Nov. 17, 2016, 3:16 a.m.
# HG changeset patch
# User Jun Wu <quark@fb.com>
# Date 1479352538 0
#      Thu Nov 17 03:15:38 2016 +0000
# Node ID 7ecfbdf2460df04c1c263875a12403d3cfe3134a
# Parent  9036c3d03d301378e67d4516937ea9c6672c3c67
patchbot: do not crash for malicious mails without message-id

Sometimes due to power failure, the on-disk files could get truncated and
lose message-id. Currently patchbot would raise "KeyError: message-id" but
it does not print clues about which mail is corrupted.

This patch makes it print which mail does not contain message-id and just
ignore them.
Augie Fackler - Nov. 18, 2016, 1:58 a.m.
> On Nov 16, 2016, at 10:16 PM, Jun Wu <quark@fb.com> wrote:
> 
> # HG changeset patch
> # User Jun Wu <quark@fb.com>
> # Date 1479352538 0
> #      Thu Nov 17 03:15:38 2016 +0000
> # Node ID 7ecfbdf2460df04c1c263875a12403d3cfe3134a
> # Parent  9036c3d03d301378e67d4516937ea9c6672c3c67
> patchbot: do not crash for malicious mails without message-id

Queued for patchbot, thanks

> 
> Sometimes due to power failure, the on-disk files could get truncated and
> lose message-id. Currently patchbot would raise "KeyError: message-id" but
> it does not print clues about which mail is corrupted.
> 
> This patch makes it print which mail does not contain message-id and just
> ignore them.
> 
> diff --git a/index.py b/index.py
> --- a/index.py
> +++ b/index.py
> @@ -51,4 +51,7 @@ def index_mailbox(session, mb):
>             if key not in all_keys:
>                 mail = mb[key]
> +                if 'message-id' not in mail:
> +                    sys.stderr.write('%s: ignored - no message-id\n' % key)
> +                    continue
>                 if session.query(models.Message).filter(models.Message.id.is_(
>                         mail['message-id'])).count() > 0:
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Patch

diff --git a/index.py b/index.py
--- a/index.py
+++ b/index.py
@@ -51,4 +51,7 @@  def index_mailbox(session, mb):
             if key not in all_keys:
                 mail = mb[key]
+                if 'message-id' not in mail:
+                    sys.stderr.write('%s: ignored - no message-id\n' % key)
+                    continue
                 if session.query(models.Message).filter(models.Message.id.is_(
                         mail['message-id'])).count() > 0: