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

codegen/helpers: fix name inference for oneof codegen #140

Merged
merged 2 commits into from
Jun 9, 2022

Conversation

willfindlay
Copy link
Contributor

@willfindlay willfindlay commented Jun 8, 2022

The approach we were using, converting the Oneof field type using
strcase.ToScreamingSnake() was fundamentally broken for types that include e.g. a number
immediately next to a letter in the type name.

For example, consider something like:

message FooEvent42 { /* ... */ }

oneof event {
    ProcessExec process_exec = 1;
    ProcessExit process_exit = 5;
    ProcessKprobe process_kprobe = 9;
    ProcessTracepoint process_tracepoint = 10;
    ProcessDns process_dns = 14;
    FooEvent42 foo_event42 = 15;

    Test test = 40000;
}

The name for the oneof according to our codegen would be wrong: FOO_EVENT_42 instead of
FOO_EVENT42. To fix this, we can just grab the name of the actual oneof field and apply
a simple strings.ToUpper() transformation to it. This then results in the correct name
FOO_EVENT42.

Signed-off-by: William Findlay [email protected]

The approach we were using, converting the Oneof field type using
strcase.ToScreamingSnake() was fundamentally broken for types that include e.g. a number
immediately next to a letter in the type name.

For example, consider something like:

message FooEvent42 { /* ... */ }

oneof event {
    ProcessExec process_exec = 1;
    ProcessExit process_exit = 5;
    ProcessKprobe process_kprobe = 9;
    ProcessTracepoint process_tracepoint = 10;
    ProcessDns process_dns = 14;
    FooEvent42 foo_event42 = 15;

    Test test = 40000;
}

The name for the oneof according to our codegen would be wrong: FOO_EVENT_42 instead of
FOO_EVENT42. To fix this, we can just grab the name of the actual oneof field and apply
a simple strings.ToUpper() transformation to it. This then results in the correct name
FOO_EVENT42.

Signed-off-by: William Findlay <[email protected]>
@willfindlay willfindlay requested a review from kevsecurity June 8, 2022 18:18
@willfindlay willfindlay requested a review from a team as a code owner June 8, 2022 18:18
This was producing false positives when including code snippets in patch messages.
For example, you can imagine a Go code snippet like:

    typedef foo struct {
        test Test
    }

Line 2 would produce a false positive due to the repetition of "test". Let's
remove this lint since it's mostly useless anyway.

Signed-off-by: William Findlay <[email protected]>
Copy link
Contributor

@kevsecurity kevsecurity left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@willfindlay willfindlay merged commit a91afb7 into main Jun 9, 2022
@willfindlay willfindlay deleted the pr/willfindlay/fix-helper-gen branch June 9, 2022 13:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants