]> git.ipfire.org Git - thirdparty/patchwork.git/commitdiff
Add fuzzer-generated tests
authorDaniel Axtens <dja@axtens.net>
Wed, 28 Jun 2017 07:48:51 +0000 (17:48 +1000)
committerStephen Finucane <stephen@that.guru>
Wed, 28 Jun 2017 20:41:28 +0000 (21:41 +0100)
This is the set of tests I generated while fuzzing the parser.

Add them so we don't regress.

Signed-off-by: Daniel Axtens <dja@axtens.net>
Reviewed-by: Stephen Finucane <stephen@that.guru>
17 files changed:
patchwork/tests/__init__.py
patchwork/tests/fuzztests/base64err.mbox [new file with mode: 0644]
patchwork/tests/fuzztests/charset.mbox [new file with mode: 0644]
patchwork/tests/fuzztests/codec-null.mbox [new file with mode: 0644]
patchwork/tests/fuzztests/date-oserror.mbox [new file with mode: 0644]
patchwork/tests/fuzztests/date-too-long.mbox [new file with mode: 0644]
patchwork/tests/fuzztests/date.mbox [new file with mode: 0644]
patchwork/tests/fuzztests/dateheader.mbox [new file with mode: 0644]
patchwork/tests/fuzztests/earlyfail.mbox [new file with mode: 0644]
patchwork/tests/fuzztests/msgid-len.mbox [new file with mode: 0644]
patchwork/tests/fuzztests/msgid-len2.mbox [new file with mode: 0644]
patchwork/tests/fuzztests/msgidheader.mbox [new file with mode: 0644]
patchwork/tests/fuzztests/refshdr.mbox [new file with mode: 0644]
patchwork/tests/fuzztests/unknown-encoding.mbox [new file with mode: 0644]
patchwork/tests/fuzztests/value2.mbox [new file with mode: 0644]
patchwork/tests/fuzztests/year-out-of-range.mbox [new file with mode: 0644]
patchwork/tests/test_parser.py

index 8bdf1a6746db1f650a12ec72455038be4a0f321e..cbe2b5d081dc83a36324f50f67a555d9e6da2694 100644 (file)
@@ -21,3 +21,4 @@ import os
 
 TEST_MAIL_DIR = os.path.join(os.path.dirname(__file__), 'mail')
 TEST_PATCH_DIR = os.path.join(os.path.dirname(__file__), 'patches')
