]> granicus.if.org Git - php/commitdiff
Persistent mallocs can return NULL (on failure)
authorSara Golemon <pollita@php.net>
Wed, 21 Jul 2004 02:38:40 +0000 (02:38 +0000)
committerSara Golemon <pollita@php.net>
Wed, 21 Jul 2004 02:38:40 +0000 (02:38 +0000)
ext/bz2/bz2_filter.c
ext/zlib/zlib_filter.c

index 87990c78a152a42138b1427e19280915e905f91a..4227cc55d921f0d3ad37ad6a5b4a1765aa8f8a87 100644 (file)
@@ -38,7 +38,7 @@ typedef struct _php_bz2_filter_data {
 
 static void *php_bz2_alloc(void *opaque, int items, int size)
 {
-       return (void *)pemalloc(items * size, ((php_bz2_filter_data*)opaque)->persistent);
+       return (void *)safe_pemalloc(items, size, 0, ((php_bz2_filter_data*)opaque)->persistent);
 }
 
 static void php_bz2_free(void *opaque, void *address)
@@ -269,6 +269,10 @@ static php_stream_filter *php_bz2_filter_create(const char *filtername, zval *fi
 
        /* Create this filter */
        data = pecalloc(1, sizeof(php_bz2_filter_data), persistent);
+       if (!data) {
+               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed allocating %d bytes.", sizeof(php_bz2_filter_data));
+               return NULL;
+       }
 
        /* Circular reference */
        data->strm.opaque = (void *) data;
@@ -278,8 +282,19 @@ static php_stream_filter *php_bz2_filter_create(const char *filtername, zval *fi
        data->persistent = persistent;
        data->strm.avail_out = data->outbuf_len = data->inbuf_len = 2048;
        data->strm.next_in = data->inbuf = (char *) pemalloc(data->inbuf_len, persistent);
+       if (!data->inbuf) {
+               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed allocating %d bytes.", data->inbuf_len);
+               pefree(data, persistent);
+               return NULL;
+       }
        data->strm.avail_in = 0;
        data->strm.next_out = data->outbuf = (char *) pemalloc(data->outbuf_len, persistent);
+       if (!data->outbuf) {
+               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed allocating %d bytes.", data->outbuf_len);
+               pefree(data->inbuf, persistent);
+               pefree(data, persistent);
+               return NULL;
+       }
 
        if (strcasecmp(filtername, "bzip2.decompress") == 0) {
                int smallFootprint = 0;
index fea81649208a82a555b7aab21efd66963b3063a7..c73e10e877f55103ac0a0e82250a11560ee5f738 100644 (file)
@@ -39,7 +39,7 @@ typedef struct _php_zlib_filter_data {
 
 static voidpf php_zlib_alloc(voidpf opaque, uInt items, uInt size)
 {
-       return (voidpf)pemalloc(items * size, ((php_zlib_filter_data*)opaque)->persistent);
+       return (voidpf)safe_pemalloc(items, size, 0, ((php_zlib_filter_data*)opaque)->persistent);
 }
 
 static void php_zlib_free(voidpf opaque, voidpf address)
@@ -274,6 +274,10 @@ static php_stream_filter *php_zlib_filter_create(const char *filtername, zval *f
 
        /* Create this filter */
        data = pecalloc(1, sizeof(php_zlib_filter_data), persistent);
+       if (!data) {
+               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed allocating %d bytes.", data->inbuf_len);
+               return NULL;
+       }
 
        /* Circular reference */
        data->strm.opaque = (voidpf) data;
@@ -282,8 +286,20 @@ static php_stream_filter *php_zlib_filter_create(const char *filtername, zval *f
        data->strm.zfree = (free_func) php_zlib_free;
        data->strm.avail_out = data->outbuf_len = data->inbuf_len = 2048;
        data->strm.next_in = data->inbuf = (Bytef *) pemalloc(data->inbuf_len, persistent);
+       if (!data->inbuf) {
+               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed allocating %d bytes.", data->inbuf_len);
+               pefree(data, persistent);
+               return NULL;
+       }
        data->strm.avail_in = 0;
        data->strm.next_out = data->outbuf = (Bytef *) pemalloc(data->outbuf_len, persistent);
+       if (!data->outbuf) {
+               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed allocating %d bytes.", data->inbuf_len);
+               pefree(data->inbuf, persistent);
+               pefree(data, persistent);
+               return NULL;
+       }
+               
        data->strm.data_type = Z_ASCII;
 
        if (strcasecmp(filtername, "zlib.inflate") == 0) {