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

Build fails on -Werror=use-after-free on GCC 12.2.0 #198

Open
mmtj opened this issue Oct 23, 2022 · 1 comment · May be fixed by #199
Open

Build fails on -Werror=use-after-free on GCC 12.2.0 #198

mmtj opened this issue Oct 23, 2022 · 1 comment · May be fixed by #199

Comments

@mmtj
Copy link
Contributor

mmtj commented Oct 23, 2022

While trying to build test tools

$ mkdir build
$ cd build/
$ cmake ..
CMake Deprecation Warning at CMakeLists.txt:1 (cmake_minimum_required):
  Compatibility with CMake < 2.8.12 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value or use a ...<max> suffix to tell
  CMake that the project does not need compatibility with older versions.


-- The C compiler identification is GNU 12.2.0
-- The CXX compiler identification is GNU 12.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Deprecation Warning at src/CMakeLists.txt:1 (cmake_minimum_required):
  Compatibility with CMake < 2.8.12 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value or use a ...<max> suffix to tell
  CMake that the project does not need compatibility with older versions.


-- Configuring done
-- Generating done
-- Build files have been written to: /home/mmtj/devel/DAWN/build

I bumped into following error:

$ make
[  4%] Building C object src/CMakeFiles/dawn.dir/main.c.o
[  8%] Building C object src/CMakeFiles/dawn.dir/storage/datastorage.c.o
In file included from /home/mmtj/devel/DAWN/src/storage/datastorage.c:4:
/home/mmtj/devel/DAWN/src/storage/datastorage.c: In function ‘insert_macs_from_file’:
/home/mmtj/devel/DAWN/src/include/memory_utils.h:25:26: error: pointer ‘fp’ used after ‘fclose’ [-Werror=use-after-free]
   25 | #define dawn_unregmem(p) dawn_memory_unregister(DAWN_MEMUNREG, __FILE__, __LINE__, p)
      |                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/mmtj/devel/DAWN/src/storage/datastorage.c:1336:5: note: in expansion of macro ‘dawn_unregmem’
 1336 |     dawn_unregmem(fp);
      |     ^~~~~~~~~~~~~
/home/mmtj/devel/DAWN/src/storage/datastorage.c:1335:5: note: call to ‘fclose’ here
 1335 |     fclose(fp);
      |     ^~~~~~~~~~
At top level:
cc1: note: unrecognized command-line option ‘-Wno-unknown-warning-option’ may have been intended to silence earlier diagnostics
cc1: all warnings being treated as errors
make[2]: *** [src/CMakeFiles/dawn.dir/build.make:90: src/CMakeFiles/dawn.dir/storage/datastorage.c.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:102: src/CMakeFiles/dawn.dir/all] Error 2
make: *** [Makefile:136: all] Error 2

Looking into the src/storage/datastorage.c:1336, there indeed seems to be use-after-free:

void insert_macs_from_file() {
    FILE *fp;
    // more code in between...
    fclose(fp);
    dawn_unregmem(fp);
mmtj added a commit to mmtj/DAWN that referenced this issue Oct 23, 2022
@mmtj mmtj linked a pull request Oct 23, 2022 that will close this issue
mmtj added a commit to mmtj/DAWN that referenced this issue Oct 23, 2022
@mmtj
Copy link
Contributor Author

mmtj commented Oct 23, 2022

With change from #199, dawn + test tools seems to build fine on my machine.

mmtj added a commit to mmtj/DAWN that referenced this issue Oct 23, 2022
@mmtj mmtj changed the title Build fails on -Werror=use-after-free Build fails on -Werror=use-after-free on GCC 12.2.0 Oct 24, 2022
mmtj added a commit to mmtj/DAWN that referenced this issue Apr 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant