This was noticed while running a Coverity scan on the libunistring sources.
From 157da9e2421d3db15b9fa2f832d650b64818accc Mon Sep 17 00:00:00 2001 From: Stephen Gallagher <[email protected]> Date: Wed, 29 Feb 2012 08:05:09 -0500 Subject: [PATCH] Add NULL check for malloc() in two uninorm files
---
lib/uninorm/u-normalize-internal.h | 5 +++++
lib/uninorm/uninorm-filter.c | 5 +++++
2 files changed, 10 insertions(+), 0 deletions(-)
diff --git a/lib/uninorm/u-normalize-internal.h b/lib/uninorm/u-normalize-internal.h
index e21243fe5589c0ca87ce230f5ea049bb37224a07..955893c15fa9044f9eff2ea407504008d9e35eea 100644
--- a/lib/uninorm/u-normalize-internal.h
+++ b/lib/uninorm/u-normalize-internal.h
@@ -310,6 +310,11 @@ FUNC (uninorm_t nf, const UNIT *s, size_t n,
abort ();
new_sortbuf =
(struct ucs4_with_ccc *) malloc (2 * sortbuf_allocated * sizeof (struct ucs4_with_ccc));
+ if(new_sortbuf == NULL) {
+ errno = ENOMEM;
+ goto fail;
+ }
+
memcpy (new_sortbuf, sortbuf,
sortbuf_count * sizeof (struct ucs4_with_ccc));
if (sortbuf != sortbuf_preallocated)
diff --git a/lib/uninorm/uninorm-filter.c b/lib/uninorm/uninorm-filter.c
index 3d991cbf027b1cd4e589838d00865a5ff94905b9..2df1490281ada05bac1f0cf01ce3ef8883ea9920 100644
--- a/lib/uninorm/uninorm-filter.c
+++ b/lib/uninorm/uninorm-filter.c
@@ -241,6 +241,11 @@ uninorm_filter_write (struct uninorm_filter *filter, ucs4_t uc_arg)
new_sortbuf =
(struct ucs4_with_ccc *)
malloc (2 * filter->sortbuf_allocated * sizeof (struct ucs4_with_ccc));
+ if (new_sortbuf == NULL) {
+ errno = ENOMEM;
+ return -1;
+ }
+
memcpy (new_sortbuf, filter->sortbuf,
sortbuf_count * sizeof (struct ucs4_with_ccc));
if (filter->sortbuf != filter->sortbuf_preallocated)
--
1.7.7.6
signature.asc
Description: This is a digitally signed message part
