Skip to content

Commit 9613ef9

Browse files
committed
Cast hook functions to sudo_hook_fn_t to fix C23 compile error.
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.
1 parent 4c99e29 commit 9613ef9

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

include/sudo_plugin.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,11 @@ typedef int (*sudo_printf_t)(int msg_type, const char * restrict fmt, ...);
9696
#endif
9797

9898
/* Hook functions typedefs. */
99+
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 202311L)
100+
typedef int (*sudo_hook_fn_t)(...);
101+
#else
99102
typedef int (*sudo_hook_fn_t)();
103+
#endif
100104
typedef int (*sudo_hook_fn_setenv_t)(const char *name, const char *value, int overwrite, void *closure);
101105
typedef int (*sudo_hook_fn_putenv_t)(char *string, void *closure);
102106
typedef int (*sudo_hook_fn_getenv_t)(const char *name, char **value, void *closure);

plugins/sudoers/policy.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1358,10 +1358,10 @@ sudoers_policy_version(int verbose)
13581358
}
13591359

13601360
static struct sudo_hook sudoers_hooks[] = {
1361-
{ SUDO_HOOK_VERSION, SUDO_HOOK_SETENV, sudoers_hook_setenv, NULL },
1362-
{ SUDO_HOOK_VERSION, SUDO_HOOK_UNSETENV, sudoers_hook_unsetenv, NULL },
1363-
{ SUDO_HOOK_VERSION, SUDO_HOOK_GETENV, sudoers_hook_getenv, NULL },
1364-
{ SUDO_HOOK_VERSION, SUDO_HOOK_PUTENV, sudoers_hook_putenv, NULL },
1361+
{ SUDO_HOOK_VERSION, SUDO_HOOK_SETENV, (sudo_hook_fn_t)sudoers_hook_setenv, NULL },
1362+
{ SUDO_HOOK_VERSION, SUDO_HOOK_UNSETENV, (sudo_hook_fn_t)sudoers_hook_unsetenv, NULL },
1363+
{ SUDO_HOOK_VERSION, SUDO_HOOK_GETENV, (sudo_hook_fn_t)sudoers_hook_getenv, NULL },
1364+
{ SUDO_HOOK_VERSION, SUDO_HOOK_PUTENV, (sudo_hook_fn_t)sudoers_hook_putenv, NULL },
13651365
{ 0, 0, NULL, NULL }
13661366
};
13671367

src/hooks.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ process_hooks_unsetenv(const char *name)
125125
/* Hook registration internals. */
126126
static int
127127
register_hook_internal(struct sudo_hook_list *head,
128-
int (*hook_fn)(), void *closure)
128+
sudo_hook_fn_t hook_fn, void *closure)
129129
{
130130
struct sudo_hook_entry *hook;
131131
debug_decl(register_hook_internal, SUDO_DEBUG_HOOKS);
@@ -185,7 +185,7 @@ register_hook(struct sudo_hook *hook)
185185
/* Hook deregistration internals. */
186186
static void
187187
deregister_hook_internal(struct sudo_hook_list *head,
188-
int (*hook_fn)(), void *closure)
188+
sudo_hook_fn_t hook_fn, void *closure)
189189
{
190190
struct sudo_hook_entry *hook, *prev = NULL;
191191
debug_decl(deregister_hook_internal, SUDO_DEBUG_HOOKS);

0 commit comments

Comments
 (0)