aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/compat_stringlist.c
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2015-05-20 23:00:43 +0000
committerIngo Schwarze <schwarze@openbsd.org>2015-05-20 23:00:43 +0000
commite6a1cb605f731f0f6868bd9e5f991a0766db0ccc (patch)
tree139599d70f1eacde9833aec487c5dfd0cd5549d8 /compat_stringlist.c
parent0595eb95660c29a4e6dfdbf7b1e9641b3ab7b7ff (diff)
downloadmandoc-e6a1cb605f731f0f6868bd9e5f991a0766db0ccc.tar.gz
mandoc-e6a1cb605f731f0f6868bd9e5f991a0766db0ccc.tar.zst
mandoc-e6a1cb605f731f0f6868bd9e5f991a0766db0ccc.zip
fix integer overflows by using reallocarray(3)
Diffstat (limited to 'compat_stringlist.c')
-rw-r--r--compat_stringlist.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/compat_stringlist.c b/compat_stringlist.c
index 2b26e200..05b62d38 100644
--- a/compat_stringlist.c
+++ b/compat_stringlist.c
@@ -1,4 +1,4 @@
-/* $Id: compat_stringlist.c,v 1.2 2015/05/20 22:22:59 schwarze Exp $ */
+/* $Id: compat_stringlist.c,v 1.3 2015/05/20 23:00:43 schwarze Exp $ */
/*
* Copyright (c) 1994 Christos Zoulas <christos@netbsd.org>
* All rights reserved.
@@ -48,7 +48,7 @@ sl_init(void)
sl->sl_cur = 0;
sl->sl_max = _SL_CHUNKSIZE;
- sl->sl_str = malloc(sl->sl_max * sizeof(char *));
+ sl->sl_str = reallocarray(NULL, sl->sl_max, sizeof(char *));
if (sl->sl_str == NULL)
err(1, "stringlist");
return sl;
@@ -63,7 +63,8 @@ sl_add(StringList *sl, char *name)
{
if (sl->sl_cur == sl->sl_max - 1) {
sl->sl_max += _SL_CHUNKSIZE;
- sl->sl_str = reallocf(sl->sl_str, sl->sl_max * sizeof(char *));
+ sl->sl_str = reallocarray(sl->sl_str,
+ sl->sl_max, sizeof(char *));
if (sl->sl_str == NULL)
return (-1);
}