Skip to content

Commit

Permalink
Fix compilation on systems without a native strlcpy() function.
Browse files Browse the repository at this point in the history
  • Loading branch information
millert committed Jan 28, 2021
1 parent dceab7d commit 8ca47cc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 9 additions & 1 deletion plugins/sudoers/strvec_join.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,15 @@

#include "sudoers.h"

#ifdef HAVE_STRLCPY
# define cpy_default strlcpy
#else
# define cpy_default sudo_strlcpy
#endif

/*
* Join a NULL-terminated array of strings using the specified separator
* character. The copy function must have strlcpy-like semantics.
* char. If non-NULL, the copy function must have strlcpy-like semantics.
*/
char *
strvec_join(char *const argv[], char sep, size_t (*cpy)(char *, const char *, size_t))
Expand All @@ -48,6 +54,8 @@ strvec_join(char *const argv[], char sep, size_t (*cpy)(char *, const char *, si
debug_return_ptr(NULL);
}

if (cpy == NULL)
cpy = cpy_default;
for (dst = result, av = argv; *av != NULL; av++) {
n = cpy(dst, *av, size);
if (n >= size) {
Expand Down
2 changes: 1 addition & 1 deletion plugins/sudoers/sudoers.c
Original file line number Diff line number Diff line change
Expand Up @@ -960,7 +960,7 @@ set_cmnd(void)
*/
user_args = strvec_join(NewArgv + 1, ' ', strlcpy_unescape);
} else {
user_args = strvec_join(NewArgv + 1, ' ', strlcpy);
user_args = strvec_join(NewArgv + 1, ' ', NULL);
}
if (user_args == NULL)
debug_return_int(NOT_FOUND_ERROR);
Expand Down

0 comments on commit 8ca47cc

Please sign in to comment.