+TEST_FUZZ_DIR = os.path.join(os.path.dirname(__file__), 'fuzztests')
diff --git a/patchwork/tests/fuzztests/base64err.mbox b/patchwork/tests/fuzztests/base64err.mbox
new file mode 100644 (file)
index 0000000..9756d5c
--- /dev/null
@@ -0,0 +1,46 @@
+From pat016
+Content-TCpe: text/plain; charset="utf-8"
+MIon: 1.0
+Content-Transfer-Encoding: 8bit
+Subject:: Up entry for B01X ARM
+From: =?utf-8?b?UmFmYcWCo alho Chehab <mchehab@osgIE1pxYJlY2tp?= <.com>
+X-: 913
+Message-Id: <1m>
+To: Fan Flli m>
+Cc: bcm-kist@broadcom.com,
+ =?UTF-8?q?Rafa=C5=82=20Mi=C5:82ecki?= <zajec5@gmail.com>,
+ An Morton <akpm@linux-foundation.org>,
+ "David S. MilYer" <d F:*
+vemloft.net>,
+ Greg Kroah-Hartman <inuxfoundat\84on.org>,
+ Mauro alho Chehab <mchehab@osg.samsung.com>,
+ Guenter Roeck <linux@roeck-us.net>, Jiri Slaby <cz>,
+ linux-kernel@vger.kernel.org ( list)
+Date:,  1 Jun 2016 22:00:54 +02
+Adh
+bci.
+
+>
+---
+ M++-
+(-)
+
+diff --ER@
+4
+--- a/ERS
++++ S
+@@ -2511,10 +2511,12 @@ F:*
+ BROURE
+ M:    >
++Mfał
+ L:g
++Lcom
+ S:    ed
+-F:
++F:i
+ F70*
+ B
diff --git a/patchwork/tests/fuzztests/charset.mbox b/patchwork/tests/fuzztests/charset.mbox
new file mode 100644 (file)
index 0000000..a8a40c8
--- /dev/null
@@ -0,0 +1,131 @@
+Received: with ECARTIS (v1.0.0; list lin; Tue, 06 Dec 2011 01:49:42 +0100 (CET)
+ived: from mcom 337 O
+  om" -OK)
+    by eddi with ESMTP id SAth PT
+ >); Tue, 6 Dec 2011 9:37 +0100
+Received:m caexch.com (Not Verified[092.168.16.9]) by mail3.caviumnetworks.com with Mal (
+    id 00>; Mon, 05 Dec 2011 1604 -
+Received: from .caveonetworks.com ([192.168.16.9]) by caexch01.caveonetworks.com with M SMT
+   n, 5 Dec 2011 1636 -
+Received: from dd1.caveonetworks.com ([64.2.3.195]) by caexch01.caveonetworks.com over TLS red channel with Microsoft SMTPS790.4675);
+ Mon, 5 Dec 2011 9:35 -0800
+Message-ID: <m>
+Date:on, 05 Dec 2011 16:49:35 -0800
+From:avid Daney <om>
+nt: lla/5.0 (X11; U; Linux x86_64; en-US; rv5) Gecko/20101027 Fedora/3.0.10-1.fc12 T0
+MIon: 1.0
+To: tils <big>
+CC:  s <l>,
+ l Lauss >,
+ n MIPS <>
+Subject: [Patch]: Fix ld p38 Fres on m.
+Content-Type: multipart/mixed;
+ boundary="------------080709040708040308010506"
+X-inalArrivalTime: 06 Dec 2011 00:49:35.0825 (UTC) FILETIME=[ECF8DC10:01CCB3B0]
+Reh: <om>
+o: <tis -s ls"> (uid 0)
+cpt:g
+Or: rfrg
+Xn: 3
+X-eon: tis .0
+Sr: lorg
+o: lorg
+r: dm
+Pr: bulk
+Xt: ls
+
+Tat.
+--------------080709040708040308010506
+Content-Type: text/plain; charset=ISO-8859-1;mat=ed
+Content-Transfer-Encoding: 7bit
+
+e 
+S.
+
+T
+sym
+vere 
+rer 
+
+
+Sim 
+sag 
+P" 
+
+
+Ine 
+'s.
+
+ex.
+
+Tnu
+
+?
+
+2
+
+       *ld.
+n a
+t.
+       Set
+
+
+--------------080709040708040308010506
+Content-Type: text/plain;
+ ="dd"
+Content-Transfer-Encoding:t
+Con: at;
+ "
+
+Index: bfd.h
+===
+,v
+r
+difh
+--- bf
++++ bfd
+@@ -198,6 +198,8 @@try
+   u
+   
+    1;
+ */
++  u 1;
+  */
+ ;
+In.c
+===
+Rv
+re430
+nk.c
+--- bfd430
++++ 000
+@@ -1946,6 +1946,9 @@ _bct
+ r)
++
++  E;
++
+   );
+   
+Ind
+===
+RCS,v
+r
+dif
+--- bfd96
++++ b0
+@@ -7260,6 +7260,7 @@ 
+        bh;
+          0;
+ 1;
++        1;
+ ))
+
+--------------080709040708040308010506--
+
diff --git a/patchwork/tests/fuzztests/codec-null.mbox b/patchwork/tests/fuzztests/codec-null.mbox
new file mode 100644 (file)
index 0000000..e31b3f6
Binary files /dev/null and b/patchwork/tests/fuzztests/codec-null.mbox differ
diff --git a/patchwork/tests/fuzztests/date-oserror.mbox b/patchwork/tests/fuzztests/date-oserror.mbox
new file mode 100644 (file)
index 0000000..36b8837
Binary files /dev/null and b/patchwork/tests/fuzztests/date-oserror.mbox differ
diff --git a/patchwork/tests/fuzztests/date-too-long.mbox b/patchwork/tests/fuzztests/date-too-long.mbox
new file mode 100644 (file)
index 0000000..e0642a4
Binary files /dev/null and b/patchwork/tests/fuzztests/date-too-long.mbox differ
diff --git a/patchwork/tests/fuzztests/date.mbox b/patchwork/tests/fuzztests/date.mbox
new file mode 100644 (file)
index 0000000..8a9685a
--- /dev/null
@@ -0,0 +1,44 @@
+From lib
+Recd: (
+Mait: cmlm
+-Id:
+Sender:
+Date: Wg>
+SctMIon: 1.0
+Content-Transfer-Encoding: 8bit
+Subject:: Up entry for B01X ARM
+From:\b=?utf-X?b?UmFmYcwCIE1pxYJlY2tp?= <.com>
+X-: 913
+Message-Id: <1m>
+To: Fan Flli m>
+Cc: bcm-kist@broadc}m.c6
+ContentF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <zajec5@gmail.com>,
+ An Morton <akpm@l\85nux-foundation.org>,
+ "David S.i iller" <dAvem@divemloft.net>,
+\7fÿreg Kroah-Hartman <inuxfoundation.org>,
+ Mauro alho Chehab <mchehab@osg.samsung.com>,
+ Kuenter Roeck <linux@roeck-us.net>, Jiri Slaby <cz>,
+ linux-kernel@vger.kernel.org ( list)
+Date:,  1 Jun 2016 22:00:54\1d+0200
+
+Adh
+bci.
+
+1 Jun 2016 22:00:5iLf"--ERS
+4
+--- a/ERS
++++ S
+@@ -2511, +2511,12 @@ F:*
+ BROURE
+ M:    >
++Mfał
+ L:g
++Lcom
+ Sà    ed
+-F:
++F:i
+ F70*
+ B
diff --git a/patchwork/tests/fuzztests/dateheader.mbox b/patchwork/tests/fuzztests/dateheader.mbox
new file mode 100644 (file)
index 0000000..7d25b87
Binary files /dev/null and b/patchwork/tests/fuzztests/dateheader.mbox differ
diff --git a/patchwork/tests/fuzztests/earlyfail.mbox b/patchwork/tests/fuzztests/earlyfail.mbox
new file mode 100644 (file)
index 0000000..47db41d
Binary files /dev/null and b/patchwork/tests/fuzztests/earlyfail.mbox differ
diff --git a/patchwork/tests/fuzztests/msgid-len.mbox b/patchwork/tests/fuzztests/msgid-len.mbox
new file mode 100644 (file)
index 0000000..2339b3c
Binary files /dev/null and b/patchwork/tests/fuzztests/msgid-len.mbox differ
diff --git a/patchwork/tests/fuzztests/msgid-len2.mbox b/patchwork/tests/fuzztests/msgid-len2.mbox
new file mode 100644 (file)
index 0000000..53fa874
--- /dev/null
@@ -0,0 +1,37 @@
+From ste016
+ath: <st
+From: Sen Fane <steom>
+To: com
+Subject: [PATCH 2/2] test: Cwn
+Date:, 11 Sep 2016 23:22:04 +0100
+Message-ID:>
+X-er: il=2
+In-Reply-To: <1473632524-8585-1-git-send-email-stephenfinucane@gmail.com>\11References: <1473632524-8585-1-git-send-emaifa=C5=82=20Mi=C5=82ecki?= <zajec5@gmail.com>,
+ An Mnuxfoundation.oorton <akpm@linuZ-foundation.org>,
+ "David S. Miller" <davem@davemloft.net>,
+ Greg Kroah-Hartman <inuxfoundation.org>,
+ Mauro alho Chehab <mchehab@osg.sam\88ungÿÿom>,
+ Guenter Roeck <linux@roeck-us.net>, Jiri Slaby <cz>,
+ linux-kernel@vger.kernel.oundation.oortoorg ( list)
+Date:,  1 Jun 2016 2il.cdm>,
+ An Mnuxfoundat2:00:54 +0200
+
+Adh
+bci.
+
+>
+---
+ M++-
+(-)
+
+diff --ERS
+4
+--- a/ERS
++++ S
+@@ -2511,10 +2511,12 @@ F:*
+ BROURE
+ M:    >
++Mfał
+ L:g
++Lc B
diff --git a/patchwork/tests/fuzztests/msgidheader.mbox b/patchwork/tests/fuzztests/msgidheader.mbox
new file mode 100644 (file)
index 0000000..e94e82e
--- /dev/null
@@ -0,0 +1,131 @@
+Received: with ECARTIS (v1.0.0; list lin; Tue, 06 Dec 2011 01:49:42 +0100 (CET)
+ived: from mcom 337 O
+  om" -OK)
+    by eddi with ESMTP id SAth PT
+ >); Tue, 6 Dec 2011 9:37 +0100
+Received:m caexch.com (Not Verified[192.168.16.9]) by mail3.caviumnetworks.com with Mal (
+    id 00>; Mon, 05 Dec 2011 1604 -
+Received: from .caveonetworks.com ([192.168.16.9]) by caexch01.caveonetworks.com with M SMT
+   n, 5 Dec 2011 1636 -
+Received: from dd1.caveonetworks.com ([64.2.3.195]) by caexch01.caveonetworks.com over TLS red channel with Microsoft SMTPS790.4675);
+ Mon, 5 Dec 2011 9:35 -0800
+Message-ID: <m>
+Date:on, 05 Dec 2011 16:49:35 -0800
+From:avid Daney <om>
+nt: lla/5.0 (X11; U; Linux x86_64; en-US; rv5) Gecko/20101027 Fedora/3.0.10-1.fc12 T0
+MIon: 1.0
+To: tils <big>
+CC:  s <l>,
+ l Lauss >,
+ n MIPS <>
+Subject: [Patch]: Fix ld p38 Fres on m.
+Content-Type: multipart/mixed;
+ boundary="------------080709040708040308010506"
+X-inalArrivalTime: 06 Dec 2011 00:49:35.0825 (UTC) FILETIME=[ECF8DC10:01CCB3B0]
+Reh: <om>
+o: <tis -s ls"> (uid 0)
+cpt:g
+Or: rfrg
+Xn: 3
+X-eon: tis .0
+Sr: lorg
+o: lorg
+r: dm
+Pr: bulk
+Xt: ls
+
+Tat.
+--------------080709040708040308010506
+Content-Type: text/plain; charset=ISO-8859-1;mat=ed
+Content-Transfer-Encoding: 7bit
+
+e 
+S.
+
+T
+sym
+vere 
+rer 
+
+
+Sim 
+sag 
+P" 
+
+
+Ine 
+'s.
+
+ex.
+
+Tnu
+
+?
+
+2
+
+       *ld.
+n a
+t.
+       Set
+
+
+--------------080709040708040308010506
+Content-Type: text/plain;
+ ="dd"
+Content-Transfer-Encoding:t
+Con: at;
+ "
+
+Index: bfd.h
+===
+,v
+r
+difh
+--- bf
++++ bfd
+@@ -198,6 +198,8 @@try
+   u
+   
+    1;
+ */
+ 1;
+  */
+ ;
+In.c
+===
+Rv
+re430
+nk.c
+--- bfd430
++++ 000
+@@ -1946,6 +1946,9 @@ _bct
+ r)
++
++  E;
++
+   );
+   
+Ind
+===
+RCS,v
+r
+dif
+--- bfd96
++++ b0
+@@ -7260,6 +7260,7 @@ 
+        bh;
+ 0;
+ 1;
++        1;
+ ))
+
+--------------080709040708040308010506--
+
diff --git a/patchwork/tests/fuzztests/refshdr.mbox b/patchwork/tests/fuzztests/refshdr.mbox
new file mode 100644 (file)
index 0000000..bc7109a
Binary files /dev/null and b/patchwork/tests/fuzztests/refshdr.mbox differ
diff --git a/patchwork/tests/fuzztests/unknown-encoding.mbox b/patchwork/tests/fuzztests/unknown-encoding.mbox
new file mode 100644 (file)
index 0000000..f6ce3fe
Binary files /dev/null and b/patchwork/tests/fuzztests/unknown-encoding.mbox differ
diff --git a/patchwork/tests/fuzztests/value2.mbox b/patchwork/tests/fuzztests/value2.mbox
new file mode 100644 (file)
index 0000000..49744ab
Binary files /dev/null and b/patchwork/tests/fuzztests/value2.mbox differ
diff --git a/patchwork/tests/fuzztests/year-out-of-range.mbox b/patchwork/tests/fuzztests/year-out-of-range.mbox
new file mode 100644 (file)
index 0000000..2dd609b
Binary files /dev/null and b/patchwork/tests/fuzztests/year-out-of-range.mbox differ
index 57a3f0decfdef11a49ccec8df77b7500418ce8fd..c86ea1be35541970e261ef177a41c405e4973372 100644 (file)
@@ -23,6 +23,7 @@ from email.mime.multipart import MIMEMultipart
 from email.mime.text import MIMEText
 from email.utils import make_msgid
 import os
