Skip to content

Commit 83c638d

Browse files
committed
writer-json-simple: provide csdiff/v1 fingerprints
... when the line content in the `csgrep --embed-context` format is available. Out of the 1783 fingerprints generated for the csgrep regression tests we got 115 collisions, which need to be analyzed. Some of them look undesired as, for example: ``` Error: CERT EXP40-C (CWE-758): wget-1.21.1/src/http.c:256: cert_exp40_c_violation: Casting pointer "value" with type "char const *" to type "void *" allows an object defined with a const-qualified type to be modified through use of an lvalue with non-const-qualified type. # 254| release_header (hdr); # 255| hdr->name = (void *)name; # 256|-> hdr->value = (void *)value; # 257| hdr->release_policy = release_policy; # 258| return; Error: CERT EXP40-C (CWE-758): wget-1.21.1/src/http.c:271: cert_exp40_c_violation: Casting pointer "value" with type "char const *" to type "void *" allows an object defined with a const-qualified type to be modified through use of an lvalue with non-const-qualified type. # 269| hdr = &req->headers[req->hcount++]; # 270| hdr->name = (void *)name; # 271|-> hdr->value = (void *)value; # 272| hdr->release_policy = release_policy; # 273| } ``` Related: #98
1 parent 328de8a commit 83c638d

9 files changed

+1791
-0
lines changed

src/lib/parser-json-simple.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ SimpleTreeDecoder::Private::Private(InStream &input):
6060
"defect_id",
6161
"events",
6262
"function",
63+
"hash_v1",
6364
"imp",
6465
"key_event_idx",
6566
"language",

src/lib/writer-json-simple.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include "writer-json-simple.hh"
2121

22+
#include "finger-print.hh"
2223
#include "writer-json-common.hh"
2324

2425
using namespace boost::json;
@@ -83,6 +84,12 @@ void SimpleTreeEncoder::appendDef(const Defect &def)
8384
if (!def.tool.empty())
8485
defNode["tool"] = def.tool;
8586

87+
// encode fingerprint if available
88+
const FingerPrinter fp(def);
89+
const std::string hash = fp.getHash(FPV_CSDIFF_WITH_LINE_CONTENT);
90+
if (!hash.empty())
91+
defNode["hash_v1"] = hash;
92+
8693
// encode events
8794
defNode["key_event_idx"] = def.keyEventIdx;
8895
defNode["events"] = simpleEncodeEvents(def.events);

