]> granicus.if.org Git - php/commitdiff
- prevent bad things to happen when invalid path are passed to MoveFileEx
authorPierre Joye <pajoye@php.net>
Wed, 27 Jan 2010 01:18:43 +0000 (01:18 +0000)
committerPierre Joye <pajoye@php.net>
Wed, 27 Jan 2010 01:18:43 +0000 (01:18 +0000)
main/streams/plain_wrapper.c

index 9ce31ac8dded845d74277b1b59766b2425a22ce2..86ad798144c2cffa325e006f42205407b30e1f0a 100644 (file)
@@ -1042,6 +1042,28 @@ static int php_plain_files_rename(php_stream_wrapper *wrapper, char *url_from, c
                return 0;
        }
 
+#ifdef PHP_WIN32
+       /* Prevent bad things to happen when passing ' ' to MoveFileEx */
+       {
+               int url_from_len = strlen(url_from);
+               int url_to_len = strlen(url_to);
+               char *trimed = php_trim(url_from, url_from_len, NULL, 0, NULL, 1 TSRMLS_CC);
+               int trimed_len = strlen(trimed);
+
+               if (trimed_len == 0 || trimed_len != url_from_len) {
+                       php_win32_docref2_from_error(ERROR_INVALID_NAME, url_from, url_to TSRMLS_CC);
+                       return 0;
+               }
+
+               trimed = php_trim(url_to, url_to_len, NULL, 0, NULL, 1 TSRMLS_CC);
+               trimed_len = strlen(trimed);
+               if (trimed_len == 0 || trimed_len != url_to_len) {
+                       php_win32_docref2_from_error(ERROR_INVALID_NAME, url_from, url_to TSRMLS_CC);
+                       return 0;
+               }
+       }
+#endif
+
        if ((p = strstr(url_from, "://")) != NULL) {
                url_from = p + 3;
        }