uninorm: Don't crash in out-of-memory conditions.
authorBruno Haible <bruno@clisp.org>
Mon, 12 Mar 2012 12:15:48 +0000 (13:15 +0100)
committerBruno Haible <bruno@clisp.org>
Tue, 13 Mar 2012 22:51:35 +0000 (23:51 +0100)
* 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>.

ChangeLog
lib/uninorm/u-normalize-internal.h
lib/uninorm/uninorm-filter.c

index 8250797..7d09cef 100644 (file)
--- 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
index e21243f..bb54b30 100644 (file)
@@ -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)
index 3d991cb..e3b9205 100644 (file)
@@ -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)