[PHP-CVS] cvs: php4 /main/streams streams.c

2003-04-03 Thread Sara Golemon
pollita Thu Apr  3 20:33:58 2003 EDT

  Modified files:  
/php4/main/streams  streams.c 
  Log:
  Prevent php_stream_get_record from grabbing more than maxlen characters
  
Index: php4/main/streams/streams.c
diff -u php4/main/streams/streams.c:1.16 php4/main/streams/streams.c:1.17
--- php4/main/streams/streams.c:1.16Mon Mar 31 18:22:10 2003
+++ php4/main/streams/streams.c Thu Apr  3 20:33:58 2003
@@ -19,7 +19,7 @@
+--+
  */
 
-/* $Id: streams.c,v 1.16 2003/03/31 23:22:10 moriyoshi Exp $ */
+/* $Id: streams.c,v 1.17 2003/04/04 01:33:58 pollita Exp $ */
 
 #define _GNU_SOURCE
 #include php.h
@@ -801,6 +801,10 @@
} else {
toread = e - (char *) stream-readbuf;
}
+   }
+
+   if (toread  maxlen  maxlen  0) {
+   toread = maxlen;
}
 
buf = emalloc(toread + 1);



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-CVS] cvs: php4 /main/streams streams.c

2003-03-31 Thread Ilia Alshanetsky
iliaa   Mon Mar 31 17:13:01 2003 EDT

  Modified files:  
/php4/main/streams  streams.c 
  Log:
  WS
  
  Index: php4/main/streams/streams.c
diff -u php4/main/streams/streams.c:1.14 php4/main/streams/streams.c:1.15
--- php4/main/streams/streams.c:1.14Wed Mar 19 20:23:04 2003
+++ php4/main/streams/streams.c Mon Mar 31 17:13:01 2003
@@ -19,7 +19,7 @@
+--+
  */
 
-/* $Id: streams.c,v 1.14 2003/03/20 01:23:04 wez Exp $ */
+/* $Id: streams.c,v 1.15 2003/03/31 22:13:01 iliaa Exp $ */
 
 #define _GNU_SOURCE
 #include php.h
@@ -56,16 +56,17 @@
 static int forget_persistent_resource_id_numbers(zend_rsrc_list_entry *rsrc TSRMLS_DC)
 {
php_stream *stream;
-   
-   if (Z_TYPE_P(rsrc) != le_pstream)
+
+   if (Z_TYPE_P(rsrc) != le_pstream) {
return 0;
+   }
 
stream = (php_stream*)rsrc-ptr;
 
 #if STREAM_DEBUG
 fprintf(stderr, forget_persistent: %s:%p\n, stream-ops-label, stream);
 #endif
-   
+
stream-rsrc_id = FAILURE;
 
return 0;
@@ -123,15 +124,17 @@
 
for (i = 0, l = 0; i  wrapper-err_count; i++) {
l += strlen(wrapper-err_stack[i]);
-   if (i  wrapper-err_count - 1)
+   if (i  wrapper-err_count - 1) {
l += brlen;
+   }
}
msg = emalloc(l + 1);
msg[0] = '\0';
for (i = 0; i  wrapper-err_count; i++) {
strcat(msg, wrapper-err_stack[i]);
-   if (i  wrapper-err_count - 1)
+   if (i  wrapper-err_count - 1) { 
strcat(msg, br);
+   }
}
 
free_msg = 1;
@@ -145,8 +148,9 @@
php_strip_url_passwd(tmp);
php_error_docref1(NULL TSRMLS_CC, tmp, E_WARNING, %s: %s, caption, msg);
efree(tmp);
-   if (free_msg)
+   if (free_msg) {
efree(msg);
+   }
 }
 
 void php_stream_tidy_wrapper_error_log(php_stream_wrapper *wrapper TSRMLS_DC)
@@ -155,10 +159,12 @@
/* tidy up the error stack */
int i;
 
-   for (i = 0; i  wrapper-err_count; i++)
+   for (i = 0; i  wrapper-err_count; i++) {
efree(wrapper-err_stack[i]);
-   if (wrapper-err_stack)
+   }
+   if (wrapper-err_stack) {
efree(wrapper-err_stack);
+   }
wrapper-err_stack = NULL;
wrapper-err_count = 0;
}
@@ -179,8 +185,9 @@
} else {
/* append to stack */
wrapper-err_stack = erealloc(wrapper-err_stack, (wrapper-err_count 
+ 1) * sizeof(char *));
-   if (wrapper-err_stack)
+   if (wrapper-err_stack) {
wrapper-err_stack[wrapper-err_count++] = buffer;
+   }
}
 }
 
