summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2020-05-10 11:46:16 -0700
committerAlan Coopersmith <alan.coopersmith@oracle.com>2020-05-10 11:47:33 -0700
commit4faf0f63f0563513252967a2da1c51de6f5f7b0c (patch)
tree45e16e50c1a03900f4984a3377c97a79ca551cfa
parentaf7a74e28b33c18c4cb90f0d25bdfd5dff2e29d3 (diff)
downloadxorg-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.ac2
-rw-r--r--process.c15
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)
diff --git a/process.c b/process.c
index b6e2591..7d2a9e7 100644
--- a/process.c
+++ b/process.c
@@ -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 {