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 /process.c | |
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>
Diffstat (limited to 'process.c')
-rw-r--r-- | process.c | 15 |
1 files changed, 14 insertions, 1 deletions
@@ -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 { |