+import unittest
 
 from django.test import TestCase
 from django.utils import six
@@ -43,6 +44,7 @@ from patchwork.parser import parse_version
 from patchwork.parser import split_prefixes
 from patchwork.parser import subject_check
 from patchwork.tests import TEST_MAIL_DIR
+from patchwork.tests import TEST_FUZZ_DIR
 from patchwork.tests.utils import create_project
 from patchwork.tests.utils import create_series
 from patchwork.tests.utils import create_series_reference
@@ -52,15 +54,20 @@ from patchwork.tests.utils import read_patch
 from patchwork.tests.utils import SAMPLE_DIFF
 
 
-def read_mail(filename, project=None):
-    """Read a mail from a file."""
-    file_path = os.path.join(TEST_MAIL_DIR, filename)
+def load_mail(file_path):
     if six.PY3:
         with open(file_path, 'rb') as f:
             mail = email.message_from_binary_file(f)
     else:
         with open(file_path) as f:
             mail = email.message_from_file(f)
+    return mail
+
+
+def read_mail(filename, project=None):
+    """Read a mail from a file."""
+    file_path = os.path.join(TEST_MAIL_DIR, filename)
+    mail = load_mail(file_path)
     if 'Message-Id' not in mail:
         mail['Message-Id'] = make_msgid()
     if project:
