Mercurial > hg > octave-lyh > gnulib-hg
changeset 16692:fec1c580b58c
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>.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Mon, 12 Mar 2012 13:15:48 +0100 |
parents | fcfa472825d5 |
children | 55c4c6aa19f4 |
files | ChangeLog lib/uninorm/u-normalize-internal.h lib/uninorm/uninorm-filter.c |
diffstat | 3 files changed, 19 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2012-03-12 Bruno Haible <bruno@clisp.org> + + 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>. + 2012-03-13 Akim Demaille <akim@lrde.epita.fr> quote: fix syntax-check
--- a/lib/uninorm/u-normalize-internal.h +++ b/lib/uninorm/u-normalize-internal.h @@ -310,6 +310,11 @@ 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)
--- a/lib/uninorm/uninorm-filter.c +++ b/lib/uninorm/uninorm-filter.c @@ -241,6 +241,12 @@ 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)