]> granicus.if.org Git - php/commitdiff
Fixed bug #71264 (file_put_contents() returns unexpected value when filesystem runs...
authorXinchen Hui <laruence@gmail.com>
Sun, 3 Jan 2016 06:21:23 +0000 (14:21 +0800)
committerXinchen Hui <laruence@gmail.com>
Sun, 3 Jan 2016 06:21:23 +0000 (14:21 +0800)
NEWS
ext/standard/file.c

diff --git a/NEWS b/NEWS
index d1a82fe2ab4ef36eb23e2846df2bed6e6c255911..cc43981a5027e326b7d517855a5826e8bae67595 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -23,6 +23,8 @@ PHP                                                                        NEWS
     immediately). (Laruence)
 
 - Standard:
+  . Fixed bug #71264 (file_put_contents() returns unexpected value when 
+    filesystem runs full). (Laruence)
   . Fixed bug #71245 (file_get_contents() ignores "header" context option if
     it's a reference). (Laruence)
   . Fixed bug #71220 (Null pointer deref (segfault) in compact via ob_start).
index 9cb7f2a813506f1f4e43d06040b9fe414d2e6484..4f3a6abd1184e9039bd4a011803a53cd79b0bffe 100644 (file)
@@ -577,7 +577,6 @@ PHP_FUNCTION(file_put_contents)
        php_stream_context *context = NULL;
        php_stream *srcstream = NULL;
        char mode[3] = "wb";
-       char ret_ok = 1;
 
        if (zend_parse_parameters(ZEND_NUM_ARGS(), "pz/|lr!", &filename, &filename_len, &data, &flags, &zcontext) == FAILURE) {
                return;
@@ -622,7 +621,7 @@ PHP_FUNCTION(file_put_contents)
                case IS_RESOURCE: {
                        size_t len;
                        if (php_stream_copy_to_stream_ex(srcstream, stream, PHP_STREAM_COPY_ALL, &len) != SUCCESS) {
-                               ret_ok = 0;
+                               numbytes = -1;
                        } else {
                                if (len > ZEND_LONG_MAX) {
                                        php_error_docref(NULL, E_WARNING, "content truncated from %zu to " ZEND_LONG_FMT " bytes", len, ZEND_LONG_MAX);
@@ -661,8 +660,8 @@ PHP_FUNCTION(file_put_contents)
                                                bytes_written = php_stream_write(stream, ZSTR_VAL(str), ZSTR_LEN(str));
                                                if (bytes_written != ZSTR_LEN(str)) {
                                                        php_error_docref(NULL, E_WARNING, "Failed to write %zd bytes to %s", ZSTR_LEN(str), filename);
-                                                       ret_ok = 0;
                                                        zend_string_release(str);
+                                                       numbytes = -1;
                                                        break;
                                                }
                                        }
@@ -686,12 +685,12 @@ PHP_FUNCTION(file_put_contents)
                                }
                        }
                default:
-                       ret_ok = 0;
+                       numbytes = -1;
                        break;
        }
        php_stream_close(stream);
 
-       if (!ret_ok) {
+       if (numbytes < 0) {
                RETURN_FALSE;
        }