Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Per-diagnostic annotation #130

Closed
DHowett opened this issue Jun 8, 2017 · 4 comments
Closed

Per-diagnostic annotation #130

DHowett opened this issue Jun 8, 2017 · 4 comments

Comments

@DHowett
Copy link

DHowett commented Jun 8, 2017

#nosec is an effective tool in making a codebase gas-clean, but it's not expressive enough. It disables every gas diagnostic (now and forever) but doesn't provide any auditable documentation to the annotated code.

Proposal

I propose per-diagnostic AST node annotations. Through gas adding support for disabling specific diagnostics on a set of AST nodes, annotated code becomes self-documenting. It also opens up the suppressed code to diagnostics gas may add in the future.

func a() {
    // gas(-G101, -G102)
    if x < y {
        // code that is not safe for G101, G102
        // code that may become a diagnostic error in a future version of gas
    }
}

NB: syntax not fleshed out; what would it mean to have gas(+G1, -G1, invalidchars)? Would we need to implement a custom parser? We could probably make the grammar simpler to avoid doing too much work here.

Prior Art

Clang, a popular C and C++ compiler, offers scoped diagnostic suppression on a per-diagnostic basis:

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wbitwise-op-parentheses"
    1 << 3 << 4 == 5 << 6; // no warning issued due to ignoring bitwise-op-parentheses
#pragma clang diagnostic pop

I believe Visual C++ and GCC offer similar.

@gcmurphy
Copy link
Member

I think this is a reasonable request. I'll put it on the backlog. Thanks for the suggestion.

@jonmcclintock
Copy link
Contributor

I've proposed an implementation in this pull request: #142

@gcmurphy
Copy link
Member

gcmurphy commented Jan 8, 2018

It might be interesting to re-use go's parser + ast to do this. e.g. using a subset of golang simple expressions. proof of concept idea here - https://play.golang.org/p/c1yfMxvTbrw

@ccojocar ccojocar changed the title [Feature Request] Per-diagnostic annotation Per-diagnostic annotation Sep 10, 2019
@ccojocar
Copy link
Member

This feature is now supported by tracking the suppressions https://github.com/securego/gosec#tracking-suppressions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants