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

Compiler warnings with binary wrappers #70

Closed
rezib opened this issue Mar 10, 2023 · 3 comments
Closed

Compiler warnings with binary wrappers #70

rezib opened this issue Mar 10, 2023 · 3 comments
Assignees
Labels
bug Something isn't working good first issue Good for newcomers
Milestone

Comments

@rezib
Copy link
Contributor

rezib commented Mar 10, 2023

The compiler raises warning when builder the binary wrappers, for example during build on fedora 37:

…
gcc -O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1  -m64  -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -o u-nspawn u-nspawn.c
u-nspawn.c: In function 'main':
u-nspawn.c:38:9: warning: ignoring return value of 'setuid' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |         setuid(0);
      |         ^~~~~~~~~
u-nspawn.c:39:9: warning: ignoring return value of 'setgid' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |         setgid(0);
      |         ^~~~~~~~~
sed -e 's|#BIN#|/usr/bin/mkosi|' u-bin.c.in > u-mkosi.c
gcc -O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1  -m64  -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -o u-mkosi u-mkosi.c
u-mkosi.c: In function 'main':
u-mkosi.c:38:9: warning: ignoring return value of 'setuid' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |         setuid(0);
      |         ^~~~~~~~~
u-mkosi.c:39:9: warning: ignoring return value of 'setgid' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |         setgid(0);
      |         ^~~~~~~~~
make: Leaving directory '/builddir/build/BUILD/fatbuildr_1.0.1~rc11/lib/wrappers'

This should be fixed.

@rezib rezib added bug Something isn't working good first issue Good for newcomers labels Mar 10, 2023
@Vedant-code
Copy link

To fix the issue, you should check the return value of 'setuid' and 'setgid' and handle any errors appropriately.
If you don't care about the return value, you can cast it to (void) to explicitly indicate that you are intentionally ignoring the return value:

(void)setuid(0);
(void)setgid(0);

@rezib
Copy link
Contributor Author

rezib commented Mar 10, 2023

To fix the issue, you should check the return value of 'setuid' and 'setgid' and handle any errors appropriately. If you don't care about the return value, you can cast it to (void) to explicitly indicate that you are intentionally ignoring the return value:

(void)setuid(0);
(void)setgid(0);

Thank you @Vedant-code for the suggestion!

@Vedant-code
Copy link

Vedant-code commented Mar 11, 2023 via email

@rezib rezib added this to the v2.0.0 milestone Mar 18, 2023
@rezib rezib self-assigned this May 2, 2023
@rezib rezib closed this as completed in a22b3b3 May 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants