wez             Tue Mar  4 20:28:45 2003 EDT

  Modified files:              (Branch: PHP_4_3)
    /php4/main  network.c streams.c 
  Log:
  Fix some signed/unsigned issues with read() and SSL_read() return values.
  Allow SSL_connect() to retry for non-blocking sockets.
  Correctly declare the char as unsigned for php_stream_getc(), as per
  fgetc() semantics.
  
  
Index: php4/main/network.c
diff -u php4/main/network.c:1.83.2.3 php4/main/network.c:1.83.2.4
--- php4/main/network.c:1.83.2.3        Sat Feb 15 10:11:57 2003
+++ php4/main/network.c Tue Mar  4 20:28:45 2003
@@ -16,7 +16,7 @@
    | Streams work by Wez Furlong <[EMAIL PROTECTED]>                   |
    +----------------------------------------------------------------------+
  */
-/* $Id: network.c,v 1.83.2.3 2003/02/15 15:11:57 wez Exp $ */
+/* $Id: network.c,v 1.83.2.4 2003/03/05 01:28:45 wez Exp $ */
 
 /*#define DEBUG_MAIN_NETWORK 1*/
 
@@ -97,6 +97,10 @@
 
 #include "ext/standard/file.h"
 
+#if HAVE_OPENSSL_EXT
+static int handle_ssl_error(php_stream *stream, int nr_bytes TSRMLS_DC);
+#endif
+
 #ifdef PHP_WIN32
 # define SOCK_ERR INVALID_SOCKET
 # define SOCK_CONN_ERR SOCKET_ERROR
@@ -715,15 +719,20 @@
                }
        }
 
-       if (activate)   {
-               if (SSL_connect(sock->ssl_handle) <= 0) {
+       if (activate) {
+               int err;
+
+               do {
+                       err = SSL_connect(sock->ssl_handle);
+               } while (err != 1 && handle_ssl_error(stream, err TSRMLS_CC)); 
+               
+               if (err != 1) {
                        php_error_docref(NULL TSRMLS_CC, E_WARNING, 
"php_stream_sock_ssl_activate_with_method: SSL handshake/connection failed");
                        SSL_shutdown(sock->ssl_handle);
                        return FAILURE;
                }
                sock->ssl_active = activate;
-       }
-       else    {
+       } else {
                SSL_shutdown(sock->ssl_handle);
                sock->ssl_active = 0;
        }
@@ -827,10 +836,10 @@
                                memcpy(wptr, esbuf, code + 1);
                                wptr += code;
                        }
-
+                       
                        php_error_docref(NULL TSRMLS_CC, E_WARNING,
                                        "SSL operation failed with code %d.%s%s",
-                                       err,
+                                       err, 
                                        ebuf ? "OpenSSL Error messages:\n" : "",
                                        ebuf ? ebuf : "");
                                
@@ -845,7 +854,7 @@
 static size_t php_sockop_write(php_stream *stream, const char *buf, size_t count 
TSRMLS_DC)
 {
        php_netstream_data_t *sock = (php_netstream_data_t*)stream->abstract;
-       size_t didwrite;
+       int didwrite;
        
 #if HAVE_OPENSSL_EXT
        if (sock->ssl_active) {
@@ -927,7 +936,7 @@
 static size_t php_sockop_read(php_stream *stream, char *buf, size_t count TSRMLS_DC)
 {
        php_netstream_data_t *sock = (php_netstream_data_t*)stream->abstract;
-       size_t nr_bytes = 0;
+       int nr_bytes = 0;
 
 #if HAVE_OPENSSL_EXT
        if (sock->ssl_active) {
Index: php4/main/streams.c
diff -u php4/main/streams.c:1.125.2.35 php4/main/streams.c:1.125.2.36
--- php4/main/streams.c:1.125.2.35      Tue Mar  4 11:20:24 2003
+++ php4/main/streams.c Tue Mar  4 20:28:45 2003
@@ -20,7 +20,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: streams.c,v 1.125.2.35 2003/03/04 16:20:24 iliaa Exp $ */
+/* $Id: streams.c,v 1.125.2.36 2003/03/05 01:28:45 wez Exp $ */
 
 #define _GNU_SOURCE
 #include "php.h"
@@ -637,7 +637,7 @@
 
 PHPAPI int _php_stream_getc(php_stream *stream TSRMLS_DC)
 {
-       char buf;
+       unsigned char buf;
 
        if (php_stream_read(stream, &buf, 1) > 0) {
                return buf & 0xff;



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

Reply via email to