Add reallocarray() for those without it.

This commit is contained in:
Todd C. Miller
2015-05-14 10:13:18 -06:00
parent 0d418df037
commit 3595807f4e
5 changed files with 28 additions and 2 deletions

View File

@@ -556,6 +556,9 @@
/* Define to 1 if you have the `random' function. */
#undef HAVE_RANDOM
/* Define to 1 if you have the `reallocarray' function. */
#undef HAVE_REALLOCARRAY
/* Define to 1 if you have the `revoke' function. */
#undef HAVE_REVOKE

3
configure vendored
View File

@@ -2653,6 +2653,7 @@ as_fn_append ac_header_list " sys/stropts.h"
as_fn_append ac_header_list " sys/sysmacros.h"
as_fn_append ac_func_list " killpg"
as_fn_append ac_func_list " nl_langinfo"
as_fn_append ac_func_list " reallocarray"
as_fn_append ac_func_list " strftime"
as_fn_append ac_func_list " tzset"
as_fn_append ac_func_list " seteuid"
@@ -17921,6 +17922,8 @@ done
for ac_func in getgrouplist
do :
ac_fn_c_check_func "$LINENO" "getgrouplist" "ac_cv_func_getgrouplist"

View File

@@ -2395,7 +2395,7 @@ dnl
dnl Function checks
dnl
AC_FUNC_GETGROUPS
AC_CHECK_FUNCS_ONCE([killpg nl_langinfo strftime tzset])
AC_CHECK_FUNCS_ONCE([killpg nl_langinfo reallocarray strftime tzset])
AC_CHECK_FUNCS([getgrouplist], [], [
case "$host_os" in
aix*)

View File

@@ -368,7 +368,7 @@ __dso_public long long sudo_strtonum(const char *, long long, long long, const c
* All libc replacements are prefixed with "sudo_" to avoid namespace issues.
*/
struct timeval;
struct passwd;
struct timespec;
#ifndef HAVE_CLOSEFROM
@@ -479,5 +479,10 @@ __dso_public const char *sudo_getprogname(void);
# undef getprogname
# define getprogname() sudo_getprogname()
#endif /* HAVE_GETPROGNAME */
#ifndef HAVE_REALLOCARRAY
__dso_public void *sudo_reallocarray(void *ptr, size_t nmemb, size_t size);
# undef reallocarray
# define reallocarray(_a, _b, _c) sudo_reallocarray((_a), (_b), (_c))
#endif /* HAVE_REALLOCARRAY */
#endif /* _SUDO_COMPAT_H */

View File

@@ -48,6 +48,7 @@
#elif defined(HAVE_INTTYPES_H)
# include <inttypes.h>
#endif
#include <errno.h>
#include <limits.h>
#define DEFAULT_TEXT_DOMAIN "sudo"
@@ -257,3 +258,17 @@ sudo_evasprintf_v1(char **ret, const char *fmt, va_list args)
sudo_fatal_nodebug(NULL);
return len;
}
#ifndef HAVE_REALLOCARRAY
void *
sudo_reallocarray(void *ptr, size_t nmemb, size_t size)
{
if (nmemb > SIZE_MAX / size) {
errno = EOVERFLOW;
return NULL;
}
size *= nmemb;
return ptr ? realloc(ptr, size) : malloc(size);
}
#endif /* HAVE_REALLOCARRAY */