aboutsummaryrefslogtreecommitdiff
path: root/src/Redirect.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/Redirect.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/Redirect.c')
-rw-r--r--src/Redirect.c70
1 files changed, 33 insertions, 37 deletions
diff --git a/src/Redirect.c b/src/Redirect.c
index 32cee44..56141cf 100644
--- a/src/Redirect.c
+++ b/src/Redirect.c
@@ -26,6 +26,7 @@
#include "http_Content.h"
#include "http_Redirect.h"
+#include "http_SString.h"
static const char *rcsid = "$Header$";
@@ -72,31 +73,27 @@ static char httpmaster[1024];
@@*/
+#define ADDRLEN 1024
+
int HTTP_SetupRedirect(int port,
int queue_size,
int hunt)
{
- int retval;
+ int retval = 0;
/* should not hunt */
int i;
- char hostnm[1024];
+ char hostnm[ADDRLEN] = EMPTYSTRING;
char *alladdr;
- int addrlen;
- int nprocs;
- int proc;
-
- addrlen = 1024;
- nprocs = CCTK_nProcs(NULL);
- proc = CCTK_MyProc(NULL);
- retval = 0;
+ int nprocs = CCTK_nProcs(NULL);
+ int proc = CCTK_MyProc(NULL);
#ifdef HTTPD_DEBUG
CCTK_INFO("enter setup redirect------------");
#endif
- memset(hostnm,0,addrlen);
- Util_GetHostName(hostnm, addrlen);
- alladdr = (char *) calloc (addrlen, nprocs);
+ memset(hostnm,0,sizeof(hostnm));
+ Util_GetHostName(hostnm, sizeof(hostnm));
+ alladdr = (char *) calloc (sizeof(hostnm), nprocs);
#ifdef CCTK_MPI
{ /* push stack */
@@ -104,8 +101,8 @@ int HTTP_SetupRedirect(int port,
CCTK_INFO("all gather");
#endif
- MPI_Allgather(hostnm,addrlen,MPI_CHAR,
- alladdr,addrlen,MPI_CHAR,
+ MPI_Allgather(hostnm,sizeof(hostnm),MPI_CHAR,
+ alladdr,sizeof(hostnm),MPI_CHAR,
MPI_COMM_WORLD);
#ifdef HTTPD_DEBUG
CCTK_INFO("collected");
@@ -125,7 +122,7 @@ int HTTP_SetupRedirect(int port,
#ifdef HTTPD_DEBUG
printf("Cycle through %u\n",i);
#endif
- if(!strcmp(alladdr+i*addrlen,hostnm))
+ if(!strcmp(alladdr+i*sizeof(hostnm),hostnm))
{
/* we matched addresses */
if(i<proc || i==0)
@@ -288,36 +285,35 @@ static void RegisterRedirect(void)
static int RedirectPage(const cGH *cctkGH, httpRequest *request, void *data)
{
- int retval;
- char message[1024];
+ int retval = -1;
+ String *message = String_New();
/* avoid compiler warning about unused parameter */
data = data;
- /* Status message */
- strcpy(message,"HTTP/1.0 200 OK\r\n");
-
- HTTP_Write(request, message, strlen(message));
-
- /* Content-Type */
- strcpy(message,"Content-Type: text/html\r\n\r\n");
-
- HTTP_Write(request, message, strlen(message));
+ SendHTTP_OK_Header(request);
/* Start the page */
- strcpy(message,"<HTML><HEAD><TITLE>Server Redirect</TITLE>\n");
+ SetToCString(message,"<html><head><title>Server Redirect</title>\n");
/* Write out the main header part */
- HTTP_Write(request, message, strlen(message));
- sprintf(message,"<META http-equiv=\"refresh\" content=\"1; URL=http://%s:%u\"></HEAD><body>\n",
- HTTP_Master(), (unsigned int) HTTP_Port());
- HTTP_Write(request,message,strlen(message));
+ Send_HTTP_String(request, message);
+ SetToCString(message,"<meta http-equiv=\"refresh\" content=\"1; URL=http://");
+ ConcatCString(message,HTTP_Master());
+ ConcatCString(message, ":");
+ ConcatDecimal(message,(unsigned int) HTTP_Port());
+ ConcatCString(message, "\" />\n</head>\n<body>\n");
+ Send_HTTP_String(request,message);
/* ********** Server Redirect To Master ************* */
- sprintf(message,"<p><h1>Redirect to master host=%s:%u</h1><p>\n",
- HTTP_Master(), (unsigned int) HTTP_Port());
- HTTP_Write(request,message,strlen(message));
+ SetToCString(message,"<h1>Redirect to master host=");
+ ConcatCString(message,HTTP_Master());
+ ConcatCString(message, ":");
+ ConcatDecimal(message,(unsigned int) HTTP_Port());
+ ConcatCString(message, "</h1>\n");
+ Send_HTTP_String(request,message);
- HTTP_ContentFooter(cctkGH, 0, sizeof (message), message);
- retval = HTTP_Write(request, message, strlen(message));
+ SetHTML_ContentFooter(cctkGH, 0, message);
+ retval = Send_HTTP_String(request, message);
+ String_Delete( message );
return retval;
}