Documentation ¶
Overview ¶
Package analysistest contains utility functions for testing the analysis tools.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var EscapeRegex = regexp.MustCompile(`//.*@Escape\(((?:\s*\w\s*,?)+)\)`)
EscapeRegex matches annotations of the form "@Escape(id1, id2, id3)"
var SinkRegex = regexp.MustCompile(`//.*@Sink\(((?:\s*\w\s*,?)+)\)`)
SinkRegex matches annotations of the form "@Sink(id1, id2, id3)"
var SourceRegex = regexp.MustCompile(`//.*@Source\(((?:\s*(\w|(\w\s+[a-zA-Z0-9$:\->]+\s*))\s*,?)+)\)`)
SourceRegex matches an annotation of the form @Source(id1, id2 meta2, ...) where the "argument" is either an identifier (e.g. id) or an identifier with associated "metadata" (e.g. id call:example1->call:helper->call:example1$1).
Functions ¶
func GetExpectedTargetToSources ¶
func GetExpectedTargetToSources(reldir string, dir string) (TargetToSources, TargetToSources)
GetExpectedTargetToSources analyzes the files in dir and looks for comments @Source(id) and @Sink(id) to construct expected flows from targets to sources in the form of two maps from: - from sink positions to all the source position that reach that sink. - from escape positions to the source of data that escapes.
Types ¶
type AnnotationID ¶
type AnnotationID struct { // ID is the value of an annotation id. // e.g. @Source(id) // ^^ ID string // Meta is the identifier of the second portion of an annotation id. // This represents an annotation id metadata, usually for trace information. // e.g. @Source(id call:example1->call:helper) // ^^^^^^^^^^^^^^^^^^^^^^^^^^ // Meta can be empty. // e.g. @Source(id) Meta string // Pos is the position of the annotation. Pos LPos }
AnnotationID represents an identifier in an annotation.
func (AnnotationID) String ¶
func (id AnnotationID) String() string
type LPos ¶
type LPos struct { // Filename is the file name of the position Filename string // Line is the line number in the file Line int }
LPos is a line position
func RelPos ¶
RelPos drops the column of the position and prepends reldir to the filename of the position
func RemoveColumn ¶
RemoveColumn transforms a token.Position into a LPos by removing the column information
type TargetToSources ¶
type TargetToSources map[AnnotationID]map[AnnotationID]bool
TargetToSources is a mapping from a target annotation (e.g. ex in @Sink(ex, ex2)) to a source annotation (e.g. ex in @Source(ex, ex2)).
func (TargetToSources) HasMetadata ¶
func (t TargetToSources) HasMetadata() bool
HasMetadata returns true if the TargetToSources mapping contains metadata