Re: [ZEND-ENGINE-CVS] cvs: Zend / zend_alloc.c zend_alloc.h
| From: | Thies C. Arntzen | Date: | Mon, 19 Aug 2002 10:37:48 +0000 |
| Subject: | Re: [ZEND-ENGINE-CVS] cvs: Zend / zend_alloc.c zend_alloc.h | ||
| References: | 1 | Groups: | php.zend-engine.cvs |
| Request: | Send a blank email to php-zend-engine-cvs+get-333@lists.php.net to get a copy of this message | ||
On Sun, Aug 18, 2002 at 09:39:05PM -0000, Stefan Esser wrote:
> sesser Sun Aug 18 17:39:05 2002 EDT
>
> Modified files:
> /Zend zend_alloc.c zend_alloc.h
> Log:
> catch possible integer overflow in ecalloc.
wasn't ecalloc replaced with a macro for speed reasons by
sascha some time ago?
re,
tc
>
>
> Index: Zend/zend_alloc.c
> diff -u Zend/zend_alloc.c:1.104 Zend/zend_alloc.c:1.105
> --- Zend/zend_alloc.c:1.104 Thu Aug 8 04:40:49 2002
> +++ Zend/zend_alloc.c Sun Aug 18 17:39:05 2002
> @@ -237,6 +237,28 @@
> }
>
>
> +ZEND_API void *_ecalloc(size_t nmemb, size_t size ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC)
> +{
> + char *p;
> + size_t _size = nmemb * size;
> +
> + if (nmemb && (_size/nmemb!=size)) {
> + fprintf(stderr,"FATAL: ecalloc(): Unable to allocate %ld * %ld bytes\n", (long)
> nmemb, (long) size);
> +#if ZEND_DEBUG && HAVE_KILL && HAVE_GETPID
> + kill(getpid(), SIGSEGV);
> +#else
> + exit(1);
> +#endif
> + }
> +
> + p = (char *) _emalloc(_size ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC);
> + if (p) {
> + memset(p, 0, _size);
> + }
> +
> + return ((void *)p);
> +}
> +
>
> ZEND_API void *_erealloc(void *ptr, size_t size, int allow_failure ZEND_FILE_LINE_DC
> ZEND_FILE_LINE_ORIG_DC)
> {
> Index: Zend/zend_alloc.h
> diff -u Zend/zend_alloc.h:1.38 Zend/zend_alloc.h:1.39
> --- Zend/zend_alloc.h:1.38 Sat Jun 22 10:25:27 2002
> +++ Zend/zend_alloc.h Sun Aug 18 17:39:05 2002
> @@ -74,6 +74,7 @@
>
> ZEND_API void *_emalloc(size_t size ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC);
> ZEND_API void _efree(void *ptr ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC);
> +ZEND_API void *_ecalloc(size_t nmemb, size_t size ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC);
> ZEND_API void *_erealloc(void *ptr, size_t size, int allow_failure ZEND_FILE_LINE_DC
> ZEND_FILE_LINE_ORIG_DC);
> ZEND_API char *_estrdup(const char *s ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC);
> ZEND_API char *_estrndup(const char *s, unsigned int length ZEND_FILE_LINE_DC
> ZEND_FILE_LINE_ORIG_DC);
> @@ -81,7 +82,7 @@
> /* Standard wrapper macros */
> #define emalloc(size) _emalloc((size) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
> #define efree(ptr) _efree((ptr) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
> -#define ecalloc(nmemb, size) memset(_emalloc((nmemb)*(size) ZEND_FILE_LINE_CC
> ZEND_FILE_LINE_EMPTY_CC), 0, (nmemb)*(size))
> +#define ecalloc(nmemb, size) _ecalloc((nmemb), (size) ZEND_FILE_LINE_CC
> ZEND_FILE_LINE_EMPTY_CC)
> #define erealloc(ptr, size) _erealloc((ptr), (size), 0 ZEND_FILE_LINE_CC
> ZEND_FILE_LINE_EMPTY_CC)
> #define erealloc_recoverable(ptr, size) _erealloc((ptr), (size), 1 ZEND_FILE_LINE_CC
> ZEND_FILE_LINE_EMPTY_CC)
> #define estrdup(s) _estrdup((s) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
> @@ -90,7 +91,7 @@
> /* Relay wrapper macros */
> #define emalloc_rel(size) _emalloc((size) ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC)
> #define efree_rel(ptr) _efree((ptr) ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC)
> -#define ecalloc_rel(nmemb, size) memset(_emalloc((nmemb)*(size) ZEND_FILE_LINE_RELAY_CC
> ZEND_FILE_LINE_CC), 0, (nmemb)*(size))
> +#define ecalloc_rel(nmemb, size) _ecalloc((nmemb), (size) ZEND_FILE_LINE_RELAY_CC
> ZEND_FILE_LINE_CC)
> #define erealloc_rel(ptr, size) _erealloc((ptr), (size), 0 ZEND_FILE_LINE_RELAY_CC
> ZEND_FILE_LINE_CC)
> #define erealloc_recoverable_rel(ptr, size) _erealloc((ptr), (size), 1 ZEND_FILE_LINE_RELAY_CC
> ZEND_FILE_LINE_CC)
> #define estrdup_rel(s) _estrdup((s) ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC)
>
>
>
> --
> Zend Engine CVS Mailing List (http://cvs.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
--
Thies C. Arnzten - Looking for all sorts of freelance work - just ask..
Whishlist: http://www.amazon.de/exec/obidos/wishlist/AB9DY62QWDSZ