Skip to content

Commit 4c9b273

Browse files
committed
Ensure there is at least one corpus file for mqtt
1 parent bb04361 commit 4c9b273

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,14 @@ missing
3838
/curl_fuzzer_gopher_seed_corpus.zip
3939
/curl_fuzzer_http
4040
/curl_fuzzer_http_seed_corpus.zip
41+
/curl_fuzzer_https
42+
/curl_fuzzer_https_seed_corpus.zip
4143
/curl_fuzzer_imap
4244
/curl_fuzzer_imap_seed_corpus.zip
4345
/curl_fuzzer_ldap
4446
/curl_fuzzer_ldap_seed_corpus.zip
47+
/curl_fuzzer_mqtt
48+
/curl_fuzzer_mqtt_seed_corpus.zip
4549
/curl_fuzzer_pop3
4650
/curl_fuzzer_pop3_seed_corpus.zip
4751
/curl_fuzzer_rtmp

corpora/curl_fuzzer_mqtt/test_dummy

38 Bytes
Binary file not shown.

curl_test_data.py

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
#
4+
# Project ___| | | | _ \| |
5+
# / __| | | | |_) | |
6+
# | (__| |_| | _ <| |___
7+
# \___|\___/|_| \_\_____|
8+
#
9+
# Copyright (C) 2017, Daniel Stenberg, <[email protected]>, et al.
10+
#
11+
# This software is licensed as described in the file COPYING, which
12+
# you should have received as part of this distribution. The terms
13+
# are also available at https://curl.haxx.se/docs/copyright.html.
14+
#
15+
# You may opt to use, copy, modify, merge, publish, distribute and/or sell
16+
# copies of the Software, and permit persons to whom the Software is
17+
# furnished to do so, under the terms of the COPYING file.
18+
#
19+
# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20+
# KIND, either express or implied.
21+
#
22+
"""Module for extracting test data from the test data folder"""
23+
24+
from __future__ import (absolute_import, division, print_function,
25+
unicode_literals)
26+
import os
27+
import re
28+
import logging
29+
30+
log = logging.getLogger(__name__)
31+
32+
33+
REPLY_DATA = re.compile("<reply>\s*<data>(.*?)</data>", re.MULTILINE | re.DOTALL)
34+
35+
36+
class TestData(object):
37+
def __init__(self, data_folder):
38+
self.data_folder = data_folder
39+
40+
def get_test_data(self, test_number):
41+
# Create the test file name
42+
filename = os.path.join(self.data_folder,
43+
"test{0}".format(test_number))
44+
45+
log.debug("Parsing file %s", filename)
46+
47+
with open(filename, "rb") as f:
48+
contents = f.read().decode("utf-8")
49+
50+
m = REPLY_DATA.search(contents)
51+
if not m:
52+
raise Exception("Couldn't find a <reply><data> section")
53+
54+
# Left-strip the data so we don't get a newline before our data.
55+
return m.group(1).lstrip()
56+
57+
58+
if __name__ == '__main__':
59+
td = TestData("./data")
60+
data = td.get_test_data(1)
61+
print(data)

0 commit comments

Comments
 (0)