cron: Use reallocarray() to prevent integer overflow

Apply OpenBSD env.c,v 1.24 and 1.25, which replaces manual size
calculations with reallocarray() to prevent possible integer
overflow.

MFC after:	3 days
This commit is contained in:
Xin LI
2025-11-02 21:59:46 -08:00
parent 088ced14a6
commit 40d2161838
+2 -3
View File
@@ -55,7 +55,7 @@ env_copy(char **envp)
for (count = 0; envp[count] != NULL; count++) for (count = 0; envp[count] != NULL; count++)
; ;
p = (char **) malloc((count+1) * sizeof(char *)); /* 1 for the NULL */ p = (char **) reallocarray(NULL, count+1, sizeof(char *)); /* 1 for the NULL */
if (p == NULL) { if (p == NULL) {
errno = ENOMEM; errno = ENOMEM;
return NULL; return NULL;
@@ -112,8 +112,7 @@ env_set(char **envp, char *envstr)
* one, save our string over the old null pointer, and return resized * one, save our string over the old null pointer, and return resized
* array. * array.
*/ */
p = (char **) realloc((void *) envp, p = (char **) reallocarray(envp, count+1, sizeof(char *));
(unsigned) ((count+1) * sizeof(char *)));
if (p == NULL) { if (p == NULL) {
/* XXX env_free(envp); */ /* XXX env_free(envp); */
errno = ENOMEM; errno = ENOMEM;