diff options
author | Bruno Haible <bruno@clisp.org> | 2012-03-12 13:15:48 +0100 |
---|---|---|
committer | Bruno Haible <bruno@clisp.org> | 2012-03-13 23:51:35 +0100 |
commit | 844a4da8483610b921cb017679848ceaf47a7b2e (patch) | |
tree | 7729b7a852a340bd9af7b04ffab8bc3a36a60f8a /lib | |
parent | 986b22b9a09720d3c13271c0d0cbc3ff5bf2ed2b (diff) | |
download | gnulib-844a4da8483610b921cb017679848ceaf47a7b2e.tar.gz |
uninorm: Don't crash in out-of-memory conditions.
* lib/uninorm/u-normalize-internal.h (FUNC): Handle malloc() failure
gracefully.
* lib/uninorm/uninorm-filter.c (uninorm_filter_write): Likewise.
Based on a report and patch by Stephen Gallagher <sgallagh@redhat.com>.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/uninorm/u-normalize-internal.h | 5 | ||||
-rw-r--r-- | lib/uninorm/uninorm-filter.c | 6 |
2 files changed, 11 insertions, 0 deletions
diff --git a/lib/uninorm/u-normalize-internal.h b/lib/uninorm/u-normalize-internal.h index e21243fe55..bb54b30045 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 3d991cbf02..e3b920539e 100644 --- a/lib/uninorm/uninorm-filter.c +++ b/lib/uninorm/uninorm-filter.c @@ -241,6 +241,12 @@ 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 is ENOMEM. */ + filter->sortbuf_count = sortbuf_count; + return -1; + } memcpy (new_sortbuf, filter->sortbuf, sortbuf_count * sizeof (struct ucs4_with_ccc)); if (filter->sortbuf != filter->sortbuf_preallocated) |