aboutsummaryrefslogtreecommitdiff
path: root/src/Steer.c
diff options
context:
space:
mode:
authorswhite <swhite@1faa4e14-9dd3-4be0-9f0e-ffe519881164>2004-04-06 17:45:14 +0000
committerswhite <swhite@1faa4e14-9dd3-4be0-9f0e-ffe519881164>2004-04-06 17:45:14 +0000
commit89b88d27b20641e04cd1c2714c299d8908822b54 (patch)
tree5b31770e8864f4d6f0953acbe24af5cc80d43730 /src/Steer.c
parent3ccc27cd1bf0912054213a88798b088010173f1e (diff)
Regarding Cactus bug report 1632 "HTTPD contains buffer overflows"
1) Got rid of most strcat/sprintf into automatic array, replaced with a String module that allocates dynamic memory on the heap. 2) Went a long way toward initializing all variables. 3) Tested: Ran two copies with same parfile except different port, one with my changes, one with original. Went through different kinds of pages by hand, checked by eye. 4) Tried to make HTML XHTML 1.0-compliant. Checked with Amaya. One problem: How to deal with raw less-than characters, etc. Made a function to convert them to HTML Character Entities, but isn't clear this will work properly in the forms. So I left these symbols in the forms. 5) Also checked with more primitive browsers, lynx and dillo. 6) Marked a few instances of questionable code with 'SW' To do ----- Document a few new functions, esp. in Content.c git-svn-id: http://svn.cactuscode.org/arrangements/CactusConnect/HTTPD/trunk@187 1faa4e14-9dd3-4be0-9f0e-ffe519881164
Diffstat (limited to 'src/Steer.c')
-rw-r--r--src/Steer.c53
1 files changed, 17 insertions, 36 deletions
diff --git a/src/Steer.c b/src/Steer.c
index 4433187..8556777 100644
--- a/src/Steer.c
+++ b/src/Steer.c
@@ -84,12 +84,9 @@ static pthread_mutex_t steer_mutex = PTHREAD_MUTEX_INITIALIZER;
@@*/
int HTTP_SteerQueue(const char *thorn, const char *parameter, const char *value)
{
- int retval;
- int buffer_length;
- int parameter_length;
- char *tmp;
-
- retval = 0;
+ int retval = -1;
+ int buffer_length = 0;
+ int parameter_length = 0;
#ifdef CCTK_PTHREADS
pthread_mutex_lock(&steer_mutex);
@@ -102,7 +99,7 @@ int HTTP_SteerQueue(const char *thorn, const char *parameter, const char *value)
if(buffer_length+parameter_length+1 > queuebuffer_size)
{
- tmp = (char *)realloc(queuebuffer, buffer_length+parameter_length+1);
+ char *tmp = (char *)realloc(queuebuffer, buffer_length+parameter_length+1);
if(tmp)
{
@@ -110,10 +107,6 @@ int HTTP_SteerQueue(const char *thorn, const char *parameter, const char *value)
queuebuffer_size = buffer_length+parameter_length+1;
retval = 0;
}
- else
- {
- retval = -1;
- }
}
if(!retval)
@@ -182,9 +175,9 @@ int HTTP_SteerDispatch(void)
static int CommunicateBuffer(void)
{
#ifdef CCTK_MPI
- int rank;
- int nprocs;
- int buffer_size;
+ int rank = 0;
+ int nprocs = 1;
+ int buffer_size = 0;
CCTK_INT8 transmit_buffer_size;
/* Work out how many processes there are. */
@@ -287,24 +280,18 @@ static int CommunicateBuffer(void)
@@*/
static int SteerParameters(void)
{
- int retval;
-
- char *token;
- char *thorn;
- char *parameter;
- char *value;
-
- retval = 0;
+ int retval = 0;
+ char *value = NULL;
if(queuebuffer)
{
- token = strtok(queuebuffer, "\n");
+ char *token = strtok(queuebuffer, "\n");
while(token)
{
- thorn = token;
+ char *thorn = token;
- parameter = strchr(token, ':');
+ char *parameter = strchr(token, ':');
if(parameter)
{
@@ -379,16 +366,14 @@ static int SteerParameters(void)
static void ByteSwap(void *buf,int nelements,int elementsize)
{
#ifndef WORDS_BIGENDIAN
- char *buffer;
+ char *buffer=(char *)buf;
int i;
int s,d;
-
- buffer=(char *)buf;
for(i=0;i<nelements;i++,buffer+=elementsize)
{
/* do the swap thing on each element */
- for(s=0,d=elementsize-1;s<d;s++,d--)
+ for(s=0, d=elementsize-1; s < d; s++,d--)
{
char c=buffer[s];
buffer[s]=buffer[d];
@@ -403,12 +388,10 @@ static void ByteSwap(void *buf,int nelements,int elementsize)
int CCTK_ParameterSet(char *parameter, char *thorn, char *value)
{
- int rank;
+ int rank = 0;
#ifdef CCTK_MPI
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
-#else
- rank = 0;
#endif
fprintf(stderr, "%d - %s::%s='%s'\n", rank, thorn, parameter, value);
@@ -419,8 +402,8 @@ int CCTK_ParameterSet(char *parameter, char *thorn, char *value)
int main(int argc, char *argv[])
{
int i;
- int rank;
- char value[20];
+ int rank = 0;
+ char value[20] = {'\0'};
#ifdef CCTK_MPI
MPI_Init(&argc, &argv);
@@ -428,8 +411,6 @@ int main(int argc, char *argv[])
#ifdef CCTK_MPI
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
-#else
- rank = 0;
#endif
for(i = 0; i < 6; i++)