Fix missing 'region' key in relatedLocations: use whole-file output

The goal is fixed-structure output formatting, so whole-file output uses
-1,-1,-1,-1 for line, column information.
This commit is contained in:
Michael Hohn
2021-12-08 16:02:31 -08:00
committed by =Michael Hohn
parent 1271589bc4
commit f1d21e4a43
2 changed files with 12 additions and 3 deletions

View File

@@ -71,6 +71,10 @@ for runi in S.indices(sarif_struct, 'runs'):
else:
S.msg("REFERENCE: %s: %s\n\n" % ("<NoFile>", message))
else:
if region == S.WholeFile:
l1, c1, l2, c2 = -1, -1, -1, -1
else:
l1, c1, l2, c2 = S.lineinfo(region)
l1, c1, l2, c2 = S.lineinfo(region)
filepath = "%s:%d:%d:%d:%d" % (artifact['uri'], l1, c1, l2, c2)
if args.csv:
@@ -96,6 +100,9 @@ for runi in S.indices(sarif_struct, 'runs'):
S.write_csv(cw, "flow_step", loci, "<NoFile>", -1, -1, -1, -1, message)
else:
S.msg("FLOW STEP %d: %s: %s\n\n" % (loci, "<NoFile>", message))
else:
if region == S.WholeFile:
l1, c1, l2, c2 = -1, -1, -1, -1
else:
l1, c1, l2, c2 = S.lineinfo(region)
filepath = "%s:%d:%d:%d:%d" % (artifact['uri'], l1, c1, l2, c2)

View File

@@ -45,11 +45,13 @@ def get_relatedlocation_message_info(related_location):
Returns: (message, artifact, region) by default
For an empty 'physicalLocation' key, returns (message, sarif_cli.NoFile, sarif_cli.NoFile)
For an empty 'region' key, returns (message, artifact, sarif_cli.WholeFile)
"""
message = get(related_location, 'message', 'text')
if 'physicalLocation' in related_location:
artifact = get(related_location, 'physicalLocation', 'artifactLocation')
region = get(related_location, 'physicalLocation', 'region')
ploc = get(related_location, 'physicalLocation')
artifact = ploc.get('artifactLocation')
region = ploc.get('region', WholeFile)
else:
artifact, region = NoFile, NoFile
return message, artifact, region