From c32cf33a16d31eeff9a66a1e73ce58b6791dd54d Mon Sep 17 00:00:00 2001 From: Patrick Monnerat Date: Mon, 15 Jun 2009 10:15:28 +0000 Subject: Replaced use of standard C library rand()/srand() by our own pseudo-random number generator. --- lib/formdata.c | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) (limited to 'lib/formdata.c') diff --git a/lib/formdata.c b/lib/formdata.c index f2a4892bf..8538e9f91 100644 --- a/lib/formdata.c +++ b/lib/formdata.c @@ -108,6 +108,12 @@ Content-Disposition: form-data; name="FILECONTENT" /* Length of the random boundary string. */ #define BOUNDARY_LENGTH 40 +/* Private pseudo-random number seed. Unsigned integer >= 32bit. Threads + mutual exclusion is not implemented to acess it since we do not require + high quality random numbers (only used in form boudary generation). */ + +static unsigned int randseed; + #if !defined(CURL_DISABLE_HTTP) || defined(USE_SSLEAY) #include @@ -1597,6 +1603,8 @@ int main(int argc, argv_item_t argv[]) (void) argc; (void) argv; + Curl_srand(); /* Because we do not call curl_global_init() here. */ + if(FormAddTest("simple COPYCONTENTS test", &httppost, &last_post, CURLFORM_COPYNAME, name1, CURLFORM_COPYCONTENTS, value1, CURLFORM_END)) @@ -1733,8 +1741,6 @@ void curl_formfree(struct curl_httppost *form) char *Curl_FormBoundary(void) { char *retstring; - static int randomizer; /* this is just so that two boundaries within - the same form won't be identical */ size_t i; static const char table16[]="0123456789abcdef"; @@ -1744,12 +1750,10 @@ char *Curl_FormBoundary(void) if(!retstring) return NULL; /* failed */ - srand((unsigned int)time(NULL)+randomizer++); /* seed */ - strcpy(retstring, "----------------------------"); for(i=strlen(retstring); i> 16) & 0xFFFF); +} + +void Curl_srand(void) +{ + /* Randomize pseudo-random number sequence. */ + + randseed = (unsigned int) time(NULL); + Curl_rand(); + Curl_rand(); + Curl_rand(); +} -- cgit v1.2.3