sqc 0.4.84

Software Code Quality - CERT C compliance checker
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
{
"liolib.c": [
{
"column": 1,
"file": "/home/brandon/toolchain/lua/liolib.c",
"line": 39,
"message": "Function 'l_checkmode' performs compound operation on shared static variable 'mode' without synchronization",
"rule_id": "CON07-C",
"severity": "Medium",
"suggestion": "Use mutex locks (mtx_lock/mtx_unlock) or atomic operations to ensure atomicity"
},
{
"column": 11,
"file": "/home/brandon/toolchain/lua/liolib.c",
"line": 40,
"message": "Variable(s) 'mode' modified and accessed without sequence point",
"rule_id": "EXP30-C",
"severity": "High",
"suggestion": "Separate the modification into a separate statement"
},
{
"column": 11,
"file": "/home/brandon/toolchain/lua/liolib.c",
"line": 40,
"message": "Variable(s) 'mode' modified and accessed without sequence point",
"rule_id": "EXP30-C",
"severity": "High",
"suggestion": "Separate the modification into a separate statement"
},
{
"column": 11,
"file": "/home/brandon/toolchain/lua/liolib.c",
"line": 40,
"message": "Variable(s) 'mode' modified and accessed without sequence point",
"rule_id": "EXP30-C",
"severity": "High",
"suggestion": "Separate the modification into a separate statement"
},
{
"column": 11,
"file": "/home/brandon/toolchain/lua/liolib.c",
"line": 41,
"message": "Variable(s) 'mode' modified and accessed without sequence point",
"rule_id": "EXP30-C",
"severity": "High",
"suggestion": "Separate the modification into a separate statement"
},
{
"column": 1,
"file": "/home/brandon/toolchain/lua/liolib.c",
"line": 68,
"message": "Function-like macro 'l_checkmodep' evaluates parameter(s) multiple times; prefer inline or static functions for type safety",
"rule_id": "PRE00-C",
"severity": "Low",
"suggestion": null
},
{
"column": 1,
"file": "/home/brandon/toolchain/lua/liolib.c",
"line": 68,
"message": "Macro parameter 'm' is not parenthesized in replacement text. This can cause operator precedence issues.",
"rule_id": "PRE01-C",
"severity": "Medium",
"suggestion": "Wrap parameter 'm' in parentheses: (m) instead of m"
},
{
"column": 1,
"file": "/home/brandon/toolchain/lua/liolib.c",
"line": 68,
"message": "Macro evaluates parameter 'm' multiple times; use inline function instead",
"rule_id": "PRE12-C",
"severity": "Medium",
"suggestion": "Replace macro with inline function to avoid multiple evaluation"
},
{
"column": 1,
"file": "/home/brandon/toolchain/lua/liolib.c",
"line": 88,
"message": "Function-like macro 'l_checkmodep' evaluates parameter(s) multiple times; prefer inline or static functions for type safety",
"rule_id": "PRE00-C",
"severity": "Low",
"suggestion": null
},
{
"column": 1,
"file": "/home/brandon/toolchain/lua/liolib.c",
"line": 88,
"message": "Macro parameter 'm' is not parenthesized in replacement text. This can cause operator precedence issues.",
"rule_id": "PRE01-C",
"severity": "Medium",
"suggestion": "Wrap parameter 'm' in parentheses: (m) instead of m"
},
{
"column": 1,
"file": "/home/brandon/toolchain/lua/liolib.c",
"line": 88,
"message": "Macro evaluates parameter 'm' multiple times; use inline function instead",
"rule_id": "PRE12-C",
"severity": "Medium",
"suggestion": "Replace macro with inline function to avoid multiple evaluation"
},
{
"column": 3,
"file": "/home/brandon/toolchain/lua/liolib.c",
"line": 202,
"message": "Potential null pointer dereference in member access of variable 'p'",
"rule_id": "EXP34-C",
"severity": "High",
"suggestion": "Check if 'p' is not NULL before member access"
},
{
"column": 3,
"file": "/home/brandon/toolchain/lua/liolib.c",
"line": 204,
"message": "Function returns pointer to local variable 'p' with automatic storage duration",
"rule_id": "DCL30-C",
"severity": "High",
"suggestion": "Use static storage, allocated memory, or pass output buffer as parameter"
},
{
"column": 3,
"file": "/home/brandon/toolchain/lua/liolib.c",
"line": 254,
"message": "Potential null pointer dereference in member access of variable 'p'",
"rule_id": "EXP34-C",
"severity": "High",
"suggestion": "Check if 'p' is not NULL before member access"
},
{
"column": 3,
"file": "/home/brandon/toolchain/lua/liolib.c",
"line": 256,
"message": "Function returns pointer to local variable 'p' with automatic storage duration",
"rule_id": "DCL30-C",
"severity": "High",
"suggestion": "Use static storage, allocated memory, or pass output buffer as parameter"
},
{
"column": 3,
"file": "/home/brandon/toolchain/lua/liolib.c",
"line": 262,
"message": "Potential null pointer dereference in member access of variable 'p'",
"rule_id": "EXP34-C",
"severity": "High",
"suggestion": "Check if 'p' is not NULL before member access"
},
{
"column": 3,
"file": "/home/brandon/toolchain/lua/liolib.c",
"line": 262,
"message": "FILE pointer 'p->f' opened with fopen/freopen but never closed with fclose()",
"rule_id": "FIO42-C",
"severity": "High",
"suggestion": "Add fclose(p->f) before function returns or program exits"
},
{
"column": 3,
"file": "/home/brandon/toolchain/lua/liolib.c",
"line": 262,
"message": "File descriptor 'p->f' opened with open() but never closed with close()",
"rule_id": "FIO42-C",
"severity": "High",
"suggestion": "Add close(p->f) before function returns or program exits"
},
{
"column": 10,
"file": "/home/brandon/toolchain/lua/liolib.c",
"line": 262,
"message": "File opened with fopen() but not closed with fclose()",
"rule_id": "FIO51-C",
"severity": "Medium",
"suggestion": "Call fclose() before function returns"
},
{
"column": 56,
"file": "/home/brandon/toolchain/lua/liolib.c",
"line": 264,
"message": "Call to non-thread-safe function 'strerror'. Use strerror_r() (POSIX) or strerror_s() (C11 Annex K) for thread-safe error reporting",
"rule_id": "CON33-C",
"severity": "Medium",
"suggestion": "Use strerror_r() (POSIX) or strerror_s() (C11 Annex K) for thread-safe error reporting"
},
{
"column": 56,
"file": "/home/brandon/toolchain/lua/liolib.c",
"line": 264,
"message": "'strerror()' uses internal static storage that is shared between threads",
"rule_id": "CON34-C",
"severity": "Medium",
"suggestion": "Use 'strerror_r' instead for thread safety"
},
{
"column": 3,
"file": "/home/brandon/toolchain/lua/liolib.c",
"line": 275,
"message": "Potential null pointer dereference in member access of variable 'p'",
"rule_id": "EXP34-C",
"severity": "High",
"suggestion": "Check if 'p' is not NULL before member access"
},
{
"column": 3,
"file": "/home/brandon/toolchain/lua/liolib.c",
"line": 275,
"message": "FILE pointer 'p->f' opened with fopen/freopen but never closed with fclose()",
"rule_id": "FIO42-C",
"severity": "High",
"suggestion": "Add fclose(p->f) before function returns or program exits"
},
{
"column": 3,
"file": "/home/brandon/toolchain/lua/liolib.c",
"line": 275,
"message": "File descriptor 'p->f' opened with open() but never closed with close()",
"rule_id": "FIO42-C",
"severity": "High",
"suggestion": "Add close(p->f) before function returns or program exits"
},
{
"column": 10,
"file": "/home/brandon/toolchain/lua/liolib.c",
"line": 275,
"message": "Return value from fopen() should be checked for errors",
"rule_id": "ERR00-C",
"severity": "Medium",
"suggestion": "Check if fopen() returned an error value (NULL, -1, etc.)"
},
{
"column": 10,
"file": "/home/brandon/toolchain/lua/liolib.c",
"line": 275,
"message": "File opened with fopen() but not closed with fclose()",
"rule_id": "FIO51-C",
"severity": "Medium",
"suggestion": "Call fclose() before function returns"
},
{
"column": 3,
"file": "/home/brandon/toolchain/lua/liolib.c",
"line": 296,
"message": "Potential null pointer dereference in member access of variable 'p'",
"rule_id": "EXP34-C",
"severity": "High",
"suggestion": "Check if 'p' is not NULL before member access"
},
{
"column": 3,
"file": "/home/brandon/toolchain/lua/liolib.c",
"line": 296,
"message": "File descriptor 'p->f' opened with open() but never closed with close()",
"rule_id": "FIO42-C",
"severity": "High",
"suggestion": "Add close(p->f) before function returns or program exits"
},
{
"column": 3,
"file": "/home/brandon/toolchain/lua/liolib.c",
"line": 305,
"message": "Potential null pointer dereference in member access of variable 'p'",
"rule_id": "EXP34-C",
"severity": "High",
"suggestion": "Check if 'p' is not NULL before member access"
},
{
"column": 10,
"file": "/home/brandon/toolchain/lua/liolib.c",
"line": 305,
"message": "tmpfile() creates temporary files in a shared directory (typically /tmp), which is vulnerable to race conditions and symlink attacks. Use mkstemp() in a secure directory instead.",
"rule_id": "FIO21-C",
"severity": "High",
"suggestion": "Use mkstemp() with a template in a secure, user-specific directory"
},
{
"column": 10,
"file": "/home/brandon/toolchain/lua/liolib.c",
"line": 316,
"message": "Potential null pointer dereference in member access of variable 'p'",
"rule_id": "EXP34-C",
"severity": "High",
"suggestion": "Check if 'p' is not NULL before member access"
},
{
"column": 17,
"file": "/home/brandon/toolchain/lua/liolib.c",
"line": 468,
"message": "Plain 'char' passed to 'isxdigit()' without cast to 'unsigned char'",
"rule_id": "STR00-C",
"severity": "Medium",
"suggestion": "Cast to '(unsigned char)' before passing to 'isxdigit()': isxdigit((unsigned char)rn->c)"
},
{
"column": 26,
"file": "/home/brandon/toolchain/lua/liolib.c",
"line": 468,
"message": "Argument to 'isxdigit()' is not cast to unsigned char. This can cause undefined behavior if the argument has a negative value.",
"rule_id": "STR37-C",
"severity": "Medium",
"suggestion": "Cast the argument to unsigned char: 'isxdigit((unsigned char)...)'"
},
{
"column": 35,
"file": "/home/brandon/toolchain/lua/liolib.c",
"line": 468,
"message": "Plain 'char' passed to 'isdigit()' without cast to 'unsigned char'",
"rule_id": "STR00-C",
"severity": "Medium",
"suggestion": "Cast to '(unsigned char)' before passing to 'isdigit()': isdigit((unsigned char)rn->c)"
},
{
"column": 43,
"file": "/home/brandon/toolchain/lua/liolib.c",
"line": 468,
"message": "Argument to 'isdigit()' is not cast to unsigned char. This can cause undefined behavior if the argument has a negative value.",
"rule_id": "STR37-C",
"severity": "Medium",
"suggestion": "Cast the argument to unsigned char: 'isdigit((unsigned char)...)'"
},
{
"column": 44,
"file": "/home/brandon/toolchain/lua/liolib.c",
"line": 479,
"message": "Pointer parameter 'f' is not modified and should be declared const",
"rule_id": "DCL13-C",
"severity": "Low",
"suggestion": "Declare parameter as 'const <type> *f'"
},
{
"column": 38,
"file": "/home/brandon/toolchain/lua/liolib.c",
"line": 488,
"message": "Plain 'char' passed to 'isspace()' without cast to 'unsigned char'",
"rule_id": "STR00-C",
"severity": "Medium",
"suggestion": "Cast to '(unsigned char)' before passing to 'isspace()': isspace((unsigned char)rn.c)"
},
{
"column": 46,
"file": "/home/brandon/toolchain/lua/liolib.c",
"line": 488,
"message": "Argument to 'isspace()' is not cast to unsigned char. This can cause undefined behavior if the argument has a negative value.",
"rule_id": "STR37-C",
"severity": "Medium",
"suggestion": "Cast the argument to unsigned char: 'isspace((unsigned char)...)'"
},
{
"column": 3,
"file": "/home/brandon/toolchain/lua/liolib.c",
"line": 501,
"message": "Return value of 'ungetc' ignored: 'ungetc(rn.c, rn.f)' - Can return error indicator",
"rule_id": "ERR33-C",
"severity": "High",
"suggestion": "Check return value for errors"
},
{
"column": 3,
"file": "/home/brandon/toolchain/lua/liolib.c",
"line": 514,
"message": "Variable 'c' is initialized but never modified, consider const-qualifying it",
"rule_id": "DCL00-C",
"severity": "Medium",
"suggestion": "Add 'const' qualifier: const c = ..."
},
{
"column": 3,
"file": "/home/brandon/toolchain/lua/liolib.c",
"line": 515,
"message": "Return value of 'ungetc' ignored: 'ungetc(c, f)' - Can return error indicator",
"rule_id": "ERR33-C",
"severity": "High",
"suggestion": "Check return value for errors"
},
{
"column": 3,
"file": "/home/brandon/toolchain/lua/liolib.c",
"line": 525,
"message": "EOF comparison without feof()/ferror() verification: 'do {  /* may need to read several chunks to get whole line */'",
"rule_id": "FIO34-C",
"severity": "High",
"suggestion": "After EOF is detected, call feof() and ferror() to distinguish between end-of-file and I/O error"
},
{
"column": 5,
"file": "/home/brandon/toolchain/lua/liolib.c",
"line": 529,
"message": "EOF comparison without feof()/ferror() verification: 'while (i < LUAL_BUFFERSIZE && (c = l_getc(f)) != EOF && c != '\\n')'",
"rule_id": "FIO34-C",
"severity": "High",
"suggestion": "After EOF is detected, call feof() and ferror() to distinguish between end-of-file and I/O error"
},
{
"column": 12,
"file": "/home/brandon/toolchain/lua/liolib.c",
"line": 529,
"message": "Variable(s) 'c' modified and accessed without sequence point",
"rule_id": "EXP30-C",
"severity": "High",
"suggestion": "Separate the modification into a separate statement"
},
{
"column": 61,
"file": "/home/brandon/toolchain/lua/liolib.c",
"line": 529,
"message": "Variable 'c' may be used uninitialized (not assigned on all paths)",
"rule_id": "EXP33-C",
"severity": "High",
"suggestion": "Initialize 'c' before use, e.g., at its declaration"
},
{
"column": 24,
"file": "/home/brandon/toolchain/lua/liolib.c",
"line": 538,
"message": "Function 'lua_rawlen' is called without prior declaration",
"rule_id": "DCL31-C",
"severity": "Low",
"suggestion": "Declare the function before calling it or include the appropriate header"
},
{
"column": 5,
"file": "/home/brandon/toolchain/lua/liolib.c",
"line": 548,
"message": "Return value of 'fread' assigned to 'nr' but not checked for errors: 'fread(p, sizeof(char), LUAL_BUFFERSIZE, f)' - Returns number of items read, may be less than requested",
"rule_id": "ERR33-C",
"severity": "High",
"suggestion": "Check if (items_read == expected_items) or handle partial reads"
},
{
"column": 10,
"file": "/home/brandon/toolchain/lua/liolib.c",
"line": 548,
"message": "Return value from fread() should be checked for errors",
"rule_id": "ERR00-C",
"severity": "Medium",
"suggestion": "Check if fread() returned an error value (NULL, -1, etc.)"
},
{
"column": 10,
"file": "/home/brandon/toolchain/lua/liolib.c",
"line": 548,
"message": "fread() used without explicitly accounting for null terminator in character buffer",
"rule_id": "FIO17-C",
"severity": "Medium",
"suggestion": "Ensure buffer size accounts for null terminator, or explicitly add null terminator after fread()"
},
{
"column": 8,
"file": "/home/brandon/toolchain/lua/liolib.c",
"line": 561,
"message": "Return value from fread() should be checked for errors",
"rule_id": "ERR00-C",
"severity": "Medium",
"suggestion": "Check if fread() returned an error value (NULL, -1, etc.)"
},
{
"column": 8,
"file": "/home/brandon/toolchain/lua/liolib.c",
"line": 561,
"message": "fread() used without explicitly accounting for null terminator in character buffer",
"rule_id": "FIO17-C",
"severity": "Medium",
"suggestion": "Ensure buffer size accounts for null terminator, or explicitly add null terminator after fread()"
},
{
"column": 14,
"file": "/home/brandon/toolchain/lua/liolib.c",
"line": 561,
"message": "Passing potentially null pointer 'p' to function",
"rule_id": "EXP34-C",
"severity": "High",
"suggestion": "Check if 'p' is not NULL before passing to function"
},
{
"column": 8,
"file": "/home/brandon/toolchain/lua/liolib.c",
"line": 589,
"message": "Dereferencing pointer in switch statement may create double-fetch vulnerability",
"rule_id": "CON43-C",
"severity": "High",
"suggestion": "Store dereferenced value in a local variable or use atomic operations"
},
{
"column": 17,
"file": "/home/brandon/toolchain/lua/liolib.c",
"line": 642,
"message": "Potential null pointer dereference in member access of variable 'p'",
"rule_id": "EXP34-C",
"severity": "High",
"suggestion": "Check if 'p' is not NULL before member access"
},
{
"column": 10,
"file": "/home/brandon/toolchain/lua/liolib.c",
"line": 668,
"message": "Variable 'buff' is used uninitialized",
"rule_id": "EXP33-C",
"severity": "High",
"suggestion": "Initialize 'buff' before use, e.g., at its declaration"
},
{
"column": 16,
"file": "/home/brandon/toolchain/lua/liolib.c",
"line": 678,
"message": "fwrite() count argument 'len' not derived from strlen(s). May write incorrect number of bytes.",
"rule_id": "FIO18-C",
"severity": "Medium",
"suggestion": "For null-terminated strings, use strlen(s) + 1 to include the null terminator but avoid writing uninitialized data."
},
{
"column": 23,
"file": "/home/brandon/toolchain/lua/liolib.c",
"line": 678,
"message": "Passing potentially null pointer 's' to function",
"rule_id": "EXP34-C",
"severity": "High",
"suggestion": "Check if 's' is not NULL before passing to function"
},
{
"column": 20,
"file": "/home/brandon/toolchain/lua/liolib.c",
"line": 703,
"message": "Array declaration 'mode[]' has implicit bounds; specify explicit size",
"rule_id": "ARR02-C",
"severity": "Medium",
"suggestion": "Explicitly specify array bounds even when using an initializer"
},
{
"column": 28,
"file": "/home/brandon/toolchain/lua/liolib.c",
"line": 704,
"message": "Array declaration 'modenames[]' has implicit bounds; specify explicit size",
"rule_id": "ARR02-C",
"severity": "Medium",
"suggestion": "Explicitly specify array bounds even when using an initializer"
},
{
"column": 42,
"file": "/home/brandon/toolchain/lua/liolib.c",
"line": 706,
"message": "'modenames' (signed/plain char) converted to larger integer type without cast to 'unsigned char' - may cause sign extension",
"rule_id": "STR34-C",
"severity": "Medium",
"suggestion": "Cast to 'unsigned char' before conversion to larger type"
},
{
"column": 20,
"file": "/home/brandon/toolchain/lua/liolib.c",
"line": 723,
"message": "Array declaration 'mode[]' has implicit bounds; specify explicit size",
"rule_id": "ARR02-C",
"severity": "Medium",
"suggestion": "Explicitly specify array bounds even when using an initializer"
},
{
"column": 28,
"file": "/home/brandon/toolchain/lua/liolib.c",
"line": 724,
"message": "Array declaration 'modenames[]' has implicit bounds; specify explicit size",
"rule_id": "ARR02-C",
"severity": "Medium",
"suggestion": "Explicitly specify array bounds even when using an initializer"
},
{
"column": 41,
"file": "/home/brandon/toolchain/lua/liolib.c",
"line": 726,
"message": "'modenames' (signed/plain char) converted to larger integer type without cast to 'unsigned char' - may cause sign extension",
"rule_id": "STR34-C",
"severity": "Medium",
"suggestion": "Cast to 'unsigned char' before conversion to larger type"
},
{
"column": 23,
"file": "/home/brandon/toolchain/lua/liolib.c",
"line": 754,
"message": "Array declaration 'iolib[]' has implicit bounds; specify explicit size",
"rule_id": "ARR02-C",
"severity": "Medium",
"suggestion": "Explicitly specify array bounds even when using an initializer"
},
{
"column": 23,
"file": "/home/brandon/toolchain/lua/liolib.c",
"line": 773,
"message": "Array declaration 'meth[]' has implicit bounds; specify explicit size",
"rule_id": "ARR02-C",
"severity": "Medium",
"suggestion": "Explicitly specify array bounds even when using an initializer"
},
{
"column": 23,
"file": "/home/brandon/toolchain/lua/liolib.c",
"line": 788,
"message": "Array declaration 'metameth[]' has implicit bounds; specify explicit size",
"rule_id": "ARR02-C",
"severity": "Medium",
"suggestion": "Explicitly specify array bounds even when using an initializer"
},
{
"column": 3,
"file": "/home/brandon/toolchain/lua/liolib.c",
"line": 802,
"message": "Passing string literal to function 'lua_setfield' which may modify it",
"rule_id": "STR30-C",
"severity": "High",
"suggestion": "Use a modifiable array instead of a string literal"
},
{
"column": 47,
"file": "/home/brandon/toolchain/lua/liolib.c",
"line": 819,
"message": "Pointer parameter 'f' is not modified and should be declared const",
"rule_id": "DCL13-C",
"severity": "Low",
"suggestion": "Declare parameter as 'const <type> *f'"
},
{
"column": 3,
"file": "/home/brandon/toolchain/lua/liolib.c",
"line": 822,
"message": "Potential null pointer dereference in member access of variable 'p'",
"rule_id": "EXP34-C",
"severity": "High",
"suggestion": "Check if 'p' is not NULL before member access"
},
{
"column": 1,
"file": "/home/brandon/toolchain/lua/liolib.c",
"line": 832,
"message": "Function 'luaopen_io' does not validate pointer parameter 'L' before use",
"rule_id": "API00-C",
"severity": "Medium",
"suggestion": "Add validation check for 'L' at the start of the function, e.g., 'if (!L) { return error_code; }'"
},
{
"column": 1,
"file": "/home/brandon/toolchain/lua/liolib.c",
"line": 832,
"message": "Function 'luaopen_io' should be declared static if it doesn't need external linkage",
"rule_id": "DCL15-C",
"severity": "Low",
"suggestion": "Add 'static' storage-class specifier: static LUAMOD_API luaopen_io"
}
],
"lua.c": [
{
"column": 1,
"file": "/home/brandon/toolchain/lua/lua.c",
"line": 42,
"message": "Shared variable 'globalL' lacks proper synchronization (not volatile or atomic). This may cause visibility issues across threads.",
"rule_id": "CON03-C",
"severity": "Medium",
"suggestion": "Consider declaring the variable as 'volatile', using atomic types (atomic_int, etc.), or protecting access with mutexes"
},
{
"column": 3,
"file": "/home/brandon/toolchain/lua/lua.c",
"line": 57,
"message": "sigaction() call detected without apparent signal masking. Ensure sa_mask is properly configured with sigaddset() before calling sigaction().",
"rule_id": "SIG00-C",
"severity": "High",
"suggestion": "Use sigemptyset() and sigaddset() to configure sa_mask before calling sigaction() to prevent race conditions in signal handlers."
},
{
"column": 44,
"file": "/home/brandon/toolchain/lua/lua.c",
"line": 70,
"message": "Pointer parameter 'ar' is not modified and should be declared const",
"rule_id": "DCL13-C",
"severity": "Low",
"suggestion": "Declare parameter as 'const <type> *ar'"
},
{
"column": 15,
"file": "/home/brandon/toolchain/lua/lua.c",
"line": 86,
"message": "Passing null pointer 'globalL' to 'lua_sethook' which does not check for NULL",
"rule_id": "EXP34-C",
"severity": "High",
"suggestion": "Check if 'globalL' is not NULL before passing to 'lua_sethook'"
},
{
"column": 3,
"file": "/home/brandon/toolchain/lua/lua.c",
"line": 152,
"message": "Function 'luaL_traceback' called with same pointer for output and input parameters. If output parameter is non-const restrict, this causes undefined behavior.",
"rule_id": "EXP43-C",
"severity": "High",
"suggestion": "Ensure output restrict parameter receives a unique pointer"
},
{
"column": 48,
"file": "/home/brandon/toolchain/lua/lua.c",
"line": 191,
"message": "Pointer parameter 'argv' is not modified and should be declared const",
"rule_id": "DCL13-C",
"severity": "Low",
"suggestion": "Declare parameter as 'const <type> *argv'"
},
{
"column": 3,
"file": "/home/brandon/toolchain/lua/lua.c",
"line": 199,
"message": "Passing string literal to function 'lua_setglobal' which may modify it",
"rule_id": "STR30-C",
"severity": "High",
"suggestion": "Use a modifiable array instead of a string literal"
},
{
"column": 5,
"file": "/home/brandon/toolchain/lua/lua.c",
"line": 233,
"message": "Pointer dereference '*modname' (char type) assigned without cast to 'unsigned char' - may cause sign extension",
"rule_id": "STR34-C",
"severity": "Medium",
"suggestion": "Cast to 'unsigned char' before assignment to larger type"
},
{
"column": 7,
"file": "/home/brandon/toolchain/lua/lua.c",
"line": 241,
"message": "Pointer dereference '*suffix' (char type) assigned without cast to 'unsigned char' - may cause sign extension",
"rule_id": "STR34-C",
"severity": "Medium",
"suggestion": "Cast to 'unsigned char' before assignment to larger type"
},
{
"column": 12,
"file": "/home/brandon/toolchain/lua/lua.c",
"line": 255,
"message": "Function 'luaL_len' is called without prior declaration",
"rule_id": "DCL31-C",
"severity": "Low",
"suggestion": "Declare the function before calling it or include the appropriate header"
},
{
"column": 20,
"file": "/home/brandon/toolchain/lua/lua.c",
"line": 258,
"message": "Signed integer negation '-i' may overflow (-INT_MIN)",
"rule_id": "INT32-C",
"severity": "High",
"suggestion": "Add check: if (value == INT_MIN) { /* handle error */ }"
},
{
"column": 46,
"file": "/home/brandon/toolchain/lua/lua.c",
"line": 264,
"message": "Pointer parameter 'argv' is not modified and should be declared const",
"rule_id": "DCL13-C",
"severity": "Low",
"suggestion": "Declare parameter as 'const <type> *argv'"
},
{
"column": 41,
"file": "/home/brandon/toolchain/lua/lua.c",
"line": 267,
"message": "Array subscript -1 is negative. Array indices must be non-negative (0 or greater).",
"rule_id": "ARR00-C",
"severity": "Medium",
"suggestion": "Array 'argv' requires a non-negative index. Negative indices access memory before the array."
},
{
"column": 30,
"file": "/home/brandon/toolchain/lua/lua.c",
"line": 293,
"message": "Pointer parameter 'argv' is not modified and should be declared const",
"rule_id": "DCL13-C",
"severity": "Low",
"suggestion": "Declare parameter as 'const <type> *argv'"
},
{
"column": 40,
"file": "/home/brandon/toolchain/lua/lua.c",
"line": 356,
"message": "Pointer parameter 'argv' is not modified and should be declared const",
"rule_id": "DCL13-C",
"severity": "Low",
"suggestion": "Declare parameter as 'const <type> *argv'"
},
{
"column": 18,
"file": "/home/brandon/toolchain/lua/lua.c",
"line": 360,
"message": "'argv' (signed/plain char) converted to larger integer type without cast to 'unsigned char' - may cause sign extension",
"rule_id": "STR34-C",
"severity": "Medium",
"suggestion": "Cast to 'unsigned char' before conversion to larger type"
},
{
"column": 22,
"file": "/home/brandon/toolchain/lua/lua.c",
"line": 394,
"message": "Function 'l_getenv' is called without prior declaration",
"rule_id": "DCL31-C",
"severity": "Low",
"suggestion": "Declare the function before calling it or include the appropriate header"
},
{
"column": 12,
"file": "/home/brandon/toolchain/lua/lua.c",
"line": 397,
"message": "Function 'l_getenv' is called without prior declaration",
"rule_id": "DCL31-C",
"severity": "Low",
"suggestion": "Declare the function before calling it or include the appropriate header"
},
{
"column": 1,
"file": "/home/brandon/toolchain/lua/lua.c",
"line": 478,
"message": "Shared variable 'l_readline' lacks proper synchronization (not volatile or atomic). This may cause visibility issues across threads.",
"rule_id": "CON03-C",
"severity": "Medium",
"suggestion": "Consider declaring the variable as 'volatile', using atomic types (atomic_int, etc.), or protecting access with mutexes"
},
{
"column": 1,
"file": "/home/brandon/toolchain/lua/lua.c",
"line": 482,
"message": "Shared variable 'l_addhist' lacks proper synchronization (not volatile or atomic). This may cause visibility issues across threads.",
"rule_id": "CON03-C",
"severity": "Medium",
"suggestion": "Consider declaring the variable as 'volatile', using atomic types (atomic_int, etc.), or protecting access with mutexes"
},
{
"column": 5,
"file": "/home/brandon/toolchain/lua/lua.c",
"line": 490,
"message": "Return value of 'fflush' ignored: 'fflush(stdout)' - Can return error indicator",
"rule_id": "ERR33-C",
"severity": "High",
"suggestion": "Check return value for errors"
},
{
"column": 12,
"file": "/home/brandon/toolchain/lua/lua.c",
"line": 491,
"message": "fgets() without truncation check. Input may be silently truncated.",
"rule_id": "FIO20-C",
"severity": "Medium",
"suggestion": "Check for newline character to detect truncation: if (strchr(buf, '\\n') == NULL) { /* handle truncation */ }"
},
{
"column": 5,
"file": "/home/brandon/toolchain/lua/lua.c",
"line": 505,
"message": "Freeing parameter 'line'. Memory should be freed at the same abstraction level where it was allocated.",
"rule_id": "MEM00-C",
"severity": "Medium",
"suggestion": "Return error code and let caller handle deallocation"
},
{
"column": 3,
"file": "/home/brandon/toolchain/lua/lua.c",
"line": 520,
"message": "File descriptor 'lib' opened with open() but never closed with close()",
"rule_id": "FIO42-C",
"severity": "High",
"suggestion": "Add close(lib) before function returns or program exits"
},
{
"column": 9,
"file": "/home/brandon/toolchain/lua/lua.c",
"line": 520,
"message": "Passing variable 'rllib' (from 'getenv()') to function 'dlopen()' which may modify it.",
"rule_id": "ENV30-C",
"severity": "Medium",
"suggestion": "Copy the return value to a local buffer before passing to functions that may modify it"
},
{
"column": 7,
"file": "/home/brandon/toolchain/lua/lua.c",
"line": 524,
"message": "Attempting to modify string literal through pointer 'name'",
"rule_id": "STR30-C",
"severity": "High",
"suggestion": "Use a modifiable array instead of a string literal"
},
{
"column": 7,
"file": "/home/brandon/toolchain/lua/lua.c",
"line": 524,
"message": "Pointer dereference '*name' (char type) assigned without cast to 'unsigned char' - may cause sign extension",
"rule_id": "STR34-C",
"severity": "Medium",
"suggestion": "Cast to 'unsigned char' before assignment to larger type"
},
{
"column": 7,
"file": "/home/brandon/toolchain/lua/lua.c",
"line": 524,
"message": "Pointer dereference '*name' (char type) assigned without cast to 'unsigned char' - may cause sign extension",
"rule_id": "STR34-C",
"severity": "Medium",
"suggestion": "Cast to 'unsigned char' before assignment to larger type"
},
{
"column": 9,
"file": "/home/brandon/toolchain/lua/lua.c",
"line": 578,
"message": "Variable 'lmsg' is used uninitialized",
"rule_id": "EXP33-C",
"severity": "High",
"suggestion": "Initialize 'lmsg' before use, e.g., at its declaration"
},
{
"column": 3,
"file": "/home/brandon/toolchain/lua/lua.c",
"line": 589,
"message": "Fixed-size buffer may be used with environment variable",
"rule_id": "ENV01-C",
"severity": "High",
"suggestion": "Use dynamic allocation based on strlen() of getenv() result"
},
{
"column": 36,
"file": "/home/brandon/toolchain/lua/lua.c",
"line": 612,
"message": "'retline' (signed/plain char) converted to larger integer type without cast to 'unsigned char' - may cause sign extension",
"rule_id": "STR34-C",
"severity": "Medium",
"suggestion": "Cast to 'unsigned char' before conversion to larger type"
},
{
"column": 52,
"file": "/home/brandon/toolchain/lua/lua.c",
"line": 612,
"message": "Passing potentially null pointer 'retline' to function",
"rule_id": "EXP34-C",
"severity": "High",
"suggestion": "Check if 'retline' is not NULL before passing to function"
},
{
"column": 52,
"file": "/home/brandon/toolchain/lua/lua.c",
"line": 612,
"message": "'retline' (signed/plain char) converted to larger integer type without cast to 'unsigned char' - may cause sign extension",
"rule_id": "STR34-C",
"severity": "Medium",
"suggestion": "Cast to 'unsigned char' before conversion to larger type"
},
{
"column": 1,
"file": "/home/brandon/toolchain/lua/lua.c",
"line": 638,
"message": "Non-void function may reach end without returning a value. Ensure all execution paths have explicit return statements.",
"rule_id": "MSC37-C",
"severity": "Medium",
"suggestion": "Add return statements to ensure all execution paths return a value"
},
{
"column": 38,
"file": "/home/brandon/toolchain/lua/lua.c",
"line": 643,
"message": "'line' (signed/plain char) converted to larger integer type without cast to 'unsigned char' - may cause sign extension",
"rule_id": "STR34-C",
"severity": "Medium",
"suggestion": "Cast to 'unsigned char' before conversion to larger type"
},
{
"column": 44,
"file": "/home/brandon/toolchain/lua/lua.c",
"line": 643,
"message": "Variable 'len' may be used uninitialized (not assigned on all paths)",
"rule_id": "EXP33-C",
"severity": "High",
"suggestion": "Initialize 'len' before use, e.g., at its declaration"
},
{
"column": 14,
"file": "/home/brandon/toolchain/lua/lua.c",
"line": 673,
"message": "Testing 'lua_gettop(L)' for equality with 1. Functions may return values > 1. Use '!= 0' for boolean-like tests.",
"rule_id": "EXP20-C",
"severity": "Medium",
"suggestion": "Consider using: lua_gettop(L) != 0"
},
{
"column": 1,
"file": "/home/brandon/toolchain/lua/lua.c",
"line": 698,
"message": "Function 'doREPL' performs compound operation on shared static variable 'progname' without synchronization",
"rule_id": "CON07-C",
"severity": "Medium",
"suggestion": "Use mutex locks (mtx_lock/mtx_unlock) or atomic operations to ensure atomicity"
},
{
"column": 3,
"file": "/home/brandon/toolchain/lua/lua.c",
"line": 711,
"message": "Local variable 'oldprogname' assigned to global/static variable 'progname' - creates dangling pointer",
"rule_id": "DCL30-C",
"severity": "High",
"suggestion": "Use static storage for local variable or copy data instead of assigning pointer"
},
{
"column": 3,
"file": "/home/brandon/toolchain/lua/lua.c",
"line": 711,
"message": "Stack pointer escape: local array/VLA assigned to global 'progname'",
"rule_id": "MEM30-C",
"severity": "Critical",
"suggestion": "Do not save pointers to stack-allocated memory in global variables."
},
{
"column": 26,
"file": "/home/brandon/toolchain/lua/lua.c",
"line": 735,
"message": "'argv' (signed/plain char) converted to larger integer type without cast to 'unsigned char' - may cause sign extension",
"rule_id": "STR34-C",
"severity": "Medium",
"suggestion": "Cast to 'unsigned char' before conversion to larger type"
},
{
"column": 17,
"file": "/home/brandon/toolchain/lua/lua.c",
"line": 736,
"message": "Variable 'script' is used uninitialized",
"rule_id": "EXP33-C",
"severity": "High",
"suggestion": "Initialize 'script' before use, e.g., at its declaration"
},
{
"column": 17,
"file": "/home/brandon/toolchain/lua/lua.c",
"line": 739,
"message": "Potential null pointer dereference in array access of variable 'argv'",
"rule_id": "EXP34-C",
"severity": "High",
"suggestion": "Check if 'argv' is not NULL before array access"
},
{
"column": 7,
"file": "/home/brandon/toolchain/lua/lua.c",
"line": 742,
"message": "Bitwise operator '&' used on signed operand 'args' of type 'int'. Use unsigned types for bitwise operations",
"rule_id": "INT13-C",
"severity": "Medium",
"suggestion": "Change 'args' to an unsigned type (e.g., 'unsigned int' instead of 'int')"
},
{
"column": 7,
"file": "/home/brandon/toolchain/lua/lua.c",
"line": 744,
"message": "Bitwise operator '&' used on signed operand 'args' of type 'int'. Use unsigned types for bitwise operations",
"rule_id": "INT13-C",
"severity": "Medium",
"suggestion": "Change 'args' to an unsigned type (e.g., 'unsigned int' instead of 'int')"
},
{
"column": 5,
"file": "/home/brandon/toolchain/lua/lua.c",
"line": 747,
"message": "Passing string literal to function 'lua_setfield' which may modify it",
"rule_id": "STR30-C",
"severity": "High",
"suggestion": "Use a modifiable array instead of a string literal"
},
{
"column": 7,
"file": "/home/brandon/toolchain/lua/lua.c",
"line": 763,
"message": "Bitwise operator '&' used on signed operand 'args' of type 'int'. Use unsigned types for bitwise operations",
"rule_id": "INT13-C",
"severity": "Medium",
"suggestion": "Change 'args' to an unsigned type (e.g., 'unsigned int' instead of 'int')"
},
{
"column": 28,
"file": "/home/brandon/toolchain/lua/lua.c",
"line": 765,
"message": "Bitwise operator '&' used on signed operand 'args' of type 'int'. Use unsigned types for bitwise operations",
"rule_id": "INT13-C",
"severity": "Medium",
"suggestion": "Change 'args' to an unsigned type (e.g., 'unsigned int' instead of 'int')"
},
{
"column": 1,
"file": "/home/brandon/toolchain/lua/lua.c",
"line": 777,
"message": "Function 'main' does not validate pointer parameter 'argv' before use",
"rule_id": "API00-C",
"severity": "Medium",
"suggestion": "Add validation check for 'argv' at the start of the function, e.g., 'if (!argv) { return error_code; }'"
}
]
}