- fix possible NULL deref

This commit is contained in:
Pierre Joye 2011-01-10 00:30:07 +00:00
parent eda798fd7a
commit 26bb38e68b

View file

@ -1874,6 +1874,9 @@ CWD_API char *tsrm_realpath(const char *path, char *real_path TSRMLS_DC) /* {{{
/* realpath("") returns CWD */ /* realpath("") returns CWD */
if (!*path) { if (!*path) {
new_state.cwd = (char*)malloc(1); new_state.cwd = (char*)malloc(1);
if (new_state.cwd == NULL) {
return NULL;
}
new_state.cwd[0] = '\0'; new_state.cwd[0] = '\0';
new_state.cwd_length = 0; new_state.cwd_length = 0;
if (VCWD_GETCWD(cwd, MAXPATHLEN)) { if (VCWD_GETCWD(cwd, MAXPATHLEN)) {
@ -1885,6 +1888,9 @@ CWD_API char *tsrm_realpath(const char *path, char *real_path TSRMLS_DC) /* {{{
new_state.cwd_length = strlen(cwd); new_state.cwd_length = strlen(cwd);
} else { } else {
new_state.cwd = (char*)malloc(1); new_state.cwd = (char*)malloc(1);
if (new_state.cwd == NULL) {
return NULL;
}
new_state.cwd[0] = '\0'; new_state.cwd[0] = '\0';
new_state.cwd_length = 0; new_state.cwd_length = 0;
} }