Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix vul_datail graph missing when highlight indexerror. #1373

Merged
merged 1 commit into from
Mar 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 58 additions & 52 deletions dongtai_common/engine/compatibility.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from math import ceil
from typing import List
import logging
logger = logging.getLogger('dongtai-core')


def method_pool_is_3(dic: dict) -> bool:
Expand Down Expand Up @@ -97,56 +99,60 @@ def highlight_target_value(target_value: str, ranges: list) -> str:
map(lambda x: x[1], sorted(str_dict.items(),
key=lambda kv: kv[0])))
return "".join(final_str)
if sorted_ranges and value and len(value) < value_origin_len:
begin_part_length = ceil((AGENT_DEFAULT_LENGTH - 3) / 2)
end_part_length = int((AGENT_DEFAULT_LENGTH - 3) / 2)
hidden_red_flag = False
end_part_start_ind = value_origin_len - end_part_length
str_dict_begin = {
ind: xss_prevent(str_)
for ind, str_ in enumerate(value[:begin_part_length])
}
str_dict_end = {
ind + (value_origin_len - end_part_length) + 3: xss_prevent(str_)
for ind, str_ in enumerate(value[-end_part_length:])
}
str_dict = {}
str_dict.update(str_dict_begin)
str_dict.update(str_dict_end)
str_dict[begin_part_length + 2] = '...'
for range_ in sorted_ranges:
if range_['start'] in str_dict.keys() and (range_['stop'] -
1) in str_dict.keys():
str_dict[
range_['start']] = '<em style="color:red;">' + str_dict[
range_['start']]
str_dict[range_['stop'] -
1] = str_dict[range_['stop'] - 1] + '</em>'

if range_['start'] in str_dict.keys() and (
range_['stop'] - 1) not in str_dict.keys():
str_dict[
range_['start']] = '<em style="color:red;">' + str_dict[
range_['start']]
str_dict[
begin_part_length] = '</em>' + str_dict[begin_part_length]
str_dict[
begin_part_length] = '</em>' + str_dict[begin_part_length]
if range_['start'] not in str_dict.keys() and (
range_['stop'] - 1) in str_dict.keys():
str_dict[
value_origin_len -
end_part_length] = '<em style="color:red;">' + str_dict[
value_origin_len - end_part_length]
str_dict[range_['stop'] -
1] = str_dict[range_['stop'] - 1] + '</em>'
if range_['start'] not in str_dict.keys() or (
range_['stop']) not in str_dict.keys():
str_dict[begin_part_length +
2] = '<em style="color:red;">' + '...' + '</em>'
final_str = list(
map(lambda x: x[1], sorted(str_dict.items(),
key=lambda kv: kv[0])))
return "".join(final_str)

if len(value) != AGENT_DEFAULT_LENGTH:
return f'<em style="color:red;">{value}</em>'
try:
if sorted_ranges and value and len(value) < value_origin_len:
begin_part_length = ceil((AGENT_DEFAULT_LENGTH - 3) / 2)
end_part_length = int((AGENT_DEFAULT_LENGTH - 3) / 2)
hidden_red_flag = False
end_part_start_ind = value_origin_len - end_part_length
str_dict_begin = {
ind: xss_prevent(str_)
for ind, str_ in enumerate(value[:begin_part_length])
}
str_dict_end = {
ind + (value_origin_len - end_part_length) + 3: xss_prevent(str_)
for ind, str_ in enumerate(value[-end_part_length:])
}
str_dict = {}
str_dict.update(str_dict_begin)
str_dict.update(str_dict_end)
str_dict[begin_part_length + 2] = '...'
for range_ in sorted_ranges:
if range_['start'] in str_dict.keys() and (range_['stop'] -
1) in str_dict.keys():
str_dict[
range_['start']] = '<em style="color:red;">' + str_dict[
range_['start']]
str_dict[range_['stop'] -
1] = str_dict[range_['stop'] - 1] + '</em>'

if range_['start'] in str_dict.keys() and (
range_['stop'] - 1) not in str_dict.keys():
str_dict[
range_['start']] = '<em style="color:red;">' + str_dict[
range_['start']]
str_dict[
begin_part_length] = '</em>' + str_dict[begin_part_length]
str_dict[
begin_part_length] = '</em>' + str_dict[begin_part_length]
if range_['start'] not in str_dict.keys() and (
range_['stop'] - 1) in str_dict.keys():
str_dict[
value_origin_len -
end_part_length] = '<em style="color:red;">' + str_dict[
value_origin_len - end_part_length]
str_dict[range_['stop'] -
1] = str_dict[range_['stop'] - 1] + '</em>'
if range_['start'] not in str_dict.keys() or (
range_['stop']) not in str_dict.keys():
str_dict[begin_part_length +
2] = '<em style="color:red;">' + '...' + '</em>'
final_str = list(
map(lambda x: x[1], sorted(str_dict.items(),
key=lambda kv: kv[0])))
return "".join(final_str)
except KeyError as e:
logger.warning(e, exc_info=e)
return f'<em style="color:red;">{value}</em>'