appneta / tcpreplay

Pcap editing and replay tools for *NIX and Windows - Users please download source from
http://tcpreplay.appneta.com/wiki/installation.html#downloads
1.15k stars 268 forks source link

Fix recursive tcpedit cleanup #855

Closed GabrielGanne closed 1 month ago

GabrielGanne commented 1 month ago

Assume a single tcpedit struct and return the previously allocated context if called twice.

This fixes an issue with the Juniper Encapsulated Ethernet DLT plugin which has an exception in the way the plugins works with regard to the extra buffer in question: tcpreplay works with the assumption that there only ever is a single link layer plugin which is mostly true except here: Juniper has a special call to tcpedit_dlt_copy_decoder_state() which causes the ctx and subctx to share a reference to the decoded_extra buffer, and a double free.

Fixes: #813 #850

GabrielGanne commented 1 month ago

Hi, cpp-linter is failing with the following error:

src/tcpedit/plugins/dlt_plugins.c:21:10 [clang-diagnostic-error]: src/tcpedit/plugins/dlt_plugins.c#L21
'config.h' file not found

Is it possible this is some configuration issue ? The normal build works fine. BR

fklassen commented 1 month ago

Hi, cpp-linter is failing with the following error:

src/tcpedit/plugins/dlt_plugins.c:21:10 [clang-diagnostic-error]: src/tcpedit/plugins/dlt_plugins.c#L21
'config.h' file not found

Is it possible this is some configuration issue ? The normal build works fine. BR

In 4.5.0 I made it so that the linter never fails, but it will still put inline suggestions in the PR. If the code quality goes up, I can restore the CI failure.

fklassen commented 1 month ago

Thanks for the PR. Will merge to 4.5.0 now and then test before release.

fklassen commented 4 weeks ago

I had to re-open #813 and back out this change because this PR, when applied after fixes #711 and #851, introduced a memory leak.

GabrielGanne commented 3 weeks ago

I had to re-open #813 and back out this change because this PR, when applied after fixes #711 and #851, introduced a memory leak.

It seems I messed up. The assumption that there's a single tcpedit struct is probably wrong in some situations. Sorry about that. Did you find a correct fix in the end ? Do you want me to have another look sometime ?

fklassen commented 3 weeks ago

Not a problem. I much prefer getting help and becoming a tester than hunting down problems on my own. Your contributions are always welcome.