Skip to content

Avoid overriding _FORTIFY_SOURCE if already set#455

Merged
ranisalt merged 2 commits intoranisalt:masterfrom
threema-ch:fix-fortify-source
Apr 24, 2025
Merged

Avoid overriding _FORTIFY_SOURCE if already set#455
ranisalt merged 2 commits intoranisalt:masterfrom
threema-ch:fix-fortify-source

Conversation

@threema-danilo
Copy link
Contributor

If the environment defines flags other than _FORTIFY_SOURCE=2 (e.g. on Arch Linux, which sets it to 3), compilation fails because the flag cannot be re-defined.

make: Entering directory '/tmp/node-argon2/build'
  CC(target) Release/obj.target/libargon2/argon2/src/opt.o
<command-line>: warning: "_FORTIFY_SOURCE" redefined
<command-line>: note: this is the location of the previous definition
  CC(target) Release/obj.target/libargon2/argon2/src/argon2.o
<command-line>: warning: "_FORTIFY_SOURCE" redefined
<command-line>: note: this is the location of the previous definition
  CC(target) Release/obj.target/libargon2/argon2/src/blake2/blake2b.o
<command-line>: warning: "_FORTIFY_SOURCE" redefined
<command-line>: note: this is the location of the previous definition
  CC(target) Release/obj.target/libargon2/argon2/src/core.o
<command-line>: warning: "_FORTIFY_SOURCE" redefined
<command-line>: note: this is the location of the previous definition
  CC(target) Release/obj.target/libargon2/argon2/src/encoding.o
<command-line>: warning: "_FORTIFY_SOURCE" redefined
<command-line>: note: this is the location of the previous definition
  CC(target) Release/obj.target/libargon2/argon2/src/thread.o
<command-line>: warning: "_FORTIFY_SOURCE" redefined
<command-line>: note: this is the location of the previous definition
rm -f Release/obj.target/argon2.a Release/obj.target/argon2.a.ar-file-list; mkdir -p `dirname Release/obj.target/argon2.a`
ar crs Release/obj.target/argon2.a @Release/obj.target/argon2.a.ar-file-list
  COPY Release/argon2.a
  CXX(target) Release/obj.target/argon2/argon2.o
<command-line>: error: "_FORTIFY_SOURCE" redefined [-Werror]
<command-line>: note: this is the location of the previous definition
cc1plus: all warnings being treated as errors
make: *** [argon2.target.mk:138: Release/obj.target/argon2/argon2.o] Error 1
make: Leaving directory '/tmp/node-argon2/build'

By only setting it conditionally, we can avoid this issue.

Fixes #454.

@threema-danilo threema-danilo force-pushed the fix-fortify-source branch 2 times, most recently from 0ef86b0 to 4bbdadc Compare April 24, 2025 09:30
@threema-danilo threema-danilo force-pushed the fix-fortify-source branch 3 times, most recently from 2b9a3f9 to 8332a8d Compare April 24, 2025 10:51
@threema-danilo
Copy link
Contributor Author

@ranisalt I confirmed that the regression test works as intended: https://github.com/ranisalt/node-argon2/actions/runs/14639636754/job/41078770309?pr=455

The fix (based on your suggestion with the Regex) is now pushed as well. I did a few tweaks, but so far it fails to run on Windows. I'll have to test this on an actual Windows build machine to find the correct incantation.

If the environment defines flags other than `_FORTIFY_SOURCE=2` (e.g. on
Arch Linux, which sets it to 3), compilation fails because the flag
cannot be re-defined.

```
make: Entering directory '/tmp/node-argon2/build'
  CC(target) Release/obj.target/libargon2/argon2/src/opt.o
<command-line>: warning: "_FORTIFY_SOURCE" redefined
<command-line>: note: this is the location of the previous definition
  CC(target) Release/obj.target/libargon2/argon2/src/argon2.o
<command-line>: warning: "_FORTIFY_SOURCE" redefined
<command-line>: note: this is the location of the previous definition
  CC(target) Release/obj.target/libargon2/argon2/src/blake2/blake2b.o
<command-line>: warning: "_FORTIFY_SOURCE" redefined
<command-line>: note: this is the location of the previous definition
  CC(target) Release/obj.target/libargon2/argon2/src/core.o
<command-line>: warning: "_FORTIFY_SOURCE" redefined
<command-line>: note: this is the location of the previous definition
  CC(target) Release/obj.target/libargon2/argon2/src/encoding.o
<command-line>: warning: "_FORTIFY_SOURCE" redefined
<command-line>: note: this is the location of the previous definition
  CC(target) Release/obj.target/libargon2/argon2/src/thread.o
<command-line>: warning: "_FORTIFY_SOURCE" redefined
<command-line>: note: this is the location of the previous definition
rm -f Release/obj.target/argon2.a Release/obj.target/argon2.a.ar-file-list; mkdir -p `dirname Release/obj.target/argon2.a`
ar crs Release/obj.target/argon2.a @Release/obj.target/argon2.a.ar-file-list
  COPY Release/argon2.a
  CXX(target) Release/obj.target/argon2/argon2.o
<command-line>: error: "_FORTIFY_SOURCE" redefined [-Werror]
<command-line>: note: this is the location of the previous definition
cc1plus: all warnings being treated as errors
make: *** [argon2.target.mk:138: Release/obj.target/argon2/argon2.o] Error 1
make: Leaving directory '/tmp/node-argon2/build'
```

By only setting it conditionally, we can avoid this issue.
@threema-danilo
Copy link
Contributor Author

Finally! Finding a string that works equally on Posix and Windows was quite tough. I had to remove the dollar template strings, because the dollar would get interpreted as a variable by bash when enclosed with double quotes, but single quotes aren't supported by Windows. The final solution is a bit less nice, but seems to work.

The two remaining checks are due to permission errors, and no merge blockers, from what I can tell.

@ranisalt
Copy link
Owner

Thanks!

Finding a string that works equally on Posix and Windows was quite tough

That's never simple 😆

@ranisalt ranisalt merged commit 94de8e2 into ranisalt:master Apr 24, 2025
34 of 36 checks passed
@threema-danilo threema-danilo deleted the fix-fortify-source branch April 24, 2025 11:37
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 this pull request may close these issues.

Cannot compile with _FORTIFY_SOURCE=3 in CPPFLAGS

2 participants