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

Match the size of an array #59

Open
plowsec opened this issue May 20, 2022 · 3 comments
Open

Match the size of an array #59

plowsec opened this issue May 20, 2022 · 3 comments
Labels
enhancement New feature or request

Comments

@plowsec
Copy link

plowsec commented May 20, 2022

Hey, thanks for weggli, it's so awesome ;)

I ran into an issue and wanted to see if you had a solution for it:

Given this pattern:
weggli -u '{char $buf[$len];snprintf($buf, $len2,_);}' test.c

I expect the following lines to be matched:

char buffer[80];
snprintf(buffer, 256, "aaaaaaaa%s", somevar);

By minimalizing the pattern, I found that a pattern like $buf[$a] won't match char buffer[80]; but $buf[_] will. Am I doing something wrong?

@felixwilhelm
Copy link
Collaborator

Thanks for the feedback and the bug report :)

At the moment, variables ($foo) don't match on number literals so this is expected behavior.
I've been thinking about changing that, but I'm worried that this makes certain queries to noisy.
For example, memcpy(_,_,$x) currently only matches on identifiers in the size field, but not literals and often that's exactly what I want.

I'm currently thinking about the following change:
Extend the behavior of numeric variables $0 $1 $1337 to match on identifiers AND number literals. "Normal" variables would still behave as they currently do. This gives an easy way to opt-in to number matching, but adds additional magic to the query language.

Would that change work for your use case?

@felixwilhelm felixwilhelm added the enhancement New feature or request label Jun 3, 2022
@plowsec
Copy link
Author

plowsec commented Sep 5, 2022

Sorry for the late reply, yes that would absolutely work for me! I think we're willing to learn a bit of weggli-specific query language magic in order to find magic bugs :)

@0xdea
Copy link

0xdea commented Dec 2, 2023

That would be a very welcome enhancement to an already awesome tool.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants