Skip to content

Commit

Permalink
Cast hook functions to sudo_hook_fn_t to fix C23 compile error.
Browse files Browse the repository at this point in the history
The sudo plugin API defines sudo_hook_fn_t as a function with
unspecified arguments.  This is no longer supported in C23 so use
a variadic function for sudo_hook_fn_t instead.  Moving to a union
may be a better long-term fix.  GitHub issue #420.
  • Loading branch information
millert committed Nov 16, 2024
1 parent 4c99e29 commit 9613ef9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
4 changes: 4 additions & 0 deletions include/sudo_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,11 @@ typedef int (*sudo_printf_t)(int msg_type, const char * restrict fmt, ...);
#endif

/* Hook functions typedefs. */
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 202311L)
typedef int (*sudo_hook_fn_t)(...);
#else
typedef int (*sudo_hook_fn_t)();
#endif
typedef int (*sudo_hook_fn_setenv_t)(const char *name, const char *value, int overwrite, void *closure);
typedef int (*sudo_hook_fn_putenv_t)(char *string, void *closure);
typedef int (*sudo_hook_fn_getenv_t)(const char *name, char **value, void *closure);
Expand Down
8 changes: 4 additions & 4 deletions plugins/sudoers/policy.c
Original file line number Diff line number Diff line change
Expand Up @@ -1358,10 +1358,10 @@ sudoers_policy_version(int verbose)
}

static struct sudo_hook sudoers_hooks[] = {
{ SUDO_HOOK_VERSION, SUDO_HOOK_SETENV, sudoers_hook_setenv, NULL },
{ SUDO_HOOK_VERSION, SUDO_HOOK_UNSETENV, sudoers_hook_unsetenv, NULL },
{ SUDO_HOOK_VERSION, SUDO_HOOK_GETENV, sudoers_hook_getenv, NULL },
{ SUDO_HOOK_VERSION, SUDO_HOOK_PUTENV, sudoers_hook_putenv, NULL },
{ SUDO_HOOK_VERSION, SUDO_HOOK_SETENV, (sudo_hook_fn_t)sudoers_hook_setenv, NULL },
{ SUDO_HOOK_VERSION, SUDO_HOOK_UNSETENV, (sudo_hook_fn_t)sudoers_hook_unsetenv, NULL },
{ SUDO_HOOK_VERSION, SUDO_HOOK_GETENV, (sudo_hook_fn_t)sudoers_hook_getenv, NULL },
{ SUDO_HOOK_VERSION, SUDO_HOOK_PUTENV, (sudo_hook_fn_t)sudoers_hook_putenv, NULL },
{ 0, 0, NULL, NULL }
};

Expand Down
4 changes: 2 additions & 2 deletions src/hooks.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ process_hooks_unsetenv(const char *name)
/* Hook registration internals. */
static int
register_hook_internal(struct sudo_hook_list *head,
int (*hook_fn)(), void *closure)
sudo_hook_fn_t hook_fn, void *closure)
{
struct sudo_hook_entry *hook;
debug_decl(register_hook_internal, SUDO_DEBUG_HOOKS);
Expand Down Expand Up @@ -185,7 +185,7 @@ register_hook(struct sudo_hook *hook)
/* Hook deregistration internals. */
static void
deregister_hook_internal(struct sudo_hook_list *head,
int (*hook_fn)(), void *closure)
sudo_hook_fn_t hook_fn, void *closure)
{
struct sudo_hook_entry *hook, *prev = NULL;
debug_decl(deregister_hook_internal, SUDO_DEBUG_HOOKS);
Expand Down

0 comments on commit 9613ef9

Please sign in to comment.