On 2014-05-10 17:46, Andy Bradford wrote:
Thus said Gerald Gutierrez on Sat, 10 May 2014 01:53:56 -0700:
frame #8: 0x0000000105719ba2 fossil`ssl_receive(NotUsed=<unavailable>,
pContent=<unavailable>, N=<unavailable>) + 50 at http_ssl.c:399
396 size_t got;
397 size_t total = 0;
398 while( N>0 ){
-> 399 got = BIO_read(iBio, pContent, N);
400 if( got<=0 ) break;
401 total += got;
402 N -= got;
I'm not sure if it is the course of the problem but got = unsigned,
So when bio_read returns -1 got is a big number because by definition it
cannot go below 0;
on my machine if i declare
int l=-1;
size_t r = l;
printf("l = %d r = l = %zu\n",l,r);
l = -1 r =l = 18446744073709551615
N cannot go below 0 also subtracting got in this case will only yield 0
by coincidence.
the 3rd argument to bio_read is listed as an int on my machine int is 4
bytes and size_t is 8 bytes
depending on input this can go wrong with sufficient values not fitting
in a int .
e.g.
this fits in an int, 0x10000000
this does not fits in an int, 0x100000000 e.g the int will be 0
changing ssl_receive to
/*
** Receive content back from the SSL connection.
*/
size_t ssl_receive(void *NotUsed, void *pContent, size_t N){
ssize_t got;
size_t total = 0;
while( N>0 ){
got = BIO_read(iBio, pContent, N <= INT_MAX ? N : INT_MAX);
if( got<=0 ) break;
total += got;
N -= got;
pContent = (void*)&((char*)pContent)[got];
}
return total;
}
will yield better results (I hope) because I cannot test it I attached a
unified patch.
I patched http_socket.c and http_ssl.c against the latest of the trunk.
I wonder if it solves your problem?
--
Rene
--- http_socket.c
+++ http_socket.c
@@ -182,14 +182,14 @@
/*
** Send content out over the open socket connection.
*/
size_t socket_send(void *NotUsed, void *pContent, size_t N){
- size_t sent;
+ ssize_t sent;
size_t total = 0;
while( N>0 ){
- sent = send(iSocket, pContent, N, 0);
+ sent = send(iSocket, pContent, N>SSIZE_MAX ?SSIZE_MAX:N , 0);
if( sent<=0 ) break;
total += sent;
N -= sent;
pContent = (void*)&((char*)pContent)[sent];
}
--- http_ssl.c
+++ http_ssl.c
@@ -444,19 +444,19 @@
cert = PEM_read_bio_X509(mem, NULL, 0, NULL);
free(zCert);
BIO_free(mem);
return cert;
}
-
+#include <limits.h>
/*
** Send content out over the SSL connection.
*/
size_t ssl_send(void *NotUsed, void *pContent, size_t N){
- size_t sent;
+ ssize_t sent;
size_t total = 0;
while( N>0 ){
- sent = BIO_write(iBio, pContent, N);
+ sent = BIO_write(iBio, pContent,N <= INT_MAX ? N : INT_MAX);
if( sent<=0 ) break;
total += sent;
N -= sent;
pContent = (void*)&((char*)pContent)[sent];
}
@@ -465,18 +465,18 @@
/*
** Receive content back from the SSL connection.
*/
size_t ssl_receive(void *NotUsed, void *pContent, size_t N){
- size_t got;
+ ssize_t got;
size_t total = 0;
while( N>0 ){
- got = BIO_read(iBio, pContent, N);
+ got = BIO_read(iBio, pContent, N <= INT_MAX ? N : INT_MAX);
if( got<=0 ) break;
total += got;
N -= got;
pContent = (void*)&((char*)pContent)[got];
}
return total;
}
#endif /* FOSSIL_ENABLE_SSL */
_______________________________________________
fossil-users mailing list
fossil-users@lists.fossil-scm.org
http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users