Commit Graph
68 Commits
Author SHA1 Message Date
Grant Murphy 3caf7c3154 Add test cases 2017-09-16 10:12:27 +10:00
Grant Murphy 6943f9e5e4 Major rework of codebase
- Get rid of 'core' and move CLI to cmd/gas directory
- Migrate (most) tests to use Ginkgo and testutils framework
- GAS now expects package to reside in $GOPATH
- GAS now can resolve dependencies for better type checking (if package
  on GOPATH)
- Simplified public API
2017-07-19 15:17:00 -06:00
Grant Murphy f4b705a864 Use glide to manage vendored dependencies 2017-05-09 21:59:12 -07:00
Grant Murphy 026fe4c534 Simplify analyzer and command line interface
The analyzer now only handles packages rather than one off files. This
simplifies the CLI functionality significantly.
2017-05-09 21:26:53 -07:00
Grant Murphy 65b18da711 Hack to address circular dependency in rulelist 2017-05-09 21:26:12 -07:00
Grant Murphy 5160048ba6 Move rule definitions into own file 2017-05-09 21:24:43 -07:00
Grant Murphy 50bbc53a34 Isolate import tracking functionality 2017-05-09 21:23:37 -07:00
Grant Murphy bf78d027a9 Restructure and introduce a standalone config 2017-04-28 14:46:26 -07:00
Grant Murphy cacf21f3c0 Restructure to focus on lib rather than cli 2017-04-26 08:08:46 -07:00
Grant Murphy 8df48f9769 Fix to reporting to use output formats 2017-04-25 17:57:12 -07:00
Grant Murphy 9b081744c9 Process via packages instead of files
Initial commit to change GAS to process packages rather than standalone
files. This is to address issues with type resolution for external
dependencies.

Uses golang.org/x/tools/go/loader to prepare analyzer input rather than
finding the individual files.
2017-04-25 16:01:28 -07:00
Grant Murphy 622440f167 Correct bad test cases and intermitent failure
The filelist test was non-deterministic and causing intermittent
failures due to ordering. This change will ensure that the file list
returns an ordered list of files in the String() method now.

Additionally there were a number of test cases that the sample code
was incorrect, or would not compile. These have also been corrected.
2017-03-15 08:47:40 -07:00
Grant Murphy 1c99e45d1c Fix recursive case on Windows platforms
Closes #117
2017-01-27 09:16:36 -08:00
Grant Murphy 3e9b66a91a Temporarily disable typechecker fatal error
It seems that the typechecker isn't considering the entire package
fileset in the current way that gas is processing projects. This leads
to cases where types that are defined in one file aren't known about
when gas is processing other files within that module.

A redesign is needed, this is a temporary fix to return to old
behaviour.

Related to #113
2017-01-14 15:21:55 -08:00
Grant Murphy 4099783722 Go 1.5 does not support width precision specifier 2017-01-14 14:39:22 -08:00
Grant Murphy 4b70300e15 Exclude vendor directory from go vet 2017-01-14 14:03:31 -08:00
Grant Murphy aaddac5e4b Add the zxcvbn library to vendor list 2017-01-14 13:48:53 -08:00
Grant Murphy 9bc02396e8 Introduce entropy checking of string
This will hopefully reduce the number of false positives when it comes
to hard coded credentials. The zxcvbn library is used to calculate the
entropy of the string. By default the first 16 characters are considered
as doing the entropy check for strings much longer than that introduces
a fairly significant performance hit.
2017-01-14 13:45:34 -08:00
Grant Murphy a7ec9ccc63 Backport test case for 1.5
Go 1.5 does not have a rand.Read function so need to adjust test
definitions accordingly.
2017-01-13 13:31:22 -08:00
Grant Murphy f9868aa8c8 Fix additional test case 2017-01-13 12:46:16 -08:00
Grant Murphy ab4867bc76 Fix test cases with invalid sample code 2017-01-13 12:40:49 -08:00
Grant Murphy d3f0a08f0d Report a failure and exit if type checking fails
Type checking failures were previously not reported and the file was
silently ignored. This change will report the error and halt further
processing.
2017-01-13 11:27:17 -08:00
Grant Murphy d1303fee0b Improve specitivity of error message for GenDecl 2017-01-11 10:12:11 -08:00
Grant Murphy 1e736c8838 Fix test case (invalid sample code) 2017-01-11 09:51:25 -08:00
Grant Murphy d1e67fc995 Ensure hardcoded credentials only examines strings
The hardcoded credentials test should only consider assignment of const strings.

