Re: [PHP-CVS] cvs: php4 /ext/standard exec.c exec.h
Shouldn't this be MFH'd ? --Jani On Wed, 26 Feb 2003, Ilia Alshanetsky wrote: >iliaa Wed Feb 26 17:11:12 2003 EDT > > Modified files: >/php4/ext/standard exec.c exec.h > Log: > 1) Make the output of system() binary safe > 2) Solved a memory leak when the return_value variable passed by reference is > not an integer in system()/exec()/passthru(). > 3) Solved a bug in exec(), which would make it append to the 2nd parameter > (passed by reference) if the parameter is an array instead of overwriting it. > 4) Changed the code to use the streams code, resulting in a smaller code base. > 5) Various cleanups resulting in reduction of overall code base inside the file > by ~ 1/3. > 6) Speed improvements of ~2.5 times compared to previous performance (based on > attached PHP script). > > -- <- For Sale! -> -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4 /ext/standard exec.c exec.h
iliaa Wed Feb 26 17:11:12 2003 EDT Modified files: /php4/ext/standard exec.c exec.h Log: 1) Make the output of system() binary safe 2) Solved a memory leak when the return_value variable passed by reference is not an integer in system()/exec()/passthru(). 3) Solved a bug in exec(), which would make it append to the 2nd parameter (passed by reference) if the parameter is an array instead of overwriting it. 4) Changed the code to use the streams code, resulting in a smaller code base. 5) Various cleanups resulting in reduction of overall code base inside the file by ~ 1/3. 6) Speed improvements of ~2.5 times compared to previous performance (based on attached PHP script). Index: php4/ext/standard/exec.c diff -u php4/ext/standard/exec.c:1.97 php4/ext/standard/exec.c:1.98 --- php4/ext/standard/exec.c:1.97 Tue Feb 25 18:52:34 2003 +++ php4/ext/standard/exec.cWed Feb 26 17:11:12 2003 @@ -12,10 +12,11 @@ | obtain it through the world-wide-web, please send a note to | | [EMAIL PROTECTED] so we can mail you a copy immediately. | +--+ - | Author: Rasmus Lerdorf | + | Author: Rasmus Lerdorf <[EMAIL PROTECTED]> | + | Ilia Alshanetsky <[EMAIL PROTECTED]> | +--+ */ -/* $Id: exec.c,v 1.97 2003/02/25 23:52:34 iliaa Exp $ */ +/* $Id: exec.c,v 1.98 2003/02/26 22:11:12 iliaa Exp $ */ #include #include "php.h" @@ -49,278 +50,201 @@ #include #endif -/* {{{ php_Exec +/* {{{ php_exec * If type==0, only last line of output is returned (exec) * If type==1, all lines will be printed and last lined returned (system) * If type==2, all lines will be saved to given array (exec with &$array) * If type==3, output will be printed binary, no lines will be saved or returned (passthru) * */ -int php_Exec(int type, char *cmd, pval *array, pval *return_value TSRMLS_DC) +int php_exec(int type, char *cmd, pval *array, pval *return_value TSRMLS_DC) { FILE *fp; char *buf, *tmp=NULL; - int buflen = 0; - int t, l, output=1; - int overflow_limit, lcmd, ldir; - char *b, *c, *d=NULL; - php_stream *stream = NULL; - int pclose_return = 0; + int buflen, l, pclose_return; + char *cmd_p, *b, *c, *d=NULL; + php_stream *stream; + size_t bufl = 0; #if PHP_SIGCHILD void (*sig_handler)(); #endif - buf = (char *) emalloc(EXEC_INPUT_BUF); - buflen = EXEC_INPUT_BUF; - if (PG(safe_mode)) { - lcmd = strlen(cmd); - ldir = strlen(PG(safe_mode_exec_dir)); - l = lcmd + ldir + 2; - overflow_limit = l; - c = strchr(cmd, ' '); - if (c) *c = '\0'; + if ((c = strchr(cmd, ' '))) { + *c = '\0'; + c++; + } if (strstr(cmd, "..")) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "No '..' components allowed in path"); - efree(buf); - return -1; + goto err; } - d = emalloc(l); - strcpy(d, PG(safe_mode_exec_dir)); - overflow_limit -= ldir; b = strrchr(cmd, PHP_DIR_SEPARATOR); - if (b) { - strcat(d, b); - overflow_limit -= strlen(b); - } else { - strcat(d, "/"); - strcat(d, cmd); - overflow_limit-=(strlen(cmd)+1); - } + spprintf(&d, 0, "%s%s%s%s", PG(safe_mode_exec_dir), (b ? "" : "/"), (b ? b : cmd), (c ? " " : ""), (c ? c : "")); if (c) { - *c = ' '; - strncat(d, c, overflow_limit); + *(c - 1) = ' '; } - tmp = php_escape_shell_cmd(d); + cmd_p = php_escape_shell_cmd(d); efree(d); - d = tmp; -#if PHP_SIGCHILD - sig_handler = signal (SIGCHLD, SIG_DFL); -#endif -#ifdef PHP_WIN32 - fp = VCWD_POPEN(d, "rb"); -#else - fp = VCWD_POPEN(d, "r"); -#endif - if (!fp) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to fork [%s]", d); - efree(d); - efree(buf); -#if PHP_SIGCHILD - signal (SIGCHLD, sig_handler); -#endif - return -1; - } + d = cmd_p; + } else { + cmd_p = cmd; + } - } else { /* not safe_mode */ #if PHP_SI
[PHP-CVS] cvs: php4 /ext/standard exec.c
iliaa Tue Feb 25 18:52:39 2003 EDT Modified files: /php4/ext/standard exec.c Log: Made shell_exec() use streams, this simplifies the code and in some cases makes it a little faster too. Index: php4/ext/standard/exec.c diff -u php4/ext/standard/exec.c:1.96 php4/ext/standard/exec.c:1.97 --- php4/ext/standard/exec.c:1.96 Tue Feb 25 11:21:00 2003 +++ php4/ext/standard/exec.cTue Feb 25 18:52:34 2003 @@ -15,7 +15,7 @@ | Author: Rasmus Lerdorf | +--+ */ -/* $Id: exec.c,v 1.96 2003/02/25 16:21:00 iliaa Exp $ */ +/* $Id: exec.c,v 1.97 2003/02/25 23:52:34 iliaa Exp $ */ #include #include "php.h" @@ -452,9 +452,10 @@ PHP_FUNCTION(shell_exec) { FILE *in; - int readbytes, total_readbytes=0, allocated_space; + size_t total_readbytes; pval **cmd; char *ret; + php_stream *stream; if (ZEND_NUM_ARGS()!=1 || zend_get_parameters_ex(1, &cmd)==FAILURE) { WRONG_PARAM_COUNT; @@ -474,21 +475,16 @@ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to execute '%s'", Z_STRVAL_PP(cmd)); RETURN_FALSE; } - allocated_space = EXEC_INPUT_BUF; - ret = (char *) emalloc(allocated_space); - while (1) { - readbytes = fread(ret+total_readbytes, 1, EXEC_INPUT_BUF, in); - if (readbytes<=0) { - break; - } - total_readbytes += readbytes; - allocated_space = total_readbytes+EXEC_INPUT_BUF; - ret = (char *) erealloc(ret, allocated_space); - } - pclose(in); + + stream = php_stream_fopen_from_pipe(in, "rb"); + total_readbytes = php_stream_copy_to_mem(stream, &ret, PHP_STREAM_COPY_ALL, 0); + php_stream_close(stream); - RETVAL_STRINGL(ret, total_readbytes, 0); - Z_STRVAL_P(return_value)[total_readbytes] = '\0'; + if (total_readbytes > 0) { + RETURN_STRINGL(ret, total_readbytes, 0); + } else { + RETURN_NULL(); + } } /* }}} */ -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4 /ext/standard exec.c /ext/standard/tests/file bug22414.phpt
iliaa Tue Feb 25 11:21:00 2003 EDT Added files: /php4/ext/standard/tests/file bug22414.phpt Modified files: /php4/ext/standard exec.c Log: Fixed bug #22414 and added a test case for it. Index: php4/ext/standard/exec.c diff -u php4/ext/standard/exec.c:1.95 php4/ext/standard/exec.c:1.96 --- php4/ext/standard/exec.c:1.95 Wed Feb 19 19:32:51 2003 +++ php4/ext/standard/exec.cTue Feb 25 11:21:00 2003 @@ -15,7 +15,7 @@ | Author: Rasmus Lerdorf | +--+ */ -/* $Id: exec.c,v 1.95 2003/02/20 00:32:51 iliaa Exp $ */ +/* $Id: exec.c,v 1.96 2003/02/25 16:21:00 iliaa Exp $ */ #include #include "php.h" @@ -213,7 +213,7 @@ } else { size_t b; - while ((b = fread(buf, buflen, 1, fp)) > 0) { + while((b = php_stream_read(stream, buf, EXEC_INPUT_BUF)) > 0) { if (output) { PHPWRITE(buf, b); } Index: php4/ext/standard/tests/file/bug22414.phpt +++ php4/ext/standard/tests/file/bug22414.phpt --TEST-- Bug #22414: passthru() does not read data correctly --SKIPIF-- --POST-- --GET-- --FILE-- ' . $pwd . '/passthru_test'; exec($cmd); if (md5_file($php) == md5_file($pwd . '/passthru_test')) { echo "Works\n"; } else { echo "Does not work\n"; } @unlink($pwd . '/passthru_test'); ?> --EXPECT-- HELLO Works -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4 /ext/standard exec.c http_fopen_wrapper.c
iliaa Wed Feb 19 19:32:51 2003 EDT Modified files: /php4/ext/standard exec.c http_fopen_wrapper.c Log: Fixed bug #22308 (optimized passthru, code is now ~40 times faster). Index: php4/ext/standard/exec.c diff -u php4/ext/standard/exec.c:1.94 php4/ext/standard/exec.c:1.95 --- php4/ext/standard/exec.c:1.94 Mon Feb 17 20:23:51 2003 +++ php4/ext/standard/exec.cWed Feb 19 19:32:51 2003 @@ -15,7 +15,7 @@ | Author: Rasmus Lerdorf | +--+ */ -/* $Id: exec.c,v 1.94 2003/02/18 01:23:51 iliaa Exp $ */ +/* $Id: exec.c,v 1.95 2003/02/20 00:32:51 iliaa Exp $ */ #include #include "php.h" @@ -211,11 +211,12 @@ RETVAL_STRINGL(buf, l, 1); } } else { - int b, i; + size_t b; - while ((b = fread(buf, 1, buflen, fp)) > 0) { - for (i = 0; i < b; i++) - if (output) (void)PUTC(buf[i]); + while ((b = fread(buf, buflen, 1, fp)) > 0) { + if (output) { + PHPWRITE(buf, b); + } } } Index: php4/ext/standard/http_fopen_wrapper.c diff -u php4/ext/standard/http_fopen_wrapper.c:1.64 php4/ext/standard/http_fopen_wrapper.c:1.65 --- php4/ext/standard/http_fopen_wrapper.c:1.64 Tue Feb 18 19:49:31 2003 +++ php4/ext/standard/http_fopen_wrapper.c Wed Feb 19 19:32:51 2003 @@ -18,7 +18,7 @@ | Wez Furlong <[EMAIL PROTECTED]> | +--+ */ -/* $Id: http_fopen_wrapper.c,v 1.64 2003/02/19 00:49:31 iliaa Exp $ */ +/* $Id: http_fopen_wrapper.c,v 1.65 2003/02/20 00:32:51 iliaa Exp $ */ #include "php.h" #include "php_globals.h" @@ -354,7 +354,7 @@ s = resource->path; *s = '/'; } - s[1] = '\0'; + *(s + 1) = '\0'; if (resource->path && *(resource->path) == '/' && *(resource->path + 1) == '\0') { snprintf(loc_path, sizeof(loc_path) - 1, "%s%s", resource->path, location); } else { -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4 /ext/standard exec.c file.c image.c info.c metaphone.c string.c
iliaa Sat Jan 18 15:01:48 2003 EDT Modified files: /php4/ext/standard exec.c file.c image.c info.c metaphone.c string.c Log: Removed pointless memory allocation checks. Index: php4/ext/standard/exec.c diff -u php4/ext/standard/exec.c:1.91 php4/ext/standard/exec.c:1.92 --- php4/ext/standard/exec.c:1.91 Wed Jan 15 11:29:00 2003 +++ php4/ext/standard/exec.cSat Jan 18 15:01:40 2003 @@ -15,7 +15,7 @@ | Author: Rasmus Lerdorf | +--+ */ -/* $Id: exec.c,v 1.91 2003/01/15 16:29:00 wez Exp $ */ +/* $Id: exec.c,v 1.92 2003/01/18 20:01:40 iliaa Exp $ */ #include #include "php.h" @@ -67,10 +67,6 @@ #endif buf = (char *) emalloc(EXEC_INPUT_BUF); - if (!buf) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to emalloc %d bytes for exec buffer", EXEC_INPUT_BUF); - return -1; - } buflen = EXEC_INPUT_BUF; if (PG(safe_mode)) { @@ -162,14 +158,6 @@ do { if ( buflen <= (l+1) ) { buf = erealloc(buf, buflen + EXEC_INPUT_BUF); - if ( buf == NULL ) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to erealloc %d bytes for exec buffer", - buflen + EXEC_INPUT_BUF); -#if PHP_SIGCHILD - signal (SIGCHLD, sig_handler); -#endif - return -1; - } buflen += EXEC_INPUT_BUF; } Index: php4/ext/standard/file.c diff -u php4/ext/standard/file.c:1.294 php4/ext/standard/file.c:1.295 --- php4/ext/standard/file.c:1.294 Sat Jan 18 09:10:22 2003 +++ php4/ext/standard/file.cSat Jan 18 15:01:41 2003 @@ -21,7 +21,7 @@ +--+ */ -/* $Id: file.c,v 1.294 2003/01/18 14:10:22 wez Exp $ */ +/* $Id: file.c,v 1.295 2003/01/18 20:01:41 iliaa Exp $ */ /* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */ @@ -1495,7 +1495,7 @@ WRONG_PARAM_COUNT; } args = (zval ***)emalloc(argCount * sizeof(zval **)); - if (!args || (zend_get_parameters_array_ex(argCount, args) == FAILURE)) { + if (zend_get_parameters_array_ex(argCount, args) == FAILURE) { efree( args ); WRONG_PARAM_COUNT; } Index: php4/ext/standard/image.c diff -u php4/ext/standard/image.c:1.84 php4/ext/standard/image.c:1.85 --- php4/ext/standard/image.c:1.84 Fri Jan 17 13:51:30 2003 +++ php4/ext/standard/image.c Sat Jan 18 15:01:43 2003 @@ -17,7 +17,7 @@ +--+ */ -/* $Id: image.c,v 1.84 2003/01/17 18:51:30 helly Exp $ */ +/* $Id: image.c,v 1.85 2003/01/18 20:01:43 iliaa Exp $ */ #include "php.h" #include @@ -215,10 +215,6 @@ do { szlength=slength*(1height = php_read2(stream TSRMLS_CC); @@ -605,9 +598,6 @@ } result = (struct gfxinfo *)ecalloc(1, sizeof(struct gfxinfo)); - if (!result) { - return NULL; - } dummy_short = php_read2(stream TSRMLS_CC); /* Lsiz */ dummy_short = php_read2(stream TSRMLS_CC); /* Rsiz */ Index: php4/ext/standard/info.c diff -u php4/ext/standard/info.c:1.223 php4/ext/standard/info.c:1.224 --- php4/ext/standard/info.c:1.223 Fri Jan 17 13:07:10 2003 +++ php4/ext/standard/info.cSat Jan 18 15:01:43 2003 @@ -18,7 +18,7 @@ +--+ */ -/* $Id: info.c,v 1.223 2003/01/17 18:07:10 derick Exp $ */ +/* $Id: info.c,v 1.224 2003/01/18 20:01:43 iliaa Exp $ */ #include "php.h" #include "php_ini.h" @@ -439,10 +439,7 @@ for (zend_hash_internal_pointer_reset(url_stream_wrappers_hash); zend_hash_get_current_key_ex(url_stream_wrappers_hash, &stream_protocol, &stream_protocol_len, NULL, 0, NULL) == HASH_KEY_IS_STRING; zend_hash_move_forward(url_stream_wrappers_hash)) { - if (NULL == (stream_protocols_buf = erealloc(stream_protocols_buf, - stream_protocols_buf_len + stream_protocol_len + 2 /* ", " */ + 1 /* 0 byte at end */))) { - break; - } +
[PHP-CVS] cvs: php4 /ext/standard exec.c
hyanantha Fri Jan 3 11:06:03 2003 EDT Modified files: /php4/ext/standard exec.c Log: Modified for NetWare. Index: php4/ext/standard/exec.c diff -u php4/ext/standard/exec.c:1.89 php4/ext/standard/exec.c:1.90 --- php4/ext/standard/exec.c:1.89 Fri Jan 3 09:37:40 2003 +++ php4/ext/standard/exec.cFri Jan 3 11:06:02 2003 @@ -15,7 +15,7 @@ | Author: Rasmus Lerdorf | +--+ */ -/* $Id: exec.c,v 1.89 2003/01/03 14:37:40 hyanantha Exp $ */ +/* $Id: exec.c,v 1.90 2003/01/03 16:06:02 hyanantha Exp $ */ #include #include "php.h" @@ -599,13 +599,13 @@ le_proc_open = zend_register_list_destructors_ex(proc_open_rsrc_dtor, NULL, "process", module_number); return SUCCESS; } - /* }}} */ /* {{{ proto int proc_close(resource process) close a process opened by proc_open */ PHP_FUNCTION(proc_close) { +#ifndef NETWARE/* This is removed for NetWare because there is not way to +execute a new process using fork() */ zval *proc; void *child; @@ -617,6 +617,7 @@ zend_list_delete(Z_LVAL_P(proc)); RETURN_LONG(FG(pclose_ret)); +#endif /* NETWARE */ } /* }}} */ @@ -667,6 +668,8 @@ Run a process with more control over it's file descriptors */ PHP_FUNCTION(proc_open) { +#ifndef NETWARE/* This is removed for NetWare because there is not way to +execute a new process using fork() */ + #define MAX_DESCRIPTORS16 char *command; @@ -896,18 +899,6 @@ child = pi.hProcess; CloseHandle(pi.hThread); -#elif defined(NETWARE) - - /* clean up all the descriptors */ - for (i = 0; i < ndesc; i++) { - close(descriptors[i].childend); - close(descriptors[i].parentend); - } - - php_error_docref(NULL TSRMLS_CC, E_WARNING, "fork not supported on NetWare"); - - goto exit_fail; - #else /* the unix way */ @@ -1008,7 +999,7 @@ efree(command); RETURN_FALSE; - +#endif /* NETWARE */ } /* }}} */ -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-CVS] cvs: php4 /ext/standard exec.c file.c filestat.c html.csyslog.c
Wouldn't it be better to just remove proc_open from the function table under netware? It doesn't make sense to do all that work and then fail because there is not way to execute a new process (fork() + exec()). --Wez. On Fri, 3 Jan 2003, Anantha Kesari H Y wrote: > hyanantha Fri Jan 3 09:37:43 2003 EDT > > Modified files: > /php4/ext/standardexec.c file.c filestat.c html.c syslog.c > Log: > Modified for NetWare. > > > Index: php4/ext/standard/exec.c > diff -u php4/ext/standard/exec.c:1.88 php4/ext/standard/exec.c:1.89 > --- php4/ext/standard/exec.c:1.88 Tue Dec 31 11:07:38 2002 > +++ php4/ext/standard/exec.c Fri Jan 3 09:37:40 2003 > @@ -895,6 +895,18 @@ > > child = pi.hProcess; > CloseHandle(pi.hThread); > + > +#elif defined(NETWARE) > + > + /* clean up all the descriptors */ > + for (i = 0; i < ndesc; i++) { > + close(descriptors[i].childend); > + close(descriptors[i].parentend); > + } > + > + php_error_docref(NULL TSRMLS_CC, E_WARNING, "fork not supported on NetWare"); > + > + goto exit_fail; -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4 /ext/standard exec.c file.c filestat.c html.c syslog.c
hyanantha Fri Jan 3 09:37:43 2003 EDT Modified files: /php4/ext/standard exec.c file.c filestat.c html.c syslog.c Log: Modified for NetWare. Index: php4/ext/standard/exec.c diff -u php4/ext/standard/exec.c:1.88 php4/ext/standard/exec.c:1.89 --- php4/ext/standard/exec.c:1.88 Tue Dec 31 11:07:38 2002 +++ php4/ext/standard/exec.cFri Jan 3 09:37:40 2003 @@ -15,7 +15,7 @@ | Author: Rasmus Lerdorf | +--+ */ -/* $Id: exec.c,v 1.88 2002/12/31 16:07:38 sebastian Exp $ */ +/* $Id: exec.c,v 1.89 2003/01/03 14:37:40 hyanantha Exp $ */ #include #include "php.h" @@ -895,6 +895,18 @@ child = pi.hProcess; CloseHandle(pi.hThread); + +#elif defined(NETWARE) + + /* clean up all the descriptors */ + for (i = 0; i < ndesc; i++) { + close(descriptors[i].childend); + close(descriptors[i].parentend); + } + + php_error_docref(NULL TSRMLS_CC, E_WARNING, "fork not supported on NetWare"); + + goto exit_fail; #else /* the unix way */ Index: php4/ext/standard/file.c diff -u php4/ext/standard/file.c:1.285 php4/ext/standard/file.c:1.286 --- php4/ext/standard/file.c:1.285 Fri Jan 3 03:02:35 2003 +++ php4/ext/standard/file.cFri Jan 3 09:37:41 2003 @@ -21,7 +21,7 @@ +--+ */ -/* $Id: file.c,v 1.285 2003/01/03 08:02:35 pollita Exp $ */ +/* $Id: file.c,v 1.286 2003/01/03 14:37:41 hyanantha Exp $ */ /* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */ @@ -54,6 +54,7 @@ #include "netware/param.h" #else #include +#include #if defined(NETWARE) && defined(USE_WINSOCK) #include #else @@ -1979,9 +1980,16 @@ MAKE_LONG_ZVAL_INCREF(stat_rdev, -1); #endif MAKE_LONG_ZVAL_INCREF(stat_size, stat_ssb.sb.st_size); +#if defined(NETWARE) && defined(CLIB_STAT_PATCH) + MAKE_LONG_ZVAL_INCREF(stat_atime, stat_ssb.sb.st_atime.tv_sec); + MAKE_LONG_ZVAL_INCREF(stat_mtime, stat_ssb.sb.st_mtime.tv_sec); + MAKE_LONG_ZVAL_INCREF(stat_ctime, stat_ssb.sb.st_ctime.tv_sec); +#else MAKE_LONG_ZVAL_INCREF(stat_atime, stat_ssb.sb.st_atime); MAKE_LONG_ZVAL_INCREF(stat_mtime, stat_ssb.sb.st_mtime); MAKE_LONG_ZVAL_INCREF(stat_ctime, stat_ssb.sb.st_ctime); +#endif + #ifdef HAVE_ST_BLKSIZE MAKE_LONG_ZVAL_INCREF(stat_blksize, stat_ssb.sb.st_blksize); #else Index: php4/ext/standard/filestat.c diff -u php4/ext/standard/filestat.c:1.114 php4/ext/standard/filestat.c:1.115 --- php4/ext/standard/filestat.c:1.114 Tue Dec 31 11:07:40 2002 +++ php4/ext/standard/filestat.cFri Jan 3 09:37:41 2003 @@ -16,7 +16,7 @@ +--+ */ -/* $Id: filestat.c,v 1.114 2002/12/31 16:07:40 sebastian Exp $ */ +/* $Id: filestat.c,v 1.115 2003/01/03 14:37:41 hyanantha Exp $ */ #include "php.h" #include "safe_mode.h" @@ -664,26 +664,30 @@ case FS_INODE: RETURN_LONG((long)BG(sb).st_ino); case FS_SIZE: +#if defined(NETWARE) && defined(NEW_LIBC) + RETURN_LONG((long)(stat_sb->st_size)); +#else RETURN_LONG((long)BG(sb).st_size); +#endif case FS_OWNER: RETURN_LONG((long)BG(sb).st_uid); case FS_GROUP: RETURN_LONG((long)BG(sb).st_gid); case FS_ATIME: #if defined(NETWARE) && defined(NEW_LIBC) - RETURN_LONG((long)(BG(sb).st_atime).tv_nsec); + RETURN_LONG((long)((stat_sb->st_atime).tv_sec)); #else RETURN_LONG((long)BG(sb).st_atime); #endif case FS_MTIME: #if defined(NETWARE) && defined(NEW_LIBC) - RETURN_LONG((long)(BG(sb).st_mtime).tv_nsec); + RETURN_LONG((long)((stat_sb->st_mtime).tv_sec)); #else - RETURN_LONG((long)BG(sb).st_mtime); + RETURN_LONG((long)BG(sb).st_mtime); #endif case FS_CTIME: #if defined(NETWARE) && defined(NEW_LIBC) - RETURN_LONG((long)(BG(sb).st_ctime).tv_nsec); + RETURN_LONG((long)((stat_sb->st_ctime).tv_sec)); #else RETURN_LONG((long)BG(sb).st_ctime); #endif @@ -706,28 +710,25 @@ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown file type (%d)", BG(sb).st_mode&S_IFMT); RETURN_STRING("unknown", 1); case FS_IS_W: -#ifdef NETWARE - RETURN_LONG(0); -#endif + #ifndef NETWARE /* getuid is not available on NetWare */ if (getuid()==0) { RETURN_TRUE; /* root */ } + #endif /* NETWARE */ RETURN_BOOL((BG(sb).st_mode & wmask) != 0); case FS_IS_R: -#ifdef NETWARE - RETURN_LONG(0); -#endif + #ifndef NETWARE /* getuid is not available on NetWare */
[PHP-CVS] cvs: php4 /ext/standard exec.c /main streams.c
wez Thu Dec 19 15:23:51 2002 EDT Modified files: /php4/ext/standard exec.c /php4/main streams.c Log: Correct mistake introduced by my last commit on these files; *_from_pipe() is for process-pipes created by fopen, not generic pipes created from proc_open(). Correctly implemented the fifo/pipe check for *_from_file() and it seems to be working correctly now. Index: php4/ext/standard/exec.c diff -u php4/ext/standard/exec.c:1.86 php4/ext/standard/exec.c:1.87 --- php4/ext/standard/exec.c:1.86 Thu Dec 12 12:51:25 2002 +++ php4/ext/standard/exec.cThu Dec 19 15:23:50 2002 @@ -15,7 +15,7 @@ | Author: Rasmus Lerdorf | +--+ */ -/* $Id: exec.c,v 1.86 2002/12/12 17:51:25 wez Exp $ */ +/* $Id: exec.c,v 1.87 2002/12/19 20:23:50 wez Exp $ */ #include #include "php.h" @@ -976,7 +976,7 @@ fp = fdopen(descriptors[i].parentend, mode_string); #endif if (fp) { - stream = php_stream_fopen_from_pipe(fp, mode_string); + stream = php_stream_fopen_from_file(fp, +mode_string); if (stream) { zval *retfp; Index: php4/main/streams.c diff -u php4/main/streams.c:1.135 php4/main/streams.c:1.136 --- php4/main/streams.c:1.135 Thu Dec 12 12:51:25 2002 +++ php4/main/streams.c Thu Dec 19 15:23:50 2002 @@ -20,7 +20,7 @@ +--+ */ -/* $Id: streams.c,v 1.135 2002/12/12 17:51:25 wez Exp $ */ +/* $Id: streams.c,v 1.136 2002/12/19 20:23:50 wez Exp $ */ #define _GNU_SOURCE #include "php.h" @@ -1298,6 +1298,7 @@ PHPAPI php_stream *_php_stream_fopen_from_file(FILE *file, const char *mode STREAMS_DC TSRMLS_DC) { php_stdio_stream_data *self; + php_stream *stream; self = emalloc_rel_orig(sizeof(*self)); self->file = file; @@ -1314,7 +1315,13 @@ } #endif - return php_stream_alloc_rel(&php_stream_stdio_ops, self, 0, mode); + stream = php_stream_alloc_rel(&php_stream_stdio_ops, self, 0, mode); + + if (stream && self->is_pipe) { + stream->flags |= PHP_STREAM_FLAG_NO_SEEK; + } + + return stream; } PHPAPI php_stream *_php_stream_fopen_from_pipe(FILE *file, const char *mode STREAMS_DC TSRMLS_DC) -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4 /ext/standard exec.c /main streams.c
wez Thu Dec 12 12:51:25 2002 EDT Modified files: /php4/ext/standard exec.c /php4/main streams.c Log: MFB: popen/pclose and proc_open/proc_close fixes. Index: php4/ext/standard/exec.c diff -u php4/ext/standard/exec.c:1.85 php4/ext/standard/exec.c:1.86 --- php4/ext/standard/exec.c:1.85 Thu Dec 5 15:59:49 2002 +++ php4/ext/standard/exec.cThu Dec 12 12:51:25 2002 @@ -15,7 +15,7 @@ | Author: Rasmus Lerdorf | +--+ */ -/* $Id: exec.c,v 1.85 2002/12/05 20:59:49 helly Exp $ */ +/* $Id: exec.c,v 1.86 2002/12/12 17:51:25 wez Exp $ */ #include #include "php.h" @@ -118,6 +118,7 @@ int overflow_limit, lcmd, ldir; char *b, *c, *d=NULL; php_stream *stream = NULL; + int pclose_return = 0; #if PHP_SIGCHILD void (*sig_handler)(); #endif @@ -283,13 +284,8 @@ } } - FG(pclose_ret) = php_stream_close(stream); + pclose_return = php_stream_close(stream); -#if HAVE_SYS_WAIT_H - if (WIFEXITED(FG(pclose_ret))) { - FG(pclose_ret) = WEXITSTATUS(FG(pclose_ret)); - } -#endif #if PHP_SIGCHILD signal (SIGCHLD, sig_handler); #endif @@ -297,7 +293,7 @@ efree(d); } efree(buf); - return FG(pclose_ret); + return pclose_return; } /* }}} */ @@ -586,8 +582,12 @@ if (wait_pid == -1) FG(pclose_ret) = -1; - else + else { + if (WIFEXITED(wstatus)) + wstatus = WEXITSTATUS(wstatus); FG(pclose_ret) = wstatus; + } + # else FG(pclose_ret) = -1; # endif @@ -976,7 +976,7 @@ fp = fdopen(descriptors[i].parentend, mode_string); #endif if (fp) { - stream = php_stream_fopen_from_file(fp, mode_string); + stream = php_stream_fopen_from_pipe(fp, +mode_string); if (stream) { zval *retfp; Index: php4/main/streams.c diff -u php4/main/streams.c:1.134 php4/main/streams.c:1.135 --- php4/main/streams.c:1.134 Tue Dec 10 11:39:59 2002 +++ php4/main/streams.c Thu Dec 12 12:51:25 2002 @@ -20,7 +20,7 @@ +--+ */ -/* $Id: streams.c,v 1.134 2002/12/10 16:39:59 iliaa Exp $ */ +/* $Id: streams.c,v 1.135 2002/12/12 17:51:25 wez Exp $ */ #define _GNU_SOURCE #include "php.h" @@ -32,6 +32,9 @@ #ifdef HAVE_SYS_MMAN_H #include #endif +#if HAVE_SYS_WAIT_H +#include +#endif #include @@ -1317,6 +1320,7 @@ PHPAPI php_stream *_php_stream_fopen_from_pipe(FILE *file, const char *mode STREAMS_DC TSRMLS_DC) { php_stdio_stream_data *self; + php_stream *stream; self = emalloc_rel_orig(sizeof(*self)); self->file = file; @@ -1325,7 +1329,9 @@ self->fd = fileno(file); self->temp_file_name = NULL; - return php_stream_alloc_rel(&php_stream_stdio_ops, self, 0, mode); + stream = php_stream_alloc_rel(&php_stream_stdio_ops, self, 0, mode); + stream->flags |= PHP_STREAM_FLAG_NO_SEEK; + return stream; } static size_t php_stdiop_write(php_stream *stream, const char *buf, size_t count TSRMLS_DC) @@ -1385,11 +1391,18 @@ php_stdio_stream_data *data = (php_stdio_stream_data*)stream->abstract; assert(data != NULL); - + if (close_handle) { if (data->file) { if (data->is_process_pipe) { + errno = 0; ret = pclose(data->file); + +#if HAVE_SYS_WAIT_H + if (WIFEXITED(ret)) { + ret = WEXITSTATUS(ret); + } +#endif } else { ret = fclose(data->file); } -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4 /ext/standard exec.c
iliaa Mon Nov 4 12:38:30 2002 EDT Modified files: /php4/ext/standard exec.c Log: Silence compiler warning. Index: php4/ext/standard/exec.c diff -u php4/ext/standard/exec.c:1.83 php4/ext/standard/exec.c:1.84 --- php4/ext/standard/exec.c:1.83 Thu Oct 24 04:46:21 2002 +++ php4/ext/standard/exec.cMon Nov 4 12:38:30 2002 @@ -15,7 +15,7 @@ | Author: Rasmus Lerdorf | +--+ */ -/* $Id: exec.c,v 1.83 2002/10/24 08:46:21 jan Exp $ */ +/* $Id: exec.c,v 1.84 2002/11/04 17:38:30 iliaa Exp $ */ #include #include "php.h" @@ -946,7 +946,7 @@ * ends, where appropriate */ for (i = 0; i < ndesc; i++) { FILE *fp; - char *mode_string; + char *mode_string=NULL; php_stream *stream; close_descriptor(descriptors[i].childend); -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4 /ext/standard exec.c
jan Thu Oct 24 04:46:22 2002 EDT Modified files: /php4/ext/standard exec.c Log: - fix segfault in proc_open #no bugreports found Index: php4/ext/standard/exec.c diff -u php4/ext/standard/exec.c:1.82 php4/ext/standard/exec.c:1.83 --- php4/ext/standard/exec.c:1.82 Wed Sep 25 11:46:46 2002 +++ php4/ext/standard/exec.cThu Oct 24 04:46:21 2002 @@ -15,7 +15,7 @@ | Author: Rasmus Lerdorf | +--+ */ -/* $Id: exec.c,v 1.82 2002/09/25 15:46:46 wez Exp $ */ +/* $Id: exec.c,v 1.83 2002/10/24 08:46:21 jan Exp $ */ #include #include "php.h" @@ -761,7 +761,7 @@ if (zend_hash_index_find(Z_ARRVAL_PP(descitem), 0, (void **)&ztype) == SUCCESS) { convert_to_string_ex(ztype); } else { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Missing handle qualifier in array", Z_STRVAL_PP(ztype)); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Missing +handle qualifier in array"); goto exit_fail; } -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4 /ext/standard exec.c exec.h
iliaa Thu Sep 19 14:59:32 2002 EDT Modified files: /php4/ext/standard exec.c exec.h Log: Fixed bug #19313 Fixed argument count check for system/exec/passthru functions Added a check to system/exec/passthru functions to make sure execution parameter is not blank before attempting to execute it. Index: php4/ext/standard/exec.c diff -u php4/ext/standard/exec.c:1.80 php4/ext/standard/exec.c:1.81 --- php4/ext/standard/exec.c:1.80 Fri Aug 23 21:19:27 2002 +++ php4/ext/standard/exec.cThu Sep 19 14:59:32 2002 @@ -15,7 +15,7 @@ | Author: Rasmus Lerdorf | +--+ */ -/* $Id: exec.c,v 1.80 2002/08/24 01:19:27 helly Exp $ */ +/* $Id: exec.c,v 1.81 2002/09/19 18:59:32 iliaa Exp $ */ #include #include "php.h" @@ -309,9 +309,14 @@ int arg_count = ZEND_NUM_ARGS(); int ret; - if (arg_count > 3 || zend_get_parameters_ex(arg_count, &arg1, &arg2, &arg3) == FAILURE) { + if (arg_count < 1 || arg_count > 3 || zend_get_parameters_ex(arg_count, &arg1, +&arg2, &arg3) == FAILURE) { WRONG_PARAM_COUNT; } + + if (!Z_STRLEN_PP(arg1)) { + PHP_EMPTY_EXEC_PARAM; + } + switch (arg_count) { case 1: ret = php_Exec(0, Z_STRVAL_PP(arg1), NULL, return_value TSRMLS_CC); @@ -337,9 +342,14 @@ int arg_count = ZEND_NUM_ARGS(); int ret; - if (arg_count > 2 || zend_get_parameters_ex(arg_count, &arg1, &arg2) == FAILURE) { + if (arg_count < 1 || arg_count > 2 || zend_get_parameters_ex(arg_count, &arg1, +&arg2) == FAILURE) { WRONG_PARAM_COUNT; } + + if (!Z_STRLEN_PP(arg1)) { + PHP_EMPTY_EXEC_PARAM; + } + switch (arg_count) { case 1: ret = php_Exec(1, Z_STRVAL_PP(arg1), NULL, return_value TSRMLS_CC); @@ -361,9 +371,14 @@ int arg_count = ZEND_NUM_ARGS(); int ret; - if (arg_count > 2 || zend_get_parameters_ex(arg_count, &arg1, &arg2) == FAILURE) { + if (arg_count < 1 || arg_count > 2 || zend_get_parameters_ex(arg_count, &arg1, +&arg2) == FAILURE) { WRONG_PARAM_COUNT; } + + if (!Z_STRLEN_PP(arg1)) { + PHP_EMPTY_EXEC_PARAM; + } + switch (arg_count) { case 1: ret = php_Exec(3, Z_STRVAL_PP(arg1), NULL, return_value TSRMLS_CC); Index: php4/ext/standard/exec.h diff -u php4/ext/standard/exec.h:1.14 php4/ext/standard/exec.h:1.15 --- php4/ext/standard/exec.h:1.14 Wed Apr 3 08:39:35 2002 +++ php4/ext/standard/exec.hThu Sep 19 14:59:32 2002 @@ -16,7 +16,7 @@ +--+ */ -/* $Id: exec.h,v 1.14 2002/04/03 13:39:35 wez Exp $ */ +/* $Id: exec.h,v 1.15 2002/09/19 18:59:32 iliaa Exp $ */ #ifndef EXEC_H #define EXEC_H @@ -34,5 +34,7 @@ char *php_escape_shell_cmd(char *); char *php_escape_shell_arg(char *); int php_Exec(int type, char *cmd, pval *array, pval *return_value TSRMLS_DC); + +#define PHP_EMPTY_EXEC_PARAM { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot +execute a blank command"); RETURN_FALSE; } #endif /* EXEC_H */ -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php