Commit 0bc309c6 by 文周繁

feat: optimized script files, added bug seed directory parameters, and fixed an…

feat: optimized script files, added bug seed directory parameters, and fixed an incomplete bug in valgrind script
parent 2883d264
...@@ -9,10 +9,11 @@ python2.7 ...@@ -9,10 +9,11 @@ python2.7
```sh ```sh
# 在python2.7环境下执行valgrind.py,脚本共接收四个参数 # 在python2.7环境下执行valgrind.py,脚本共接收四个参数
# 第一个参数为可执行程序,也就是被测目标程序 # 第一个参数为可执行程序,也就是被测目标程序
# 第二个参数为种子目录 # 第二个参数为产生crashs的种子目录
# 第三个参数为标准输出文件路径,用于存储标准输入信息 # 第三个参数用于存储vargrind检测后疑似漏洞的seeds文件夹目录
# 第四个参数为错误信息文件路径,用于存储错误信息 # 第四个参数为标准输出文件路径,用于存储标准输入信息
# 例:python valgrind.py /path/to/jhead /path/to/seeds /path/to/stdout /path/to/stderr # 第五个参数为错误信息文件路径,用于存储错误信息
# 例:python valgrind.py /path/to/jhead /path/to/crash-seeds /path/to/bug-seeds /path/to/stdout /path/to/stderr
``` ```
# asan.py用法 # asan.py用法
...@@ -21,8 +22,9 @@ python2.7 ...@@ -21,8 +22,9 @@ python2.7
# 在python2.7环境下执行asan.py,脚本共接收四个参数 # 在python2.7环境下执行asan.py,脚本共接收四个参数
# 第一个参数为可执行程序,也就是被测目标程序 # 第一个参数为可执行程序,也就是被测目标程序
# 第二个参数为种子目录 # 第二个参数为种子目录
# 第三个参数为标准输出文件路径,用于存储标准输入信息 # 第三个参数用于存储asan检测后疑似漏洞的seeds文件夹目录
# 第四个参数为错误信息文件路径,用于存储错误信息 # 第四个参数为标准输出文件路径,用于存储标准输入信息
# 例:python asan.py /path/to/jhead /path/to/seeds /path/to/stdout /path/to/stderr # 第五个参数为错误信息文件路径,用于存储错误信息
# 例:python asan.py /path/to/jhead /path/to/crash-seeds /path/to/bug-seeds /path/to/stdout /path/to/stderr
``` ```
...@@ -2,6 +2,7 @@ import sys ...@@ -2,6 +2,7 @@ import sys
import subprocess import subprocess
import os import os
import re import re
import shutil
pattern_asan_head = re.compile(r'==\d+==ERROR: AddressSanitizer:') pattern_asan_head = re.compile(r'==\d+==ERROR: AddressSanitizer:')
pattern_asan = re.compile(r' {4}#\d+ 0x\w+ in ') pattern_asan = re.compile(r' {4}#\d+ 0x\w+ in ')
...@@ -23,7 +24,7 @@ def search_file(dirname): ...@@ -23,7 +24,7 @@ def search_file(dirname):
return paths return paths
def TIMEOUT_COMMAND(command, stdout, stderr): def TIMEOUT_COMMAND(command, path, output_seeds_dirname, stdout, stderr):
"""call shell-command and either return its output or kill it """call shell-command and either return its output or kill it
if it doesn't normally exit within timeout seconds and return None""" if it doesn't normally exit within timeout seconds and return None"""
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
...@@ -46,26 +47,30 @@ def TIMEOUT_COMMAND(command, stdout, stderr): ...@@ -46,26 +47,30 @@ def TIMEOUT_COMMAND(command, stdout, stderr):
stderr.write(errs) stderr.write(errs)
# TODO write to mangodb # TODO write to mangodb
invalid_cause_dict[error_cause] = 1 invalid_cause_dict[error_cause] = 1
if not os.path.exists(output_seeds_dirname):
os.makedirs(output_seeds_dirname)
shutil.copy2(path, output_seeds_dirname)
def generation_command(target, parameter, paths, stdout_outputfile, stderr_outputfile): def generation_command(target, parameter, paths, output_seeds_dirname, stdout_outputfile, stderr_outputfile):
stdout_output = open(stdout_outputfile, "w+") stdout_output = open(stdout_outputfile, "w+")
stderr_output = open(stderr_outputfile, "w+") stderr_output = open(stderr_outputfile, "w+")
for path in paths: for path in paths:
command = target + " " + parameter.replace("@@", path, 1) + " " command = target + " " + parameter.replace("@@", path, 1) + " "
print(command) print(command)
TIMEOUT_COMMAND(command, stdout_output, stderr_output) TIMEOUT_COMMAND(command, path, output_seeds_dirname, stdout_output, stderr_output)
def main(argv): def main(argv):
target = argv[0] target = argv[0]
cmd = "@@" cmd = "@@"
dirname = argv[1] input_seeds_dirname = argv[1] # input_seeds dir
stdout_outputfile = argv[2] output_seeds_dirname = argv[2] # output_seeds dir
stderr_outputfile = argv[3] stdout_outputfile = argv[3]
stderr_outputfile = argv[4]
print("Searching files\n") print("Searching files\n")
paths = search_file(dirname) paths = search_file(input_seeds_dirname)
generation_command(target, cmd, paths, stdout_outputfile, stderr_outputfile) generation_command(target, cmd, paths, output_seeds_dirname, stdout_outputfile, stderr_outputfile)
if __name__ == "__main__": if __name__ == "__main__":
......
...@@ -2,6 +2,7 @@ import sys ...@@ -2,6 +2,7 @@ import sys
import subprocess import subprocess
import os import os
import re import re
import shutil
pattern_valgrind_head = re.compile(r'==\d+==') pattern_valgrind_head = re.compile(r'==\d+==')
pattern_valgrind_tail = re.compile(r'==\d+== ERROR SUMMARY: [1-9]+') pattern_valgrind_tail = re.compile(r'==\d+== ERROR SUMMARY: [1-9]+')
...@@ -24,57 +25,63 @@ def search_file(dirname): ...@@ -24,57 +25,63 @@ def search_file(dirname):
return paths return paths
def TIMEOUT_COMMAND(command, stdout, stderr): def TIMEOUT_COMMAND(command, path, output_seeds_dirname, stdout, stderr):
"""call shell-command and either return its output or kill it """call shell-command and either return its output or kill it
if it doesn't normally exit within timeout seconds and return None""" if it doesn't normally exit within timeout seconds and return None"""
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
outs, errs = process.communicate() outs, errs = process.communicate()
stdout.write(outs) stdout.write(outs)
err_data = '' err_data = ''
is_search_at = False search_at_count = 0
search_by_count = 0 search_by_count = 0
error_cause = '' error_cause = ''
for i in errs.splitlines(): if pattern_valgrind_tail.search(errs):
if pattern_valgrind_at.match(i) is not None and not is_search_at: for i in errs.splitlines():
is_search_at = True if pattern_valgrind_at.match(i) is not None and search_at_count < 2:
err_data = err_data + i + "\n" search_at_count += 1
_, end = pattern_valgrind_at.search(i).span() if search_at_count <= 1:
error_cause += i[end:] err_data = err_data + i + "\n"
elif pattern_valgrind_by.match(i) is not None and search_by_count <= 10: _, end = pattern_valgrind_at.search(i).span()
search_by_count += 1 error_cause += i[end:]
err_data = err_data + i + "\n" elif pattern_valgrind_by.match(i) is not None and search_by_count <= 10 and search_at_count <= 1:
_, end = pattern_valgrind_by.search(i).span() search_by_count += 1
error_cause += i[end:] err_data = err_data + i + "\n"
elif pattern_valgrind_tail.match(i) is not None: _, end = pattern_valgrind_by.search(i).span()
err_data = err_data + i + "\n" error_cause += i[end:]
if not invalid_cause_dict.has_key(error_cause): elif pattern_valgrind_tail.match(i) is not None:
stderr.write(err_data) err_data = err_data + i + "\n"
# TODO write to mangodb if not invalid_cause_dict.has_key(error_cause):
invalid_cause_dict[error_cause] = 1 stderr.write(err_data)
elif pattern_valgrind_head.match(i) is not None: # TODO write to mangodb
err_data = err_data + i + "\n" invalid_cause_dict[error_cause] = 1
else: if not os.path.exists(output_seeds_dirname):
pass os.makedirs(output_seeds_dirname)
shutil.copy2(path, output_seeds_dirname)
elif pattern_valgrind_head.match(i) is not None:
err_data = err_data + i + "\n"
else:
pass
def generation_command(target, parameter, paths, stdout_outputfile, stderr_outputfile): def generation_command(target, parameter, paths, output_seeds_dirname, stdout_outputfile, stderr_outputfile):
stdout_output = open(stdout_outputfile, "w+") stdout_output = open(stdout_outputfile, "w+")
stderr_output = open(stderr_outputfile, "w+") stderr_output = open(stderr_outputfile, "w+")
for path in paths: for path in paths:
command = "valgrind " + target + " " + parameter.replace("@@", path, 1) + " " command = "valgrind " + target + " " + parameter.replace("@@", path, 1) + " "
print(command) print(command)
TIMEOUT_COMMAND(command, stdout_output, stderr_output) TIMEOUT_COMMAND(command, path, output_seeds_dirname, stdout_output, stderr_output)
def main(argv): def main(argv):
target = argv[0] # target program target = argv[0] # target program
cmd = "@@" cmd = "@@"
dirname = argv[1] # seeds dir input_seeds_dirname = argv[1] # input_seeds dir
stdout_outputfile = argv[2] output_seeds_dirname = argv[2] # output_seeds dir
stderr_outputfile = argv[3] stdout_outputfile = argv[3]
stderr_outputfile = argv[4]
print("Searching files\n") print("Searching files\n")
paths = search_file(dirname) paths = search_file(input_seeds_dirname)
generation_command(target, cmd, paths, stdout_outputfile, stderr_outputfile) generation_command(target, cmd, paths, output_seeds_dirname, stdout_outputfile, stderr_outputfile)
if __name__ == "__main__": if __name__ == "__main__":
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment