diff options
author | Dmitry Stogov <dmitry@php.net> | 2007-11-22 13:27:13 +0000 |
---|---|---|
committer | Dmitry Stogov <dmitry@php.net> | 2007-11-22 13:27:13 +0000 |
commit | 648fbe9d5838073154f3737829d5298502184343 (patch) | |
tree | bd21fcbb0af89d62032a842dc4e6f29518fa3cdf /TSRM | |
parent | 1836daf7f9f3ab088a65fd8c0b8c9421d6550be5 (diff) | |
download | php-git-648fbe9d5838073154f3737829d5298502184343.tar.gz |
Fixed bug #43128 (Very long class name causes segfault)
Diffstat (limited to 'TSRM')
-rw-r--r-- | TSRM/tsrm_config_common.h | 12 | ||||
-rw-r--r-- | TSRM/tsrm_virtual_cwd.c | 5 |
2 files changed, 13 insertions, 4 deletions
diff --git a/TSRM/tsrm_config_common.h b/TSRM/tsrm_config_common.h index 0c6a2a183f..d2b9bfc994 100644 --- a/TSRM/tsrm_config_common.h +++ b/TSRM/tsrm_config_common.h @@ -52,9 +52,17 @@ char *alloca (); #endif #if (HAVE_ALLOCA || (defined (__GNUC__) && __GNUC__ >= 2)) -# define tsrm_do_alloca(p) alloca(p) -# define tsrm_free_alloca(p) +# define TSRM_ALLOCA_MAX_SIZE 4096 +# define TSRM_ALLOCA_FLAG(name) \ + int name; +# define tsrm_do_alloca_ex(size, limit, use_heap) \ + ((use_heap = ((size) > (limit))) ? malloc(size) : alloca(size)) +# define tsrm_do_alloca(size, use_heap) \ + tsrm_do_alloca_ex(size, TSRM_ALLOCA_MAX_SIZE, use_heap) +# define tsrm_free_alloca(p, use_heap) \ + do { if (use_heap) free(p); } while (0) #else +# define TSRM_ALLOCA_FLAG(name) # define tsrm_do_alloca(p) malloc(p) # define tsrm_free_alloca(p) free(p) #endif diff --git a/TSRM/tsrm_virtual_cwd.c b/TSRM/tsrm_virtual_cwd.c index e808f85b6e..d4654a7010 100644 --- a/TSRM/tsrm_virtual_cwd.c +++ b/TSRM/tsrm_virtual_cwd.c @@ -777,6 +777,7 @@ CWD_API int virtual_chdir_file(const char *path, int (*p_chdir)(const char *path int length = strlen(path); char *temp; int retval; + TSRM_ALLOCA_FLAG(use_heap) if (length == 0) { return 1; /* Can't cd to empty string */ @@ -793,14 +794,14 @@ CWD_API int virtual_chdir_file(const char *path, int (*p_chdir)(const char *path if (length == COPY_WHEN_ABSOLUTE(path) && IS_ABSOLUTE_PATH(path, length+1)) { /* Also use trailing slash if this is absolute */ length++; } - temp = (char *) tsrm_do_alloca(length+1); + temp = (char *) tsrm_do_alloca(length+1, use_heap); memcpy(temp, path, length); temp[length] = 0; #if VIRTUAL_CWD_DEBUG fprintf (stderr, "Changing directory to %s\n", temp); #endif retval = p_chdir(temp TSRMLS_CC); - tsrm_free_alloca(temp); + tsrm_free_alloca(temp, use_heap); return retval; } /* }}} */ |