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

filter_modify: fix clean up function for cond/rule(#7368) #7378

Merged
merged 5 commits into from
May 14, 2023

Conversation

nokute78
Copy link
Collaborator

Fixes #7368

This patch is to

  • Add rule_free to release struct modify_rule
  • Check if valid pointer before releasing
  • Use flb_calloc to initialize members of struct
  • Add test code for Segv from simple wildcard #7368

Enter [N/A] in the box, if an item is not applicable to your change.

Testing
Before we can approve your change; please submit the following in a comment:

  • Example configuration file for the change
  • Debug log output from testing the change
  • Attached Valgrind output that shows no leaks or memory corruption was found

If this is a change to packaging of containers or native binaries then please confirm it works for all targets.

  • [N/A] Run local packaging test showing all targets (including any new ones) build.
  • [N/A] Set ok-package-test label to test for all targets (requires maintainer to do).

Documentation

  • [N/A] Documentation required for this feature

Backporting

  • Backport to latest stable release.

Configuration

[SERVICE]
    Flush      1
    Grace      2
    Log_Level  info

[INPUT]
    Name       dummy
    Dummy      {"r1":"someval"}
    Samples    1

[FILTER]
    Name                 modify
    Match                *
    Log_Level            debug
    Remove_wildcard      *s3

[OUTPUT]
    Name  stdout
    Match *

[OUTPUT]
    Name exit
    Match *

Debug/Valgrind output

$ valgrind --leak-check=full bin/flb-rt-filter_modify 
==34097== Memcheck, a memory error detector
==34097== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==34097== Using Valgrind-3.18.1 and LibVEX; rerun with -h for copyright info
==34097== Command: bin/flb-rt-filter_modify
==34097== 
Test op_set_append...                           [2023/05/13 08:13:56] [ info] [fluent bit] version=2.1.3, commit=4398840ed5, pid=34097
[2023/05/13 08:13:57] [ info] [storage] ver=1.2.0, type=memory, sync=normal, checksum=off, max_chunks_up=128
[2023/05/13 08:13:57] [ info] [cmetrics] version=0.6.1

(snip)

Test invalid_wildcard...                        [2023/05/13 08:15:10] [ info] [fluent bit] version=2.1.3, commit=4398840ed5, pid=34097
[2023/05/13 08:15:10] [ info] [storage] ver=1.2.0, type=memory, sync=normal, checksum=off, max_chunks_up=128
[2023/05/13 08:15:10] [ info] [cmetrics] version=0.6.1
[2023/05/13 08:15:10] [ info] [ctraces ] version=0.3.0
[2023/05/13 08:15:10] [ info] [input:lib:lib.0] initializing
[2023/05/13 08:15:10] [ info] [input:lib:lib.0] storage_strategy='memory' (memory only)
[2023/05/13 08:15:10] [error] [filter:modify:modify.0] Unable to create regex(key) from *s3
[2023/05/13 08:15:10] [error] Failed initialize filter modify.0
[2023/05/13 08:15:10] [error] [engine] filter initialization failed
[2023/05/13 08:15:10] [error] [lib] backend failed
[ OK ]
SUCCESS: All unit tests have passed.
==34097== 
==34097== HEAP SUMMARY:
==34097==     in use at exit: 0 bytes in 0 blocks
==34097==   total heap usage: 56,139 allocs, 56,139 frees, 28,221,757 bytes allocated
==34097== 
==34097== All heap blocks were freed -- no leaks are possible
==34097== 
==34097== For lists of detected and suppressed errors, rerun with: -s
==34097== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

Fluent Bit is licensed under Apache 2.0, by submitting this pull request I understand that this code will be released under the terms of that license.

nokute78 added 2 commits May 13, 2023 07:48
Signed-off-by: Takahiro Yamashita <nokute78@gmail.com>
Signed-off-by: Takahiro Yamashita <nokute78@gmail.com>
@nokute78 nokute78 temporarily deployed to pr May 12, 2023 23:17 — with GitHub Actions Inactive
@nokute78 nokute78 temporarily deployed to pr May 12, 2023 23:17 — with GitHub Actions Inactive
@nokute78 nokute78 temporarily deployed to pr May 12, 2023 23:17 — with GitHub Actions Inactive
@nokute78 nokute78 temporarily deployed to pr May 12, 2023 23:38 — with GitHub Actions Inactive
Copy link
Collaborator

@leonardo-albertovich leonardo-albertovich left a comment

Choose a reason for hiding this comment

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

In modify.c these setup exit paths seem to require this call teardown(ctx); :

  1. Line 313
  2. Line 332

Other than that and the comment I made in the code it looks good, thank you for taking the time to address this issue.

nokute78 added 2 commits May 13, 2023 09:35
Signed-off-by: Takahiro Yamashita <nokute78@gmail.com>
Signed-off-by: Takahiro Yamashita <nokute78@gmail.com>
@nokute78 nokute78 temporarily deployed to pr May 13, 2023 00:36 — with GitHub Actions Inactive
@nokute78
Copy link
Collaborator Author

I added missing teardown and remove unused variables from test code.

@nokute78 nokute78 temporarily deployed to pr May 13, 2023 00:36 — with GitHub Actions Inactive
@nokute78 nokute78 temporarily deployed to pr May 13, 2023 00:37 — with GitHub Actions Inactive
@nokute78 nokute78 temporarily deployed to pr May 13, 2023 00:58 — with GitHub Actions Inactive
Signed-off-by: Takahiro Yamashita <nokute78@gmail.com>
@nokute78 nokute78 temporarily deployed to pr May 13, 2023 23:04 — with GitHub Actions Inactive
@nokute78 nokute78 temporarily deployed to pr May 13, 2023 23:04 — with GitHub Actions Inactive
@nokute78 nokute78 temporarily deployed to pr May 13, 2023 23:05 — with GitHub Actions Inactive
@nokute78 nokute78 temporarily deployed to pr May 13, 2023 23:26 — with GitHub Actions Inactive
@leonardo-albertovich leonardo-albertovich merged commit 055704e into fluent:master May 14, 2023
@nokute78 nokute78 deleted the fix_7368 branch May 17, 2023 11:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Segv from simple wildcard
2 participants