tests/csgrep/0036-csgrep-json-stdout.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"checker": "SHELLCHECK_WARNING",
55
"language": "shell",
66
"tool": "shellcheck",
7+
"hash_v1": "b6311c1fdc52c47d4279cd6650af36e6f8299960",
78
"key_event_idx": 0,
89
"events": [
910
{

tests/csgrep/0069-csfilter-python-build-path-stdout.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"cwe": 398,
2929
"function": "_iglob",
3030
"language": "python",
31+
"hash_v1": "554e9b7906f0190923e89202997ef41ff2fb2ff1",
3132
"key_event_idx": 1,
3233
"events": [
3334
{

tests/csgrep/0070-csparser-included-from-note-stdout.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"cwe": 758,
66
"language": "c/c++",
77
"tool": "gcc",
8+
"hash_v1": "3d6f5aa62d8ec23aa8f96f320fa7cda8d60941f4",
89
"key_event_idx": 10,
910
"events": [
1011
{
@@ -127,6 +128,7 @@
127128
"cwe": 758,
128129
"language": "c/c++",
129130
"tool": "gcc",
131+
"hash_v1": "f448f63e387cbc6662221e3efe5f3c13b5f98b4b",
130132
"key_event_idx": 11,
131133
"events": [
132134
{

tests/csgrep/0086-sarif-parser-stdout.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"checker": "UNCAUGHT_EXCEPT",
2929
"cwe": 248,
3030
"tool": "coverity",
31+
"hash_v1": "f75915548d17ebc31e35ad7c4f34514688703109",
3132
"key_event_idx": 0,
3233
"events": [
3334
{
@@ -85,6 +86,7 @@
8586
"checker": "UNCAUGHT_EXCEPT",
8687
"cwe": 248,
8788
"tool": "coverity",
89+
"hash_v1": "f751115465d08a034db0c47d3bdda83d544dc285",
8890
"key_event_idx": 0,
8991
"events": [
9092
{
@@ -142,6 +144,7 @@
142144
"checker": "UNCAUGHT_EXCEPT",
143145
"cwe": 248,
144146
"tool": "coverity",
147+
"hash_v1": "ffed405bfb4ef75b9de1588f2ae94661db90cb8f",
145148
"key_event_idx": 0,
146149
"events": [
147150
{
@@ -199,6 +202,7 @@
199202
"checker": "UNCAUGHT_EXCEPT",
200203
"cwe": 248,
201204
"tool": "coverity",
205+
"hash_v1": "b59a6dfe30dd990e93bc2ff51b9a61e1fc3b0926",
202206
"key_event_idx": 0,
203207
"events": [
204208
{
@@ -256,6 +260,7 @@
256260
"checker": "UNCAUGHT_EXCEPT",
257261
"cwe": 248,
258262
"tool": "coverity",
263+
"hash_v1": "2b94655ac88de81e21564d68ba609c967257d460",
259264
"key_event_idx": 0,
260265
"events": [
261266
{
@@ -313,6 +318,7 @@
313318
"checker": "UNCAUGHT_EXCEPT",
314319
"cwe": 248,
315320
"tool": "coverity",
321+
"hash_v1": "3489908a33d71933646018c6af1d99654c12f995",
316322
"key_event_idx": 0,
317323
"events": [
318324
{
@@ -370,6 +376,7 @@
370376
"checker": "UNCAUGHT_EXCEPT",
371377
"cwe": 248,
372378
"tool": "coverity",
379+
"hash_v1": "05bc362f71d27e6caca89cb7eaed08720379622e",
373380
"key_event_idx": 0,
374381
"events": [
375382
{
@@ -427,6 +434,7 @@
427434
"checker": "UNCAUGHT_EXCEPT",
428435
"cwe": 248,
429436
"tool": "coverity",
437+
"hash_v1": "8f8bd8e7bc4b3458dddeb917207831b973ff44d0",
430438
"key_event_idx": 0,
431439
"events": [
432440
{
@@ -484,6 +492,7 @@
484492
"checker": "UNCAUGHT_EXCEPT",
485493
"cwe": 248,
486494
"tool": "coverity",
495+
"hash_v1": "58e1f662e974930637555fd08b0d7bc584eb389c",
487496
"key_event_idx": 0,
488497
"events": [
489498
{
@@ -541,6 +550,7 @@
541550
"checker": "UNCAUGHT_EXCEPT",
542551
"cwe": 248,
543552
"tool": "coverity",
553+
"hash_v1": "1ceac5351bf27c316a7317f1d5ae782890a489ca",
544554
"key_event_idx": 0,
545555
"events": [
546556
{
@@ -598,6 +608,7 @@
598608
"checker": "UNCAUGHT_EXCEPT",
599609
"cwe": 248,
600610
"tool": "coverity",
611+
"hash_v1": "63ae1429f2f7edeea500344b6181c2a426f13b8c",
601612
"key_event_idx": 0,
602613
"events": [
603614
{
@@ -655,6 +666,7 @@
655666
"checker": "UNCAUGHT_EXCEPT",
656667
"cwe": 248,
657668
"tool": "coverity",
669+
"hash_v1": "aac84c26219cc0e4ae0b0e916ea65a0a897ea5cb",
658670
"key_event_idx": 0,
659671
"events": [
660672
{
@@ -712,6 +724,7 @@
712724
"checker": "UNCAUGHT_EXCEPT",
713725
"cwe": 248,
714726
"tool": "coverity",
727+
"hash_v1": "abd11bd54a40383a913a850e6cba5634d404134a",
715728
"key_event_idx": 0,
716729
"events": [
717730
{
@@ -769,6 +782,7 @@
769782
"checker": "UNCAUGHT_EXCEPT",
770783
"cwe": 248,
771784
"tool": "coverity",
785+
"hash_v1": "9afea3c68ec0867020943d0343b5c46fc63cd38a",
772786
"key_event_idx": 0,
773787
"events": [
774788
{
@@ -826,6 +840,7 @@
826840
"checker": "UNCAUGHT_EXCEPT",
827841
"cwe": 248,
828842
"tool": "coverity",
843+
"hash_v1": "7277dca5030b5230bd7279fbd4d2da5d9f2dfd2a",
829844
"key_event_idx": 0,
830845
"events": [
831846
{
@@ -883,6 +898,7 @@
883898
"checker": "UNCAUGHT_EXCEPT",
884899
"cwe": 248,
885900
"tool": "coverity",
901+
"hash_v1": "3a30dc31a50e73377464370e31ef610d45e459e2",
886902
"key_event_idx": 0,
887903
"events": [
888904
{
@@ -940,6 +956,7 @@
940956
"checker": "UNCAUGHT_EXCEPT",
941957
"cwe": 248,
942958
"tool": "coverity",
959+
"hash_v1": "fb0aa5afe7e8d70ebfc6069c2acc185d3c97b941",
943960
"key_event_idx": 0,
944961
"events": [
945962
{
@@ -997,6 +1014,7 @@
9971014
"checker": "UNCAUGHT_EXCEPT",
9981015
"cwe": 248,
9991016
"tool": "coverity",
1017+
"hash_v1": "e0c742d03cd6f29e0611b4992b1292dade93ec5c",
10001018
"key_event_idx": 0,
10011019
"events": [
10021020
{
@@ -1054,6 +1072,7 @@
10541072
"checker": "UNCAUGHT_EXCEPT",
10551073
"cwe": 248,
10561074
"tool": "coverity",
1075+
"hash_v1": "4184f94fe78777e886108f7cda4b64c1ab380c6a",
10571076
"key_event_idx": 0,
10581077
"events": [
10591078
{
@@ -1111,6 +1130,7 @@
11111130
"checker": "UNCAUGHT_EXCEPT",
11121131
"cwe": 248,
11131132
"tool": "coverity",
1133+
"hash_v1": "3ddf218d4bfcbcc00ddb78214866ea90daff11f4",
11141134
"key_event_idx": 0,
11151135
"events": [
11161136
{
@@ -1168,6 +1188,7 @@
11681188
"checker": "UNINIT_CTOR",
11691189
"cwe": 456,
11701190
"tool": "coverity",
1191+
"hash_v1": "4b7e4e2caa66077653924005972f710a5cb6d400",
11711192
"key_event_idx": 1,
11721193
"events": [
11731194
{
@@ -1225,6 +1246,7 @@
12251246
"checker": "UNINIT_CTOR",
12261247
"cwe": 456,
12271248
"tool": "coverity",
1249+
"hash_v1": "eb2f4311ffbce9e44a3814d2dec6a85853e9992f",
12281250
"key_event_idx": 1,
12291251
"events": [
12301252
{

0 commit comments

Comments
 (0)