sudo-project/sudo

Build failure with -std=gnu23 (GCC 15 default)

Closed this issue · 2 comments

When building with GCC trunk which now defaults to -std=gnu23, I get the following:

/bin/sh ../../libtool  --mode=compile x86_64-pc-linux-gnu-gcc -c -I../../include -I../.. -I. -I. -DLIBDIR=\"/usr/lib64\" -DLOCALEDIR=\"/usr/share/locale\" -D_PATH_SUDOERS=\"/etc/sudoers\" -D_PATH_CVTSUDOERS_CONF=\"/etc/cvtsudoers.conf\" -DSUDOERS_UID=0 -DSUDOERS_GID=0 -DSUDOERS_MODE=0440 -DZLIB_CONST -march=native -O3 -pipe  -flto=jobserver -Warray-bounds -fdiagnostics-details -Wstringop-overread -Wstringop-overflow -Wstringop-truncation -fvisibility=hidden  -fPIE  ./policy.c
./policy.c:1361:44: error: initialization of 'int (*)(void)' from incompatible pointer type 'int (*)(const char *, const char *, int,  void *)' [-Wincompatible-pointer-types]
 1361 |     { SUDO_HOOK_VERSION, SUDO_HOOK_SETENV, sudoers_hook_setenv, NULL },
      |                                            ^~~~~~~~~~~~~~~~~~~
./policy.c:1361:44: note: (near initialization for 'sudoers_hooks[0].hook_fn')
./policy.c:1362:46: error: initialization of 'int (*)(void)' from incompatible pointer type 'int (*)(const char *, void *)' [-Wincompatible-pointer-types]
 1362 |     { SUDO_HOOK_VERSION, SUDO_HOOK_UNSETENV, sudoers_hook_unsetenv, NULL },
      |                                              ^~~~~~~~~~~~~~~~~~~~~
./policy.c:1362:46: note: (near initialization for 'sudoers_hooks[1].hook_fn')
./policy.c:1363:44: error: initialization of 'int (*)(void)' from incompatible pointer type 'int (*)(const char *, char **, void *)' [-Wincompatible-pointer-types]
 1363 |     { SUDO_HOOK_VERSION, SUDO_HOOK_GETENV, sudoers_hook_getenv, NULL },
      |                                            ^~~~~~~~~~~~~~~~~~~
./policy.c:1363:44: note: (near initialization for 'sudoers_hooks[2].hook_fn')
./policy.c:1364:44: error: initialization of 'int (*)(void)' from incompatible pointer type 'int (*)(char *, void *)' [-Wincompatible-pointer-types]
 1364 |     { SUDO_HOOK_VERSION, SUDO_HOOK_PUTENV, sudoers_hook_putenv, NULL },
      |                                            ^~~~~~~~~~~~~~~~~~~
./policy.c:1364:44: note: (near initialization for 'sudoers_hooks[3].hook_fn')

C23 removes unprototyped functions and foo() starts to mean foo(void).

include/sudo_plugin.h has:

#if defined(__GNUC__) && ((__GNUC__ == 4 && __GNUC_MINOR__ >= 4) || __GNUC__ > 4)
# pragma GCC diagnostic ignored "-Wstrict-prototypes"
#endif

which would've flagged this. It goes back to 4e44bd4.

9613ef9 works around this with casts. In the future the hook API may be dropped as it can't really function as intended with modern C libraries.