Related to issue #108
2017-01-11 09:43:05 -08:00
Grant Murphy 94ac200d79 Tests broken if logger is not initialized 2016-12-02 15:39:01 -08:00
Grant Murphy 1ba8b93565 Reduce logging messages a tad
Only need to log if we're skipping a file or if we're processing it.
Should also use the [gas] prefix to aid filtering.
2016-12-02 15:34:12 -08:00
Grant Murphy 191750f44c Recreate fileset each time we process a file
Some files were being counted multiple times here and giving a skewed
result for line numbers processed.

Closes #100
2016-12-02 15:21:13 -08:00
Grant Murphy 6ace60b950 Address unhandled error conditions
Closes #95
2016-12-02 10:20:23 -08:00
Grant Murphy dcfd97c57d Remove ast.Print debug message from tryresolve 2016-12-01 09:24:58 -08:00
Grant Murphy 129be1561b Update error test case
There were several issues with the error test case that have been
addressed in this commit.

- It is possible to specify a whitelist of calls that error handling
  should be ignored for.
- Additional support for ast.ExprStmt for cases where the error is
  implicitly ignored.

There were several other additions to the helpers and call list in order
to support this type of functionality.

Fixes #54
2016-11-18 14:09:10 -08:00
Grant Murphy 5242a2c1df Extend helpers and call list
- Update call list to work directly with call expression
- Add call list test cases
- Extend helpers to add GetCallInfo to resolve call name and package or
  type if it's a var.
- Add test cases to ensure correct behaviour
2016-11-18 09:57:34 -08:00
Grant Murphy d29c64800e Add match call by type 2016-11-17 20:18:31 -08:00
Grant Murphy 63e8b1af23 Update unsafe rule to match package explicitly
Unsafe is not tracked in Package.Imports(), the regexp was not explicit
enough and foounsafe.Blah() would trigger an error.
2016-11-15 13:53:36 -08:00
Grant Murphy 39b18a1539 Remove debug print messages 2016-11-15 12:36:02 -08:00
Grant Murphy ca42de24ba Initialize fresh import info for each file
The import information was being persisted between files. This was
causing false positives.

Fixes #87
2016-11-15 11:58:28 -08:00
Grant Murphy c7bb2dd3b7 Fix additional crash condition
A var GenDecl may not have a value assigned. This error case must be
handled.
2016-11-14 15:15:17 -08:00
Grant Murphy 5012c34d48 Handle inbalanced declaration of constants
The following code would create a panic condition:

const foo, bar = "some thing"

Fixes #84
2016-11-14 13:57:55 -08:00
Grant Murphy a3fcd96f57 Update hardcoded credentials rule for GenDecls
The hardcoded credentials rule will now also examine GenDecls so will
work with global vars and constants.

Fixes #74
2016-11-13 12:57:59 -08:00
Grant Murphy bf103da519 Allow rules to register against multiple ast nodes
Update the AddRule interface to allow rules to register interest in
multiple ast.Nodes. Adds more flexibility to how rules can work, and was
needed to fix the hard coded credentials test specifically.
2016-11-13 12:55:31 -08:00
Grant Murphy 1d732b8ae3 Ensure os.OpenFile file permissions are checked
In addition configuration file may be used to set the permission level.

Closes #53
2016-11-12 17:57:20 -08:00
Grant Murphy 97dcc72a8b Incorrect rule mapping in rulelist 2016-11-08 08:48:45 -08:00
Grant Murphy be96ef273d Fix alias logic 2016-11-07 20:10:30 -08:00
Grant Murphy c833bfae02 Merge branch 'tam7t-rand-pkg-helper' 2016-11-07 20:04:40 -08:00
Grant Murphy e0db3f404a Merge branch 'rand-pkg-helper' of git://github.com/tam7t/gas into tam7t-rand-pkg-helper 2016-11-07 20:03:51 -08:00
Grant Murphy 20f2a98ce8 Ensure initialization only imports are ignored
Blacklisted imports should not report failures when a module is imported
for side-effects only using the blank identifier.

Closes #59
2016-11-07 09:28:37 -08:00
Grant Murphy 7a275fd0ad MatchCallByPackage updated to avoid GetCallObject
There seems to be an inconsistency in the way that the type.Info.Uses
map is populated by the type checker in Go 1.5 and the latest release.

It is possible to ascertain the package that relates to an object 1.7.x
release but this does not work for earlier Go versions.

To work around this limitation we now track imports, and monitor if they
are aliased or initalization only imports.
2016-11-07 09:13:20 -08:00
Grant Murphy b02c0fa2fc Add imports dumper 2016-11-06 12:15:32 -08:00
Grant Murphy 2c9d8fc461 Skip files if they don't exist 2016-11-06 12:04:52 -08:00
Grant Murphy d20506048f Update to dump specific context information
Added output printers for comments, types, defs, and uses maps.
2016-11-06 11:59:24 -08:00
Grant Murphy 14e6635ca6 Add tool to inspect call objects in file 2016-11-06 11:17:10 -08:00
Grant Murphy 0bc4d4808d Add an experimental way to whitelist calls
A call list is a way of grouping a number of packages and function calls
into a blacklist or whitelist. Could be useful to exclude certain
functions from results or looking for a specific set of functions.
2016-11-06 11:07:50 -08:00
Grant Murphy 0fef3ad40a Split out MatchCallByObject into two functions
Allows direct call to GetCallObject.
2016-11-04 14:39:22 -07:00
Grant Murphy f71ade6702 Update usage to indicate html is supported 2016-11-04 11:38:25 -07:00
Grant Murphy d72cee8663 Add quiet mode
When -quiet is specified on the command line we will only show issues
when issues were found.

Fixes #55
2016-11-04 11:38:00 -07:00
Grant Murphy c4057545ae Add MatchCall helper that utilizes type checker
This introduces a helper function that will significantly reduce the
number of false positives that occur due to the use of regexp based
call matching.

It resolves the object related to a CallExpr and checks that against the
supplied package and identifier name. If both of these match the
returned value is the CallExpr and Object.
2016-11-04 11:20:28 -07:00
Grant Murphy d60a2b4ebb Confirmed correct behavior for SQL tests
Closes #64
2016-11-02 17:46:59 -07:00
Grant Murphy 686927c894 Address go vet failure in SQL rule 2016-11-02 17:12:23 -07:00
Grant Murphy 344ebd1ab6 Add go vet to travis-ci 2016-11-02 17:03:24 -07:00
Grant Murphy 74b6633ee0 Updated imports to new repository location. 2016-11-02 16:54:20 -07:00
Grant Murphy b8ce40e193 Remove debugging println 2016-11-02 16:25:13 -07:00
Grant Murphy 59fbf7446d Refactor path matching logic
Effectively using filepath.Glob to build a set of files and directories
to exclude from the scan.

(ref: https://golang.org/pkg/path/filepath/#Glob)
2016-09-10 14:55:12 -07:00
Grant Murphy d05a2416a2 MatcMatchCompLit should be MatchCompList 2016-08-28 11:44:14 -07:00
Grant Murphy b5a98c12a8 Add godocs.org bagdge 2016-08-28 11:36:53 -07:00
Grant Murphy 9ca975d56f Add gas to .gitignore 2016-08-28 11:35:58 -07:00
Grant Murphy 0bce1770b5 Fix typos in godocs 2016-08-28 11:22:08 -07:00
Grant Murphy a2b7f3e0a2 Add LICENSE information to README.md 2016-08-28 11:09:52 -07:00
Grant Murphy 929edb490a Update README.md to use rule ID's 2016-08-28 11:07:28 -07:00