Re: cvs: php4 /ext/standard file.c

From: Date: Tue, 08 Apr 2003 23:05:48 +0000
Subject: Re: cvs: php4 /ext/standard file.c
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-812@lists.php.net to get a copy of this message
I had the same reaction when I saw this but ultimately decided to leave it in. (A) Hopefully sterling had a reason for putting it in in the first place :) (B) include_path typically starts with a '.' making this a non-issue. (C) fopen($filename, 'w', true) is possible and can cause exactly the same potential problem anyway. My vote: +0 -Pollita "Wez Furlong" <wez@thebrainroom.com> wrote in message news:Pine.LNX.4.53.0304082312140.13015@zaneeb.brainnet.i... > I'm not so sure if we should use the include path for > file_put_contents(), as there is potential for writing to the wrong > file; generally speaking you should know which file you are going to > modify before you attempt to modify it :) And what if the file doesn't > yet existing in the include path? :) > > --Wez. > > I know you didn't write that bit of code; just raising the issue. > > On Tue, 8 Apr 2003, Sara Golemon wrote: > > > pollita Tue Apr 8 18:10:15 2003 EDT > > > > Modified files: > > /php4/ext/standard file.c > > Log: > > Add context support to file_put_contents() and readfile(), convert readfile() to zend_parse_parameters usage, fix proto for file_put_contents() > > > > Index: php4/ext/standard/file.c > > diff -u php4/ext/standard/file.c:1.332 php4/ext/standard/file.c:1.333 > > --- php4/ext/standard/file.c:1.332 Tue Apr 8 17:00:07 2003 > > +++ php4/ext/standard/file.c Tue Apr 8 18:10:15 2003 > > @@ -21,7 +21,7 @@ > > +----------------------------------------------------------------------+ > > */ > > > > -/* $Id: file.c,v 1.332 2003/04/08 21:00:07 pollita Exp $ */ > > +/* $Id: file.c,v 1.333 2003/04/08 22:10:15 pollita Exp $ */ > > > > /* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */ > > > > @@ -465,7 +465,7 @@ > > } > > /* }}} */ > > > > -/* {{{ proto string file_put_contents(string file, string data) > > +/* {{{ proto string file_put_contents(string file, string data[, bool use_include_path[, resource context]]) > > Write/Create a file with contents data */ > > PHP_FUNCTION(file_put_contents) > > { > > @@ -474,14 +474,20 @@ > > size_t filename_len, data_len; > > int numbytes; > > zend_bool use_include_path = 0; > > + zval *zcontext = NULL; > > + php_stream_context *context = NULL; > > > > - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|b", &filename, &filename_len, > > - &data, &data_len, &use_include_path) == FAILURE) { > > + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|br!", &filename, &filename_len, > > + &data, &data_len, &use_include_path, &zcontext) == FAILURE) { > > return; > > } > > > > - stream = php_stream_open_wrapper(filename, "wb", > > - (use_include_path ? USE_PATH : 0) | ENFORCE_SAFE_MODE | REPORT_ERRORS, NULL); > > + if (zcontext) { > > + context = zend_fetch_resource(&zcontext TSRMLS_CC, -1, "Stream-Context", NULL, 1, php_le_stream_context()); > > + } > > + > > + stream = php_stream_open_wrapper_ex(filename, "wb", > > + (use_include_path ? USE_PATH : 0) | ENFORCE_SAFE_MODE | REPORT_ERRORS, NULL, context); > > if (stream == NULL) { > > RETURN_FALSE; > > } > > @@ -1282,37 +1288,27 @@ > > } > > /* }}} */ > > > > -/* {{{ proto int readfile(string filename [, bool use_include_path]) > > +/* {{{ proto int readfile(string filename [, bool use_include_path[, resource context]]) > > Output a file or a URL */ > > PHP_FUNCTION(readfile) > > { > > - zval **arg1, **arg2; > > - int size=0; > > - int use_include_path=0; > > + int size = 0; > > + char *filename; > > + int filename_len; > > + zend_bool use_include_path = 0; > > + zval *zcontext = NULL; > > php_stream *stream; > > - > > - /* check args */ > > - switch (ZEND_NUM_ARGS()) { > > - case 1: > > - if (zend_get_parameters_ex(1, &arg1) == FAILURE) { > > - WRONG_PARAM_COUNT; > > - } > > - break; > > + php_stream_context *context = NULL; > > > > - case 2: > > - if (zend_get_parameters_ex(2, &arg1, &arg2) == FAILURE) { > > - WRONG_PARAM_COUNT; > > - } > > - convert_to_long_ex(arg2); > > - use_include_path = Z_LVAL_PP(arg2); > > - break; > > + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|br!", &filename, &filename_len, &use_include_path, &zcontext) == FAILURE) { > > + RETURN_FALSE; > > + } > > > > - default: > > - WRONG_PARAM_COUNT; > > + if (zcontext) { > > + context = zend_fetch_resource(&zcontext TSRMLS_CC, -1, "Stream-Context", NULL, 1, php_le_stream_context()); > > } > > - convert_to_string_ex(arg1); > > > > - stream = php_stream_open_wrapper(Z_STRVAL_PP(arg1), "rb", (use_include_path ? USE_PATH : 0) | ENFORCE_SAFE_MODE | REPORT_ERRORS, NULL); > > + stream = php_stream_open_wrapper_ex(filename, "rb", (use_include_path ? USE_PATH : 0) | ENFORCE_SAFE_MODE | REPORT_ERRORS, NULL, context); > > if (stream) { > > size = php_stream_passthru(stream); > > php_stream_close(stream); > > > > > > > > -- > > PHP CVS Mailing List (http://www.php.net/) > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > > >

« previous php.internals (#812) next »