This is an archive of the discontinued LLVM Phabricator instance.

Add check for CERT ENV33-C
ClosedPublic

Authored by aaron.ballman on Feb 19 2016, 7:33 AM.

Details

Reviewers
alexfh
sbenza
Summary

This patch adds a check for the CERT secure coding rule: ENV33-C. Do not call system(). It flags any call expression that calls a system command processor (system(), popen(), _popen()).

https://www.securecoding.cert.org/confluence/pages/viewpage.action?pageId=2130132

Diff Detail

Event Timeline

aaron.ballman retitled this revision from to Add check for CERT ENV33-C.
aaron.ballman updated this object.
aaron.ballman added reviewers: alexfh, sbenza.
aaron.ballman added a subscriber: cfe-commits.
sbenza added inline comments.Feb 19 2016, 7:57 AM
clang-tidy/cert/CommandProcessorCheck.cpp
23

Should we check that it is calling ::system and not any function called system?

clang-tidy/cert/CommandProcessorCheck.h
20

typo: is can

aaron.ballman marked an inline comment as done.
aaron.ballman added inline comments.
clang-tidy/cert/CommandProcessorCheck.cpp
23

Hmm, that's not a bad idea. Same for popen and _popen().

clang-tidy/cert/CommandProcessorCheck.h
20

Good catch.

sbenza added inline comments.Feb 19 2016, 12:00 PM
clang-tidy/cert/CommandProcessorCheck.cpp
37

You could move this into the matcher.
It could use the brand new nullPointerConstant()

unless(callExpr(callee(functionDecl(hasName("::system"))),
       argumentCountIs(1), hasArgument(0, nullPointerConstant())))

Seems simpler.

Updated based on review feedback.

aaron.ballman marked 4 inline comments as done.Feb 22 2016, 7:17 AM
sbenza accepted this revision.Feb 22 2016, 7:40 AM
sbenza edited edge metadata.
This revision is now accepted and ready to land.Feb 22 2016, 7:40 AM
aaron.ballman closed this revision.Feb 22 2016, 8:06 AM

Thanks! I've commit in r261530.