Conversation
|
Don't look at the merge yet, I'll change it |
There was a problem hiding this comment.
Thanks for the patch!
I left a number of comments, please take a look.
Also, please squash commits to a single one, update commit description (it is better to say that we change arg format, not algorithm, and add a long commit description). Add Fixes #13 at the end of commit message`. Changelog entry is also required.
| @@ -32,7 +32,7 @@ local function TestOneInput(buf) | |||
| parser.parse(decoder.decode(buf)) | |||
There was a problem hiding this comment.
BTW docs/api.md should be updated too.
At least this:
argsis a table with arguments: the process arguments to pass to the
fuzzer. Fieldcorpusspecifies a path to a directory with seed corpus, see a
list with other options in the [libFuzzer documentation][libfuzzer-options-url].
There was a problem hiding this comment.
Please describe passing arguments via command-line in documentation.
README.md
Outdated
| end | ||
|
|
||
| luzer.Fuzz(TestOneInput) | ||
| luzer.Fuzz(TestOneInput, nil, arg) |
There was a problem hiding this comment.
arg is added, but in a step 3 it is unused (no options are passed to a script).
e069f35 to
b877c49
Compare
|
Thanks for the review! |
b877c49 to
d1981f4
Compare
ligurio
left a comment
There was a problem hiding this comment.
Thanks for update!
I like your idea to keep a Lua table with options and merge it with CLI arguments.
Please see the comments inline.
| end | ||
|
|
||
| luzer.Fuzz(TestOneInput) | ||
| luzer.Fuzz(TestOneInput, nil, {}) |
There was a problem hiding this comment.
Line 330 in 0179547
At the moment, it is checked that the last argument is a table and if not, fuzzing ends with an error. Therefore, it is necessary to explicitly specify arguments 2 and 3.
There was a problem hiding this comment.
It is not clear why support of CLI arguments makes custom mutator and table with options mandatory for Fuzz function.
There was a problem hiding this comment.
The problem is that the code currently shown in the readme will not work at all. The fuzzing process will start only if all 3 arguments are passed to the function input. In this PR, the process of parsing input arguments has been changed, I decided to fix this too.
luzer/luzer.c
Outdated
| #define CUSTOM_MUTATOR_LIB "libcustom_mutator.so.1" | ||
| #define DEBUG_HOOK_FUNC "luzer_custom_hook" | ||
|
|
||
| #define ENV_NOT_USE_CLI_ARGS "LUZER_NOT_USE_CLI_ARGS_FOR_LF" |
There was a problem hiding this comment.
According to changelog, option allows discarding arguments specified in command line.
What is the point? Just don't pass these options, and that's all. Or I didn't get your usecase.
From my point of view, it is more sense to introduce an option that will allow ignoring libfuzzer options specified in Lua.
There was a problem hiding this comment.
This is necessary so that if we fuzz functionality that works with command line arguments, there may be problems if the flags are the same.
For example:
local function TestOneInput(buf)
local fdp = luzer.FuzzedDataProvider(buf)
local str = fdp:consume_string(4)
local b = {}
str:gsub(".", function(c) table.insert(b, c) end)
if (b[1] == "o" and #arg > 0 and arg[1] == "-help=1") then assert(nil) end
endif we need to set the "-help=1" flag, then without this environment variable, the fuzzer will simply launch its help and fuzzing will not even start, but with the variable set, this crash will be found.
luzer/luzer.c
Outdated
| if (result < 0) | ||
| luaL_error(L, "failed to parse arguments from lua"); |
There was a problem hiding this comment.
According to implementation get_args_from_lua never returns non-zero exit code. It is a Lua C function and we raise lua_error inside it.
There was a problem hiding this comment.
Add descriptions for luaL_get_args_from_cli and luaL_get_args_from_table with possible return codes.
luzer/luzer.c
Outdated
| if (result < 0) | ||
| luaL_error(L, "failed to merge arguments"); |
There was a problem hiding this comment.
Message "failed to merge arguments" says nothing to user. It is not clear what a problem is happened and what is "merging arguments" at all. Probably it is better to return an error code for each type of error and use this code here. Currently, we return non-zero code in merge_args in case of lack of memory.
luzer/luzer.c
Outdated
| if (result < 0) | ||
| luaL_error(L, "failed to parse arguments from console"); |
There was a problem hiding this comment.
same comment as for get_args_from_lua
d1981f4 to
a0e1cc8
Compare
|
Corrected the PR according to your comments |
luzer/luzer_args.c
Outdated
| char search_flag[strlen(key) + 3]; | ||
| snprintf(search_flag, strlen(key) + 3, "-%s=", key); |
There was a problem hiding this comment.
Please define a var for strlen(key) + 3 and use it in array definition and for snprintf.
luzer/luzer_args.c
Outdated
| char search_flag[strlen(key) + 3]; | ||
| snprintf(search_flag, strlen(key) + 3, "-%s=", key); | ||
| for (int i = 0; i <= f_args->argc; i++) { | ||
| if (strncmp(f_args->argv[i], search_flag, strlen(search_flag)) == 0) |
There was a problem hiding this comment.
strlen(search_flag) is known, replace with variable (see a previous comment)
luzer/luzer_args.c
Outdated
| if (!arg) | ||
| return -1; | ||
|
|
||
| if (key > 0 && (not_use_cli_args == NULL || !strncmp(not_use_cli_args, "0", 1))) { |
There was a problem hiding this comment.
getenv(3):
The getenv() function returns a pointer to the value in the environment, or NULL if there is no match.
so comparing not_use_cli_args with NULL is enough
Do not use console arguments when LUZER_NOT_USE_CLI_ARGS_FOR_LF is set (even when equal to 0) and use console arguments when LUZER_NOT_USE_CLI_ARGS_FOR_LF is not set.
a0e1cc8 to
1643bce
Compare
|
@ligurio Wait for your response. |
Sure, I'll take a look. |
ligurio
left a comment
There was a problem hiding this comment.
Thanks for fixes!
The patch looks good, need some polishing. Please resolve comments that I left.
| end | ||
|
|
||
| luzer.Fuzz(TestOneInput) | ||
| luzer.Fuzz(TestOneInput, nil, {}) |
There was a problem hiding this comment.
It is not clear why support of CLI arguments makes custom mutator and table with options mandatory for Fuzz function.
d10c7b5 to
746ace8
Compare
…ents for libfuzzer Fixes ligurio#13
746ace8 to
e6a2372
Compare
|
@ligurio Thanks for the review. I fixed everything |
ligurio
left a comment
There was a problem hiding this comment.
Thanks for fixes! We are close to finish, but need a little more work.
Please take a look on comments.
| @@ -0,0 +1,284 @@ | |||
| /* | |||
| @@ -32,7 +32,7 @@ local function TestOneInput(buf) | |||
| parser.parse(decoder.decode(buf)) | |||
| const int key = lua_tointeger(L, -2); | ||
| lua_pop(L, 1); | ||
|
|
||
| if (key < 0) { |
There was a problem hiding this comment.
Add comment here with explanation
luzer/luzer.c
Outdated
| if (result < 0) | ||
| luaL_error(L, "failed to parse arguments from lua"); |
There was a problem hiding this comment.
Add descriptions for luaL_get_args_from_cli and luaL_get_args_from_table with possible return codes.
| #include "luzer_args.h" | ||
| #include "macros.h" | ||
|
|
||
| #define ENV_NOT_USE_CLI_ARGS "LUZER_NOT_USE_CLI_ARGS" |
There was a problem hiding this comment.
I would rename ENV_NOT_USE_CLI_ARGS to IGNORE_CLI_ARGS and the same for env variable name: LUZER_NOT_USE_CLI_ARGS -> LUZER_IGNORE_CLI_ARGS.
| #define FLAG_SCANF_FORMAT_KEY "-%[^=]" | ||
| #define FLAG_PATTERN_KEY "-%s=" | ||
| #define FLAG_PATTERN_KEY_VALUE "-%s=%s" | ||
| #define FLAG_PATTERN_OVERHEAD 2 |
There was a problem hiding this comment.
Used only once in a line below, I would drop it.
| NO_SANITIZE static bool | ||
| is_flag_in_args(luzer_args *f_args, const char *key) { | ||
| if (!f_args || !f_args->argv || f_args->argc <= 1) { | ||
| return false; |
There was a problem hiding this comment.
Why functions below returns int and here you are using bool?
There was a problem hiding this comment.
Do you mean to change return type to int? With return 0/1?
| total_args->argv[0] = cli_args->argv[0]; | ||
|
|
||
| char *corpus_path = NULL; | ||
| for (int i = 0; i < table_args->argc; i++) { |
There was a problem hiding this comment.
Probably it is better to put table_args->argv[i] to a separate variable (for example cur_arg) at the beginning of loop iteration. This change will reduce length of lines a bit. Currently, it is difficult to read lines in a loop body.
| luzer_args table_args = { .argv = NULL, .argc = 0 }; | ||
|
|
||
| int result = -1; | ||
| result = luaL_get_args_from_cli(L, &cli_args); |
There was a problem hiding this comment.
It is not a self-explained variable name. I propose to rename to something like retcode, rc or something else.
|
Superseded by #21. |


I changed the flag formatting algorithm for libfuzzer
2 problems were solved:
Now flags (and corpus directories) for libfuzzer can be added from console.
For example:
lua example_basic.lua -max_total_time=60 -only_ascii=1lua example_basic.lua ./corpus/But now for
luzer.Fuzz()function as third arguments need use global tablearg.If you need to add flags from a Lua script, you can use the construction:
Perhaps there is a better and easier way :)