Page MenuHomePhabricator

[analyzer] CERT: STR32-C
Needs ReviewPublic

Authored by Charusso on Dec 4 2019, 2:20 PM.

Details

Reviewers
NoQ
Summary

This checker is implemented based on the following rule:
https://wiki.sei.cmu.edu/confluence/display/c/STR32-C.+Do+not+pass+a+non-null-terminated+character+sequence+to+a+library+function+that+expects+a+string

It warns on reading non-null-terminated strings. This warning is restricted to
the allocations which the Static Analyzer models with unix.Malloc checker.

Also warns on misusing the strncpy() function.

Diff Detail

Event Timeline

Charusso created this revision.Dec 4 2019, 2:20 PM
Charusso marked an inline comment as done.Dec 4 2019, 2:25 PM
Charusso added inline comments.
clang/lib/StaticAnalyzer/Checkers/cert/StrChecker.cpp
430

This is a huge assumption to make this checker as simple as possible. On each allocation I would store the memory regions which the size expression consists of. When we encounter a memory/string handler function call which has a size-expression parameter we could match whether the allocation considered the length of the string it will store.

May we will have a better idea, so I would leave that as it is, for now.

Examples generated by CodeChecker from the curl project:

Charusso updated this revision to Diff 232672.EditedDec 6 2019, 4:19 PM
Charusso edited the summary of this revision. (Show Details)
  • Add docs.
  • Move to alpha.
Charusso updated this revision to Diff 233904.EditedDec 13 2019, 6:47 PM
Charusso retitled this revision from [analyzer] CERT: StrChecker: 32.c to [analyzer] CERT: STR32-C.
  • Add notes to the initialization of char-arrays.
  • Mark the string null-terminated calling strcpy() with an appropriate size.

We need to add the interestingness to the NoteTags so that we only emit notes on initialization/function calls which leads to an error.

Charusso marked an inline comment as done.Dec 13 2019, 6:52 PM
Charusso added inline comments.
clang/lib/StaticAnalyzer/Checkers/cert/StrChecker.cpp
479

-1 line