diff options
author | Alan Coopersmith <alan.coopersmith@oracle.com> | 2020-05-10 11:46:16 -0700 |
---|---|---|
committer | Alan Coopersmith <alan.coopersmith@oracle.com> | 2020-05-10 11:47:33 -0700 |
commit | 4faf0f63f0563513252967a2da1c51de6f5f7b0c (patch) | |
tree | 45e16e50c1a03900f4984a3377c97a79ca551cfa | |
parent | af7a74e28b33c18c4cb90f0d25bdfd5dff2e29d3 (diff) | |
download | xorg-app-xauth-4faf0f63f0563513252967a2da1c51de6f5f7b0c.tar.gz |
Use reallocarray() when adding members to array in split_into_words()
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | process.c | 15 |
2 files changed, 15 insertions, 2 deletions
diff --git a/configure.ac b/configure.ac index c7ee0a5..7e518b9 100644 --- a/configure.ac +++ b/configure.ac @@ -42,7 +42,7 @@ XORG_DEFAULT_OPTIONS AC_CHECK_HEADERS([net/errno.h]) -AC_CHECK_FUNCS([strlcpy]) +AC_CHECK_FUNCS([reallocarray strlcpy]) # Checks for pkg-config packages PKG_CHECK_MODULES(XAUTH, x11 xau xext xmuu xproto >= 7.0.17) @@ -37,6 +37,7 @@ from The Open Group. #include "xauth.h" #include <ctype.h> #include <errno.h> +#include <stdint.h> #include <sys/stat.h> #ifndef WIN32 #include <sys/socket.h> @@ -251,6 +252,18 @@ skip_nonspace(register char *s) return s; } +#ifndef HAVE_REALLOCARRAY +static inline void * +reallocarray(void *optr, size_t nmemb, size_t size) +{ + if ((nmemb > 0) && (SIZE_MAX / nmemb < size)) { + errno = ENOMEM; + return NULL; + } + return realloc(optr, size * nmemb); +} +#endif + static const char ** split_into_words(char *src, int *argcp) /* argvify string */ { @@ -280,7 +293,7 @@ split_into_words(char *src, int *argcp) /* argvify string */ if (cur == total) { const char **new_argv; total += WORDSTOALLOC; - new_argv = realloc (argv, total * sizeof (char *)); + new_argv = reallocarray (argv, total, sizeof (char *)); if (new_argv != NULL) { argv = new_argv; } else { |