@@ -191,7 +198,7 @@
 PHPAPI php_stream *_php_stream_alloc(php_stream_ops *ops, void *abstract, const char 
*persistent_id, const char *mode STREAMS_DC TSRMLS_DC) /* {{{ */
 {
php_stream *ret;
-   
+
ret = (php_stream*) pemalloc_rel_orig(sizeof(php_stream), persistent_id ? 1 : 
0);
 
memset(ret, 0, sizeof(php_stream));
@@ -199,14 +206,15 @@
 #if STREAM_DEBUG
 fprintf(stderr, stream_alloc: %s:%p persistent=%s\n, ops-label, ret, 
persistent_id);
 #endif
-   
+
ret-ops = ops;
ret-abstract = abstract;
ret-is_persistent = persistent_id ? 1 : 0;
ret-chunk_size = FG(def_chunk_size);
-   
-   if (FG(auto_detect_line_endings))
+
+   if (FG(auto_detect_line_endings)) {
ret-flags |= PHP_STREAM_FLAG_DETECT_EOL;
+   }
 
if (persistent_id) {
list_entry le;
@@ -222,10 +230,10 @@
return NULL;
}
}
-   
+
ret-rsrc_id = ZEND_REGISTER_RESOURCE(NULL, ret, persistent_id ? le_pstream : 
le_stream);
strlcpy(ret-mode, mode, sizeof(ret-mode));
-   
+
return ret;
 }
 /* }}} */
@@ -240,10 +248,11 @@
 #if STREAM_DEBUG
 fprintf(stderr, stream_free: %s:%p[%s] in_free=%d opts=%08x\n, stream-ops-label, 
stream, stream-__orig_path, stream-in_free, close_options);
 #endif
-   
+
/* recursion protection */
-   if (stream-in_free)
+   if (stream-in_free) {
return 1;
+   }
 
stream-in_free++;
 
@@ -269,17 +278,15 @@
 fprintf(stderr, stream_free: %s:%p[%s] preserve_handle=%d release_cast=%d 
remove_rsrc=%d\n,
stream-ops-label, stream, stream-__orig_path, preserve_handle, 
release_cast, remove_rsrc);
 #endif
-   
+
/* make 

[PHP-CVS] cvs: php4 /main/streams streams.c

2003-03-31 Thread Moriyoshi Koizumi
moriyoshi   Mon Mar 31 18:22:10 2003 EDT

  Modified files:  
/php4/main/streams  streams.c 
  Log:
  Fixed bug #22538 (stream filter problem) 
  
  
Index: php4/main/streams/streams.c
diff -u php4/main/streams/streams.c:1.15 php4/main/streams/streams.c:1.16
--- php4/main/streams/streams.c:1.15Mon Mar 31 17:13:01 2003
+++ php4/main/streams/streams.c Mon Mar 31 18:22:10 2003
@@ -19,7 +19,7 @@
+--+
  */
 
-/* $Id: streams.c,v 1.15 2003/03/31 22:13:01 iliaa Exp $ */
+/* $Id: streams.c,v 1.16 2003/03/31 23:22:10 moriyoshi Exp $ */
 
 #define _GNU_SOURCE
 #include php.h
@@ -843,7 +843,7 @@

/* Only screw with the buffer if we can seek, otherwise we 
lose data
 * buffered from fifos and sockets */
-   if (stream-ops-seek  (stream-flags  
PHP_STREAM_FLAG_NO_SEEK) == 0  !php_stream_is_filtered(stream)) {
+   if (stream-ops-seek  (stream-flags  
PHP_STREAM_FLAG_NO_SEEK) == 0) {
stream-position += justwrote;
}
} else {



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-CVS] cvs: php4 /main/streams streams.c

2003-03-18 Thread Wez Furlong
wez Tue Mar 18 17:26:03 2003 EDT

  Modified files:  
/php4/main/streams  streams.c 
  Log:
  Q}
  
  
Index: php4/main/streams/streams.c
diff -u php4/main/streams/streams.c:1.11 php4/main/streams/streams.c:1.12
--- php4/main/streams/streams.c:1.11Tue Mar 18 09:35:01 2003
+++ php4/main/streams/streams.c Tue Mar 18 17:26:02 2003
@@ -19,7 +19,7 @@
+--+
  */
 
-/* $Id: streams.c,v 1.11 2003/03/18 14:35:01 wez Exp $ */
+/* $Id: streams.c,v 1.12 2003/03/18 22:26:02 wez Exp $ */
 
 #define _GNU_SOURCE
 #include php.h
@@ -1131,12 +1131,12 @@
}
}

-   /* avoid many reallocs by allocating a good sized chunk to begin with, if we 
can.
-* Note that the stream may be filtered, in which case the stat result may be 
inaccurate,
-* as the filter may inflate or deflate the number of bytes that we can read.
-* In order to avoid an upsize followed by a downsize of the buffer, 
overestimate by the
-* step size (which is 2K).
-* */
+   /* avoid many reallocs by allocating a good sized chunk to begin with, if
+* we can.  Note that the stream may be filtered, in which case the stat
+* result may be inaccurate, as the filter may inflate or deflate the
+* number of bytes that we can read.  In order to avoid an upsize followed
+* by a downsize of the buffer, overestimate by the step size (which is
+* 2K).  */
if (php_stream_stat(src, ssbuf) == 0  ssbuf.sb.st_size  0) {
max_len = ssbuf.sb.st_size + step;
} else {



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-CVS] cvs: php4 /main/streams streams.c