@@ -819,3 +826,47 @@ class SubjectTest(TestCase):
         self.assertEqual(parse_version('Hello, world', ['v10']), 10)
         self.assertEqual(parse_version('Hello, world (v2)', []), 2)
         self.assertEqual(parse_version('Hello, world (V6)', []), 6)
+
+
+class FuzzTest(TestCase):
+    """Test fuzzed patches."""
+    def setUp(self):
+        create_project(listid='patchwork.ozlabs.org')
+
+    def _test_patch(self, name):
+        file_path = os.path.join(TEST_FUZZ_DIR, name)
+        m = load_mail(file_path)
+        try:
+            parse_mail(m, list_id='patchwork.ozlabs.org')
+        except ValueError:
+            pass
+
+    @unittest.skipIf(six.PY2, 'Breaks only on Python 3')
+    def test_early_fail(self):
+        file_path = os.path.join(TEST_FUZZ_DIR, 'earlyfail.mbox')
+        with self.assertRaises(AttributeError):
+            load_mail(file_path)
+
+    def test_base64err(self):
+        self._test_patch('base64err.mbox')
+
+    def test_codec(self):
+        self._test_patch('codec-null.mbox')
+        self._test_patch('charset.mbox')
+        self._test_patch('unknown-encoding.mbox')
+        self._test_patch('value2.mbox')
+
+    def test_date(self):
+        self._test_patch('date.mbox')
+        self._test_patch('date-too-long.mbox')
+        self._test_patch('year-out-of-range.mbox')
+        self._test_patch('date-oserror.mbox')
+
+    def test_msgid(self):
+        self._test_patch('msgid-len.mbox')
+        self._test_patch('msgid-len2.mbox')
+
+    def test_hdr(self):
+        self._test_patch('refshdr.mbox')
+        self._test_patch('dateheader.mbox')
+        self._test_patch('msgidheader.mbox')