]> granicus.if.org Git - php/commitdiff
Fixed bug #43248 (backward compatibility break in realpath())
authorDmitry Stogov <dmitry@php.net>
Tue, 13 Nov 2007 09:47:19 +0000 (09:47 +0000)
committerDmitry Stogov <dmitry@php.net>
Tue, 13 Nov 2007 09:47:19 +0000 (09:47 +0000)
TSRM/tsrm_virtual_cwd.c
ext/standard/tests/file/bug43248.phpt [new file with mode: 0755]

index adf5510d067a7f3f7427dafa2a858011203d68d6..6918fe3b534336098a8e0e153872b74903a05fa2 100644 (file)
@@ -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 (executable)
index 0000000..a20e0e0
--- /dev/null
@@ -0,0 +1,8 @@
+--TEST--
+Bug #43248 backward compatibility break in realpath() 
+--FILE--
+<?php
+echo realpath(dirname(__FILE__) . '/../file/');
+?>
+--EXPECTF--
+%sfile