curl-library
RE: Stack smashed when linked with pthreads
Date: Fri, 28 Jul 2006 16:44:39 -0700
Well, going back and looking at the change, the hack wasn't as extensive as
I remembered. This patch is generated off the current CVS tree:
--- mprintf_orig.c 2006-07-06 06:33:56.000000000 -0700
+++ mprintf.c 2006-07-28 16:36:07.453125000 -0700
@@ -606,14 +606,24 @@
long param; /* current parameter to read */
long param_num=0; /* parameter counter */
- va_stack_t vto[MAX_PARAMETERS];
- char *endpos[MAX_PARAMETERS];
+ va_stack_t *vto /*[MAX_PARAMETERS]*/;
+ char **endpos /*[MAX_PARAMETERS]*/;
char **end;
char work[BUFFSIZE];
va_stack_t *p;
+ vto = (va_stack_t *)calloc( MAX_PARAMETERS, sizeof(va_stack_t) );
+ endpos = (char **)calloc( MAX_PARAMETERS, sizeof(char *) );
+
+ if ( !vto || !endpos )
+ {
+ free( vto );
+ free( endpos );
+ return 0;
+ }
+
/* Do the actual %-code parsing */
dprintf_Pass1((char *)format, vto, endpos, ap_save);
@@ -982,6 +992,9 @@
f = *end++; /* goto end of %-code */
}
+ free( vto );
+ free( endpos );
+
return done;
}
** End of patch **
This assumes that the implementation of free() accepts a null argument,
which is normally the convention.
Enjoy, for what it's worth!
Gary Maxwell
Casabi, Inc.
-----Original Message-----
From: Gary Maxwell [mailto:gmaxwell_at_casabi.com]
Sent: Friday, July 28, 2006 4:04 PM
To: 'libcurl development'
Subject: RE: Stack smashed when linked with pthreads
We recently ported libcurl to an embedded ARM system with microscopic thread
stacks (3-4 kbytes typical) and ran into this problem.
I traced it down to the mprintf module, where local stack frames are large
and the functions can be called recursively. I hacked a change so that the
large stack frame objects were allocated off the heap (heap space is not an
issue), and that solved the problem.
I haven't considered submitting a patch, unless there is general hue and cry
for one.
Gary Maxwell
Casabi
-----Original Message-----
From: Dan Fandrich [mailto:dan_at_coneharvesters.com]
Sent: Friday, July 28, 2006 3:49 PM
To: curl-library_at_cool.haxx.se
Subject: Re: Stack smashed when linked with pthreads
On Fri, Jul 28, 2006 at 03:58:34PM -0500, Marshall Crocker wrote:
> Hmm...that may be it. I'm not exactly sure of my stack size but I am
> using the linux-tiny patches for the 2.6 kernel which may very well
> reduce the size below the default 8K. I assume 8K would be big enough
> to handle curl and pthreads right?
8K is very small. There is at least one place in the curl app where a 64K
buffer is put onto the stack, and I wouldn't be surprised if there are
buffers in the KB range in libcurl. Some of the call stacks can get pretty
deep, so I'd be surprised if you *didn't* see stack overflows at 8K.
>>> Dan
-- http://www.MoveAnnouncer.com The web change of address service Let webmasters know that your web site has movedReceived on 2006-07-29