pi-hole / FTL

The Pi-hole FTL engine
https://pi-hole.net
Other
1.34k stars 187 forks source link

Fix use after free warning in FTLrealloc #1933

Closed williamvds closed 2 months ago

williamvds commented 2 months ago

What does this PR aim to accomplish?:

Fix -Wuse-after-free warning in FTLrealloc:

In file included from /home/william/scratch/public/FTL/src/syscalls/realloc.c:13:
/home/william/scratch/public/FTL/src/syscalls/realloc.c: In function ‘FTLrealloc’:
/home/william/scratch/public/FTL/src/syscalls/../log.h:30:27: error: pointer ‘ptr_in’ may be used after ‘realloc’ [-Werror=use-after-free]
   30 | #define logg(format, ...) _FTL_log(true, false, format, ## __VA_ARGS__)
      |                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/william/scratch/public/FTL/src/syscalls/realloc.c:42:17: note: in expansion of macro ‘logg’
   42 |                 logg("FATAL: Memory reallocation (%p -> %zu) failed in %s() (%s:%i)",
      |                 ^~~~
/home/william/scratch/public/FTL/src/syscalls/realloc.c:31:27: note: call to ‘realloc’ here
   31 |                 ptr_out = realloc(ptr_in, size);
      |                           ^~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors

How does this PR accomplish the above?:

Remove the reference to the indeterminate pointer after the call to realloc. Increase the warning to -Wuse-after-free=3.

Link documentation PRs if any are needed to support this PR:


By submitting this pull request, I confirm the following:

  1. I have read and understood the contributors guide, as well as this entire template. I understand which branch to base my commits and Pull Requests against.
  2. I have commented my proposed changes within the code and I have tested my changes.
  3. I am willing to help maintain this change if there are issues with it later.
  4. It is compatible with the EUPL 1.2 license
  5. I have squashed any insignificant commits. (git rebase)
  6. I have checked that another pull request for this purpose does not exist.
  7. I have considered, and confirmed that this submission will be valuable to others.
  8. I accept that this submission may not be used, and the pull request closed at the will of the maintainer.
  9. I give this submission freely, and claim no ownership to its content.

DL6ER commented 2 months ago

Thank you for your submission! We are currently in the middle (actually: rather towards the end) of the public beta for Pi-hole v6.0. Please submit your PR against branch development-v6 instead.

williamvds commented 2 months ago

Thank you for your submission! We are currently in the middle (actually: rather towards the end) of the public beta for Pi-hole v6.0. Please submit your PR against branch development-v6 instead.

Aha, it seems the warning has already been resolved in the development branch in 44e7007378aca305612afa13511fbcf6c51a8135! No matter then, I can keep a patch until v6 is released, a backport would be too much hassle.

Thanks for your time!