Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
63f8a50
created new branch of master to merge the changes
Oct 6, 2021
90b0a7c
fixed tags bug
Oct 7, 2021
2ba31da
fixed bug with multiLocations
Oct 7, 2021
e707acc
fixed new single loc bug
Oct 7, 2021
7804bcb
bugfix
Oct 7, 2021
4ec8312
corrected rule display and matching
Oct 7, 2021
f0620c2
minor changes
Oct 7, 2021
94766e2
minor changes
Oct 7, 2021
54bfaba
github action location trimming
Oct 7, 2021
e3de786
removed useless struct
Oct 7, 2021
6e78b1d
removed useless struct
Oct 7, 2021
28a3c8b
refactoring
Oct 7, 2021
b12907d
path changes
Oct 7, 2021
8c1794b
path testing
Oct 7, 2021
4a07649
last refactoring
Oct 7, 2021
5cb2181
added testScript and GithubAction
Oct 7, 2021
886e20a
Update goblintAnalysis.yml
AlexanderEichler Oct 7, 2021
819b29a
improved indentation
Oct 8, 2021
e095fd0
Merge branch 'integrationSarif' of https://github.com/AlexanderEichle…
Oct 8, 2021
71c5d00
removed unneeded flags, and some other minor refactoring
Oct 8, 2021
36019f8
usage of yojson for Sarif output
Oct 9, 2021
7fc4176
added locationObject for yojson
Oct 9, 2021
3f50280
bugfix location
Oct 10, 2021
38e5ce0
added invocationsObject
Oct 10, 2021
0200afd
removed obsolete code
Oct 10, 2021
2ff8c0b
added location object to toolComponent
Oct 10, 2021
538b0a1
code cleanup
Oct 10, 2021
ce8c08d
code cleanup
Oct 10, 2021
d8e0ced
formatting
Oct 10, 2021
dbdddbf
added messageCategory toString
Oct 11, 2021
aeebcf9
added optional parameter -R to Goblint. This option removes the leadi…
Oct 11, 2021
7d52394
minor change to path of uri in Sarif
Oct 11, 2021
4162e27
added endline and endColumn
Oct 11, 2021
aae6252
added cil path
Oct 14, 2021
1253203
added firstElements function
Oct 14, 2021
d09d8db
added maximum to locations of result object
Oct 14, 2021
9779187
bugfix
Oct 15, 2021
665ba0b
modified gitHubaction path
Oct 15, 2021
bbc4470
added more documentation
Oct 15, 2021
c3d9c45
deleted unneeded script
Oct 15, 2021
0cad65f
improved documentation
Oct 15, 2021
038c6b7
deleted test output
Oct 15, 2021
db7e044
removed debug messages
Oct 15, 2021
eefe41f
removed dead code and debug messages
Oct 15, 2021
24bfd57
Trim trailing whitespace in Sarif
sim642 Nov 3, 2021
bef4b47
Use BatList in Sarif
sim642 Nov 3, 2021
c1bbb7c
Update --sarif options
sim642 Nov 3, 2021
2cdf708
Add *.sarif to .gitignore
sim642 Nov 3, 2021
cb093d6
Remove slow Sarif GitHub workflow example
sim642 Nov 3, 2021
901dc4b
Move Sarif from framework to util
sim642 Nov 3, 2021
dfbcb7d
Move Sarif rules to SarifRules module
sim642 Nov 3, 2021
7d9040e
Move Sarif types to SarifType module
sim642 Nov 3, 2021
370ce69
Rename Sarif types to match standard
sim642 Nov 3, 2021
d356c39
Remove removePath hack for Sarif
sim642 Nov 3, 2021
2636adb
Merge branch 'master' into sarif
sim642 Nov 3, 2021
7f9aa31
Remove scripts/run
sim642 Nov 3, 2021
9a8d370
Clean up Sarif in Analyses
sim642 Nov 3, 2021
2c52bfd
Revert Sarif whitespace changes to unrelated files
sim642 Nov 3, 2021
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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,6 @@ incremental_data/
*.log

# make relocatable
relocatable/
relocatable/

*.sarif
4 changes: 4 additions & 0 deletions src/framework/analyses.ml
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,10 @@ struct
iter insert (Lazy.force table);
let t1 = Unix.gettimeofday () -. t in
Printf.printf "Done in %fs!\n" t1 *)
| "sarif" ->
let open BatPrintf in
printf "Writing Sarif to file: %s\n%!" (get_string "outfile");
Yojson.Safe.pretty_to_channel ~std:true out (Sarif.to_yojson (List.rev !Messages.Table.messages_list));
| "json-messages" ->
Yojson.Safe.pretty_to_channel ~std:true out (Messages.Table.to_yojson ())
| "none" -> ()
Expand Down
7 changes: 7 additions & 0 deletions src/maingoblint.ml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ let option_spec_list =
set_bool "g2html" true;
set_string "result" "fast_xml"
in
let configure_sarif () =
if (get_string "outfile" = "") then
set_string "outfile" "goblint.sarif";
set_bool "dbg.print_dead_code" true;
set_string "result" "sarif"
in
let tmp_arg = ref "" in
[ "-o" , Arg.String (set_string "outfile"), ""
; "-v" , Arg.Unit (fun () -> set_bool "dbg.verbose" true; set_bool "printstats" true), ""
Expand All @@ -99,6 +105,7 @@ let option_spec_list =
; "--tracelocs" , add_int Tracing.tracelocs, ""
; "--help" , Arg.Unit (fun _ -> print_help stdout),""
; "--html" , Arg.Unit (fun _ -> configure_html ()),""
; "--sarif" , Arg.Unit (fun _ -> configure_sarif ()),""
; "--compare_runs" , Arg.Tuple [Arg.Set_string tmp_arg; Arg.String (fun x -> set_auto "compare_runs" (sprintf "['%s','%s']" !tmp_arg x))], ""
; "--oil" , Arg.String oil, ""
(* ; "--tramp" , Arg.String (set_string "ana.osek.tramp"), "" *)
Expand Down
2 changes: 1 addition & 1 deletion src/util/defaults.ml
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ let default_schema = {schema|
, "justcil" : {}
, "justcfg" : {}
, "printstats" : {}
, "verify" : {}
, "verify" : {}
, "mainfun" : {}
, "exitfun" : {}
, "otherfun" : {}
Expand Down
25 changes: 25 additions & 0 deletions src/util/messageCategory.ml
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,31 @@ let path_show e =

let show x = String.concat " > " (path_show x)

let behaviorName = function
|Machine -> "Machine";
|Implementation -> "Implementation"
|Undefined u -> match u with
|NullPointerDereference -> "NullPointerDereference"
|UseAfterFree -> "UseAfterFree"
| ArrayOutOfBounds aob -> match aob with
| PastEnd -> "PastEnd"
| BeforeStart -> "BeforeStart"
| Unknown -> "Unknown Aob"
let categoryName = function
| Assert -> "Assert"

| Race -> "Race"
| Cast x -> "Cast"
| Deadcode -> "Deadcode"
| Unknown -> "Unknown"
| Analyzer -> "Analyzer"

| Behavior x -> behaviorName x
| Integer x -> match x with
| Overflow -> "Overflow";
| DivByZero -> "DivByZero"


let from_string_list (s: string list) =
match s with
| [] -> Unknown
Expand Down
157 changes: 157 additions & 0 deletions src/util/sarif.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
(** The Sarif format is a standardised output format for static analysis tools. https://docs.oasis-open.org/sarif/sarif/v2.1.0/sarif-v2.1.0.html *)
open Prelude

open SarifType
open SarifRules

module Region = SarifType.Region (* TODO: why is this needed if SarifType is opened? *)


(*matches the Goblint severity to the Sarif property level.*)
let severityToLevel (severity:Messages.Severity.t)= match severity with
| Error -> "error"
| Warning -> "warning"
| Info -> "note"
| Debug -> "none"
| Success -> "none"


let createMessageObject (text:String.t) =
{
Message.text=text;
}
(*A reportingDescriptor offers a lot of information about a Goblint rule *)
let createReportingDescriptor categoryInformation =
{
ReportingDescriptor.ruleId=categoryInformation.ruleId;
ReportingDescriptor.ruleName=categoryInformation.name;
ReportingDescriptor.helpUri=categoryInformation.helpUri;
ReportingDescriptor.help=(createMessageObject categoryInformation.helpText);
ReportingDescriptor.shortDescription=(createMessageObject categoryInformation.shortDescription);
ReportingDescriptor.fullDescription=(createMessageObject categoryInformation.longDescription);
}

let transformToReportingDescriptor (id:String.t)=
createReportingDescriptor (getRuleInformation id)

let (driverObject:ToolComponent.t) =
{
ToolComponent.name="Goblint";
ToolComponent.fullName= "Goblint static analyser";
ToolComponent.informationUri="https://goblint.in.tum.de/home";
ToolComponent.organization="TUM - i2 and UTartu - SWS";
ToolComponent.version=Version.goblint;
ToolComponent.rules=List.map transformToReportingDescriptor (List.map (fun rule -> rule.name) rules)
}
let (toolObject:Tool.t) =
{
Tool.driver=driverObject;
}


(*returns the Rule corresponding to a message entry *)
let getCategoryInformationID (tags:Messages.Tags.t) =
let getCWE (tag:Messages.Tag.t) = match tag with
| CWE cwe-> Some cwe;
| Category cat -> None;
in
(* if a CWE is present only the CWE is used, since using multiple ones for the same result doesn' make sense.
If only Categorys are present, all of them are displayed.*)
match List.find_map_opt getCWE tags with
| Some cwe -> string_of_int cwe;
| None -> match tags with
| [] -> ""
| x::xs -> match x with
|Category cat-> MessageCategory.categoryName cat
| CWE c-> "" (*this case should not be reachable *)


let createArtifact (uri:string) =
{
Artifact.location={
ArtifactLocation.uri=uri;
}
}
let createArtifactObject (uri:string) =
{
ArtifactLocation.uri=uri;
}
let hasLocation (piece:Messages.Piece.t) = match piece.loc with
|Some loc -> true
|None -> false
(*should only be called after hasLocation*)
let deOptionalizeLocation (piece:Messages.Piece.t)= match piece.loc with
| Some loc ->loc
| None -> assert false

let createPhysicalLocationObject (piece:Messages.Piece.t) =
let createRegionObject (line,column)=
{
Region.startLine=line;
Region.startColumn=column;
Region.endLine=line+4;
Region.endColumn=column+4;
}
in
{
Location.physicalLocation={
PhysicalLocation.artifactLocation= createArtifactObject (deOptionalizeLocation piece).file;
PhysicalLocation.region=createRegionObject ((deOptionalizeLocation piece).line,(deOptionalizeLocation piece).column);
}
}


let createLocationsObject (multiPiece:Messages.MultiPiece.t) = match multiPiece with
| Single piece ->List.map createPhysicalLocationObject (List.filter hasLocation [piece]);
| Group {group_text = n; pieces = e} ->List.map createPhysicalLocationObject (List.take 10 (List.filter hasLocation e))



let createResult (message:Messages.Message.t) =
let getMessage (multiPiece:Messages.MultiPiece.t)= match multiPiece with
| Single piece ->piece.text;
| Group {group_text = n; pieces = e} ->n
in
{
Result.ruleId=(getRuleInformation (getCategoryInformationID message.tags)).ruleId;
Result.level=severityToLevel message.severity;
Result.message=createMessageObject (getMessage message.multipiece);
Result.locations=createLocationsObject message.multipiece;
}

let getFileLocation (multipiece:Messages.MultiPiece.t)=
let getFile (loc:Cil.location) =
loc.file
in
let toLocation = match multipiece with

| Single piece ->[deOptionalizeLocation piece];
| Group {group_text = n; pieces = e} ->
List.map deOptionalizeLocation (List.filter hasLocation e);
in
List.map getFile toLocation

let collectAllFileLocations (msgList:Messages.Message.t list)=
let getUris=
List.flatten (List.map (fun (msg:Messages.Message.t)-> getFileLocation msg.multipiece) msgList)
in
let uniques x xs = if List.mem x xs then xs else x::xs;
in
List.fold_right uniques getUris []
let runObject msgList=
{
Run.invocations=[{
Invocation.commandLine=String.concat ", " (BatArray.to_list BatSys.argv) ;
Invocation.executionSuccessful=true;
}];
Run.artifacts= List.map createArtifact (collectAllFileLocations msgList);
Run.tool=toolObject;
Run.defaultSourceLanguage="C";
Run.results=List.map createResult (List.take 5000 msgList);
}

let sarifObject msgList={SarifLog.version="2.1.0";
SarifLog.schema="https://schemastore.azurewebsites.net/schemas/json/sarif-2.1.0-rtm.5.json";
SarifLog.runs=[runObject msgList] }

let to_yojson msgList= [%to_yojson: SarifLog.t] (sarifObject msgList)
Loading