From bc939dce43b4abf1f59e639115749c010d5d49cb Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Tue, 13 Nov 2007 09:47:19 +0000 Subject: [PATCH] Fixed bug #43248 (backward compatibility break in realpath()) --- TSRM/tsrm_virtual_cwd.c | 29 +++++++++++++++------------ ext/standard/tests/file/bug43248.phpt | 8 ++++++++ 2 files changed, 24 insertions(+), 13 deletions(-) create mode 100755 ext/standard/tests/file/bug43248.phpt diff --git a/TSRM/tsrm_virtual_cwd.c b/TSRM/tsrm_virtual_cwd.c index adf5510d06..6918fe3b53 100644 --- a/TSRM/tsrm_virtual_cwd.c +++ b/TSRM/tsrm_virtual_cwd.c @@ -712,22 +712,25 @@ no_realpath: } ptr = tsrm_strtok_r(NULL, TOKENIZER_STRING, &tok); } -#if defined(TSRM_WIN32) || defined(NETWARE) - if (path[path_length-1] == '\\' || path[path_length-1] == '/') { -#else - if (path[path_length-1] == '/') { -#endif - state->cwd = (char*)realloc(state->cwd, state->cwd_length + 2); - state->cwd[state->cwd_length++] = DEFAULT_SLASH; - state->cwd[state->cwd_length] = 0; - } free(free_path); - if ((use_realpath == CWD_REALPATH) && ret) { - CWD_STATE_FREE(state); - *state = old_state; - return 1; + if (use_realpath == CWD_REALPATH) { + if (ret) { + CWD_STATE_FREE(state); + *state = old_state; + return 1; + } + } else { +#if defined(TSRM_WIN32) || defined(NETWARE) + if (path[path_length-1] == '\\' || path[path_length-1] == '/') { +#else + if (path[path_length-1] == '/') { +#endif + state->cwd = (char*)realloc(state->cwd, state->cwd_length + 2); + state->cwd[state->cwd_length++] = DEFAULT_SLASH; + state->cwd[state->cwd_length] = 0; + } } if (state->cwd_length == COPY_WHEN_ABSOLUTE(state->cwd)) { diff --git a/ext/standard/tests/file/bug43248.phpt b/ext/standard/tests/file/bug43248.phpt new file mode 100755 index 0000000000..a20e0e06c4 --- /dev/null +++ b/ext/standard/tests/file/bug43248.phpt @@ -0,0 +1,8 @@ +--TEST-- +Bug #43248 backward compatibility break in realpath() +--FILE-- + +--EXPECTF-- +%sfile -- 2.50.1