2003-03-18 Thread Wez Furlong
wez Tue Mar 18 19:17:15 2003 EDT

  Modified files:  
/php4/main/streams  streams.c 
  Log:
  Sanity check for when a stream is requested to be persistent but the wrapper
  does not respect the flag.
  
  
  
Index: php4/main/streams/streams.c
diff -u php4/main/streams/streams.c:1.12 php4/main/streams/streams.c:1.13
--- php4/main/streams/streams.c:1.12Tue Mar 18 17:26:02 2003
+++ php4/main/streams/streams.c Tue Mar 18 19:17:15 2003
@@ -19,7 +19,7 @@
+--+
  */
 
-/* $Id: streams.c,v 1.12 2003/03/18 22:26:02 wez Exp $ */
+/* $Id: streams.c,v 1.13 2003/03/19 00:17:15 wez Exp $ */
 
 #define _GNU_SOURCE
 #include php.h
@@ -1461,6 +1461,15 @@
stream = wrapper-wops-stream_opener(wrapper,
path_to_open, mode, options ^ REPORT_ERRORS,
opened_path, context STREAMS_REL_CC TSRMLS_CC);
+   
+   /* if the caller asked for a persistent stream but the wrapper did not
+* return one, force an error here */
+   if (stream  (options  STREAM_OPEN_PERSISTENT)  
!stream-is_persistent) {
+   php_stream_wrapper_log_error(wrapper, options ^ REPORT_ERRORS 
TSRMLS_CC,
+   wrapper does not support persistent streams);
+   php_stream_close(stream);
+   stream = NULL;
+   }

if (stream) {
stream-wrapper = wrapper;



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-CVS] cvs: php4 /main/streams streams.c

2003-03-17 Thread Ilia Alshanetsky
iliaa   Mon Mar 17 13:32:15 2003 EDT

  Modified files:  
/php4/main/streams  streams.c 
  Log:
  Fixed bug #22538 (failed stat on stdio/stdin/stderr streams).
  
  
Index: php4/main/streams/streams.c
diff -u php4/main/streams/streams.c:1.8 php4/main/streams/streams.c:1.9
--- php4/main/streams/streams.c:1.8 Thu Mar  6 15:31:20 2003
+++ php4/main/streams/streams.c Mon Mar 17 13:32:15 2003
@@ -19,7 +19,7 @@
+--+
  */
 
-/* $Id: streams.c,v 1.8 2003/03/06 20:31:20 sesser Exp $ */
+/* $Id: streams.c,v 1.9 2003/03/17 18:32:15 iliaa Exp $ */
 
 #define _GNU_SOURCE
 #include php.h
@@ -1168,7 +1168,7 @@
if (php_stream_stat(src, ssbuf) == 0) {
/* in the event that the source file is 0 bytes, return 1 to indicate 
success
 * because opening the file to write had already created a copy */
-   if (ssbuf.sb.st_size == 0) {
+   if (ssbuf.sb.st_size == 0  !S_ISFIFO(ssbuf.sb.st_mode)) {
return 1;
}
}



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-CVS] cvs: php4 /main/streams streams.c

2003-03-17 Thread Ilia Alshanetsky
iliaa   Mon Mar 17 17:25:56 2003 EDT

  Modified files:  
/php4/main/streams  streams.c 
  Log:
  Win32 build fix.
  
  
Index: php4/main/streams/streams.c
diff -u php4/main/streams/streams.c:1.9 php4/main/streams/streams.c:1.10
--- php4/main/streams/streams.c:1.9 Mon Mar 17 13:32:15 2003
+++ php4/main/streams/streams.c Mon Mar 17 17:25:55 2003
@@ -19,7 +19,7 @@
+--+
  */
 
-/* $Id: streams.c,v 1.9 2003/03/17 18:32:15 iliaa Exp $ */
+/* $Id: streams.c,v 1.10 2003/03/17 22:25:55 iliaa Exp $ */
 
 #define _GNU_SOURCE
 #include php.h
@@ -1168,7 +1168,11 @@
if (php_stream_stat(src, ssbuf) == 0) {
/* in the event that the source file is 0 bytes, return 1 to indicate 
success
 * because opening the file to write had already created a copy */
-   if (ssbuf.sb.st_size == 0  !S_ISFIFO(ssbuf.sb.st_mode)) {
+   if (ssbuf.sb.st_size == 0
+#ifdef S_ISFIFO
+ !S_ISFIFO(ssbuf.sb.st_mode)
+#endif
+   ) {
return 1;
}
}



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php