def get_sink_node(sink, sink_apis, all_sinks): # The sink name may not be in apis, but in all_sinks sink_node = AstNode() info = get_matching_info(node=sink, info_nodes=all_sinks) if not info: return sink_node sink_node.type = AstNode.FUNCTION_DECL_REF_EXPR # set the name and other information api = get_matching_api(node=sink, apis=sink_apis) if api: sink_node.id = api.id sink_node.name = api.name sink_node.base_type = api.base_type sink_node.full_name = api.full_name sink_node.source = sink['name'] else: sink_node.name = info['name'] if 'instanceof' in info: sink_node.base_type = info['instanceof'] sink_node.full_name = get_progpilot_name(entry=info) sink_node.source = sink['name'] # set the location sink_file_info = FileInfo() sink_file_info.filename = basename(sink['file']) sink_file_info.relpath = dirname(sink['file']) sink_node.range.start.row = sink['row'] sink_node.range.start.column = sink['column'] sink_node.range.start.file_info.CopyFrom(sink_file_info) sink_node.range.end.CopyFrom(sink_node.range.start) return sink_node
def get_source_node(src, source_apis, all_sources): # The source name may not be in apis, but in all_sources source_node = AstNode() info = get_matching_info(node=src, info_nodes=all_sources, fuzzy=True) if not info: return source_node if 'is_function' in info and info['is_function']: source_node.type = AstNode.FUNCTION_DECL_REF_EXPR else: source_node.type = AstNode.VARIABLE_DECL_REF_EXPR # set the name and other information api = get_matching_api(node=src, apis=source_apis, fuzzy=True) if api: source_node.id = api.id source_node.name = api.name source_node.base_type = api.base_type source_node.full_name = api.full_name source_node.source = src['name'] else: source_node.name = info['name'] if 'instanceof' in info: source_node.base_type = info['instanceof'] source_node.full_name = get_progpilot_name(entry=info) source_node.source = src['name'] # set the location source_file_info = FileInfo() source_file_info.filename = basename(src['file']) source_file_info.relpath = dirname(src['file']) source_node.range.start.row = src['row'] source_node.range.start.column = src['column'] source_node.range.start.file_info.CopyFrom(source_file_info) source_node.range.end.CopyFrom(source_node.range.start) return source_node
def get_sink_node(sink): sink_node = AstNode() if sink['user_input']: sink_node.full_name = sink['user_input'] if sink['code']: sink_node.source = sink['code'] sink_file_info = FileInfo() if sink['file']: sink_file_info.filename = basename(sink['file']) sink_file_info.relpath = dirname(sink['file']) if sink['row']: sink_node.range.start.row = sink['row'] sink_node.range.start.file_info.CopyFrom(sink_file_info) return sink_node
def _get_api_result(base, name, args, source_text, source_range, filepb): api_result = AstNode() api_result.type = ast_pb2.AstNode.FUNCTION_DECL_REF_EXPR api_result.name = name if base is None: api_result.full_name = name else: api_result.base_type = base api_result.full_name = '%s.%s' % (base, name) for arg in args: api_result.arguments.append(arg) api_result.source = source_text source_start, source_end = source_range api_result.range.start.row = source_start[0] api_result.range.start.column = source_start[1] api_result.range.start.file_info.CopyFrom(filepb) api_result.range.end.row = source_end[0] api_result.range.end.column = source_end[1] api_result.range.end.file_info.CopyFrom(filepb) return api_result