diff options
author | Toomas Soome <tsoome@me.com> | 2019-06-22 09:27:52 +0300 |
---|---|---|
committer | Toomas Soome <tsoome@me.com> | 2019-06-27 23:14:19 +0300 |
commit | e1a5df12e67cd370138ad95c737fb5436fbb2131 (patch) | |
tree | ee9d4458d1a8c60f2618cce4a068c99fc4a47b19 | |
parent | 082e84855d5f07c088beac66080cad0b6e1dadc3 (diff) | |
download | illumos-joyent-e1a5df12e67cd370138ad95c737fb5436fbb2131.tar.gz |
11271 libprint: memset after calloc and possible NULL pointer dereference
Reviewed by: Gergő Doma <domag02@gmail.com>
Reviewed by: Norm Jacobs <naj@snapcon.com>
Approved by: Dan McDonald <danmcd@joyent.com>
-rw-r--r-- | usr/src/lib/print/libprint/common/list.c | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/usr/src/lib/print/libprint/common/list.c b/usr/src/lib/print/libprint/common/list.c index fd90e58130..56060f44ec 100644 --- a/usr/src/lib/print/libprint/common/list.c +++ b/usr/src/lib/print/libprint/common/list.c @@ -23,8 +23,6 @@ * Use is subject to license terms. */ -#pragma ident "%Z%%M% %I% %E% SMI" - /*LINTLIBRARY*/ #include <stdio.h> @@ -58,8 +56,8 @@ list_append(void **list, void *item) if (list == NULL) { list = (void **)calloc(_list_increment, sizeof (void *)); - (void) memset(list, NULL, (_list_increment * sizeof (void *))); - list[0] = item; + if (list != NULL) + list[0] = item; } else { int count; @@ -70,10 +68,9 @@ list_append(void **list, void *item) int new_size = (((count + 1) / _list_increment) + 1) * _list_increment; - new_list = (void **)calloc(new_size, - sizeof (void *)); - (void) memset(new_list, NULL, - (new_size * sizeof (void *))); + new_list = (void **)calloc(new_size, sizeof (void *)); + if (new_list == NULL) + return (NULL); for (count = 0; list[count] != NULL; count++) new_list[count] = list[count]; free(list); |