On Mon, Oct 04, 1999, Aidas Kasparas wrote:
> I used experimental code to be able to put files (using POST method, of
> course) and authenticate users using client certificates. Server crashed
> most of times (standard 1.3.9 + only mod_ssl 2.4.5) with Segmentation
> fault.
>
> Traceing lead to problem in the ssl_engine_io.c file. Attached patch
> hopefully fixes this problem (altought no guarantees) - at least my
> server does not crashes any more
You're right, the ``if (ss->buflen < len)'' was incorrect, of course. But to
reduce the amount of memory consumption we should be really carefully. So I
took your advice and tried a second attempt which also tries to fix the
problem and tries to safe memory a little bit more. My proposed patch (against
a plain ssl_engine_io.c from 2.4.5) is appended. Please try this out and give
me feedback whether it works for you. Thanks for your efforts.
Ralf S. Engelschall
[EMAIL PROTECTED]
www.engelschall.com
Index: ssl_engine_io.c
===================================================================
RCS file: /e/modssl/cvs/mod_ssl/pkg.apache/src/modules/ssl/ssl_engine_io.c,v
retrieving revision 1.25
diff -u -r1.25 ssl_engine_io.c
--- ssl_engine_io.c 1999/07/29 09:46:13 1.25
+++ ssl_engine_io.c 1999/10/05 10:16:35
@@ -161,18 +161,35 @@
if ((ss = ap_ctx_get(r->ctx, "ssl::io::suck")) == NULL)
return;
- if (((ss->bufptr+ss->buflen)-(ss->pendptr+ss->pendlen)) < len) {
- /* "expand" buffer */
+ if (((ss->bufptr + ss->buflen) - (ss->pendptr + ss->pendlen)) < len) {
+ /* "expand" buffer: actually we cannot really expand the buffer
+ here, because Apache's pool system doesn't support expanding chunks
+ of memory. Instead we have to either reuse processed data or
+ allocate a new chunk of memory in advance if we really need more
+ memory. */
int newlen;
char *newptr;
- if (ss->buflen < len)
- newlen = ss->buflen * 2;
- else
- newlen = ss->buflen + len;
- newptr = ap_palloc(r->pool, newlen);
- memcpy(newptr, ss->bufptr, ss->buflen);
- ss->bufptr = newptr;
- ss->buflen = newlen;
+
+ if (( (ss->pendptr - ss->bufptr)
+ + ((ss->bufptr + ss->buflen) - (ss->pendptr + ss->pendlen)) ) < len) {
+ /* make memory available by reusing already processed data */
+ memmove(ss->bufptr, ss->pendptr, ss->pendlen);
+ ss->pendptr = ss->bufptr;
+ }
+ else {
+ /* too bad, we have to allocate a new larger buffer */
+ if (len < 8192)
+ newlen = ss->buflen + (4 * len);
+ else if (len < 16384)
+ newlen = ss->buflen + (2 * len);
+ else
+ newlen = ss->buflen + len;
+ newptr = ap_palloc(r->pool, newlen);
+ ss->bufptr = newptr;
+ ss->buflen = newlen;
+ memcpy(ss->bufptr, ss->pendptr, ss->pendlen);
+ ss->pendptr = ss->bufptr;
+ }
}
memcpy(ss->pendptr+ss->pendlen, buf, len);
ss->pendlen += len;
______________________________________________________________________
Apache Interface to OpenSSL (mod_ssl) www.modssl.org
User Support Mailing List [EMAIL PROTECTED]
Automated List Manager [EMAIL PROTECTED]