* Numerous memory management bugfixes.
authorArt Cancro <ajc@citadel.org>
Wed, 1 Dec 2004 21:34:17 +0000 (21:34 +0000)
committerArt Cancro <ajc@citadel.org>
Wed, 1 Dec 2004 21:34:17 +0000 (21:34 +0000)
webcit/ChangeLog
webcit/context_loop.c
webcit/subst.c
webcit/tcp_sockets.c
webcit/webcit.c
webcit/webserver.c

index 3cae42833a80247f3325b7c6708bc4bba6625d97..5b74b85f89c5635fcb7a753dc71f72aff32eaf69 100644 (file)
@@ -1,4 +1,7 @@
 $Log$
+Revision 525.3  2004/12/01 21:34:17  ajc
+* Numerous memory management bugfixes.
+
 Revision 525.2  2004/12/01 16:48:24  ajc
 * tools.c: don't crash when striplt() is called with a zero-length string
 
@@ -2115,4 +2118,3 @@ Sun Dec  6 19:50:55 EST 1998 Art Cancro <ajc@uncnsrd.mt-kisco.ny.us>
 
 1998-12-03 Nathan Bryant <bryant@cs.usm.maine.edu>
        * webserver.c: warning fix
-
index 41a468e7a532c23dcad0829b4846cb0a0097d919..482dcfaba847c0651b91520cd3370423e746b362 100644 (file)
@@ -169,7 +169,7 @@ int req_gets(int sock, char *buf, char *hold)
                a = client_gets(sock, buf);
                if (a<1) return(-1);
        } else {
-               strcpy(buf, hold);
+               safestrncpy(buf, hold, SIZ);
        }
        strcpy(hold, "");
 
@@ -287,11 +287,11 @@ void context_loop(int sock)
                hptr->next = NULL;
                last = hptr;
 
-               strcpy(hptr->line, buf);
+               safestrncpy(hptr->line, buf, sizeof hptr->line);
 
        } while (strlen(buf) > 0);
 
-       strcpy(buf, req->line);
+       safestrncpy(buf, req->line, sizeof buf);
        lprintf(5, "HTTP: %s\n", buf);
 
        /* Check for bogus requests */
index 0e9b4e37c2bc01d0d774abbc96f178c28db8044a..c7047771339dc617d5e7699ced56a85141f74bd3 100644 (file)
@@ -58,12 +58,12 @@ void clear_local_substs(void) {
 void svprintf(char *keyname, int keytype, const char *format,...)
 {
        va_list arg_ptr;
-       char wbuf[1024];
+       char wbuf[4096];
        struct wcsubst *ptr = NULL;
        struct wcsubst *scan;
 
        va_start(arg_ptr, format);
-       vsprintf(wbuf, format, arg_ptr);
+       vsnprintf(wbuf, sizeof wbuf, format, arg_ptr);
        va_end(arg_ptr);
 
        /* First scan through to see if we're doing a replacement of
@@ -80,13 +80,12 @@ void svprintf(char *keyname, int keytype, const char *format,...)
        if (ptr == NULL) {
                ptr = (struct wcsubst *) malloc(sizeof(struct wcsubst));
                ptr->next = WC->vars;
+               strcpy(ptr->wcs_key, keyname);
+               WC->vars = ptr;
        }
 
        ptr->wcs_type = keytype;
-       strcpy(ptr->wcs_key, keyname);
-       ptr->wcs_value = malloc(strlen(wbuf)+1);
-       strcpy(ptr->wcs_value, wbuf);
-       WC->vars = ptr;
+       ptr->wcs_value = strdup(wbuf);
 }
 
 /*
index 77867fc4a4487afd94b8b55772481aa6e8f57461..42df6b96f90799888e48a1d05036b5cea458b60f 100644 (file)
@@ -224,7 +224,7 @@ void serv_printf(const char *format,...)
        char buf[SIZ];
 
        va_start(arg_ptr, format);
-       vsprintf(buf, format, arg_ptr);
+       vsnprintf(buf, sizeof buf, format, arg_ptr);
        va_end(arg_ptr);
 
        strcat(buf, "\n");
index 780bf4806643a097618d6cff81b444fc560a55d8..17177b559b103b2dd418393e5ee3e675d80d582a 100644 (file)
@@ -158,7 +158,7 @@ void wprintf(const char *format,...)
        char wbuf[4096];
 
        va_start(arg_ptr, format);
-       vsprintf(wbuf, format, arg_ptr);
+       vsnprintf(wbuf, sizeof wbuf, format, arg_ptr);
        va_end(arg_ptr);
 
        client_write(wbuf, strlen(wbuf));
@@ -386,9 +386,9 @@ void output_headers(int controlcode)
                        WC->wc_password, WC->wc_roomname);
 
        if (print_standard_html_head == 2) {
-               wprintf("Set-cookie: webcit=%s\n", unset);
+               wprintf("Set-cookie: webcit=%s; path=/\n", unset);
        } else {
-               wprintf("Set-cookie: webcit=%s\n", cookie);
+               wprintf("Set-cookie: webcit=%s; path=/\n", cookie);
                if (server_cookie != NULL) {
                        wprintf("%s\n", server_cookie);
                }
@@ -516,7 +516,6 @@ void output_static(char *what)
        char *bigbuffer;
        char content_type[SIZ];
 
-       lprintf(9, "output_static(%s)\n", what);
        sprintf(buf, "static/%s", what);
        fp = fopen(buf, "rb");
        if (fp == NULL) {
@@ -558,7 +557,7 @@ void output_static(char *what)
 
                fstat(fileno(fp), &statbuf);
                bytes = statbuf.st_size;
-               lprintf(3, "Static: %s, %ld bytes\n", what, bytes);
+               lprintf(3, "Static: %s, (%s; %ld bytes)\n", what, content_type, bytes);
                bigbuffer = malloc(bytes + 2);
                fread(bigbuffer, bytes, 1, fp);
                fclose(fp);
index a79d1b8684610569f005195cb88555d4bbb7dadf..a0fc24698b5fdf87a0b9e2fd65650ccae50a2308 100644 (file)
@@ -436,38 +436,11 @@ void worker_entry(void) {
 int lprintf(int loglevel, const char *format, ...)
 {
        va_list ap;
-       char buf[32768];
-
-       va_start(ap, format);
-       vsprintf(buf, format, ap);
-       va_end(ap);
 
        if (loglevel <= verbosity) {
-               struct timeval tv;
-               struct tm *tim;
-               int sess = 0;
-
-               gettimeofday(&tv, NULL);
-               tim = localtime((time_t *)&(tv.tv_sec));
-
-               if (WC) if (WC->wc_session) sess = 1;
-               if (sess) {
-                       fprintf(stderr,
-                               "%04d/%02d/%02d %2d:%02d:%02d.%03ld [%ld:%d] %s",
-                               tim->tm_year + 1900, tim->tm_mon + 1,
-                               tim->tm_mday, tim->tm_hour, tim->tm_min,
-                               tim->tm_sec, (long)tv.tv_usec / 1000,
-                               (long)pthread_self(),
-                               WC->wc_session, buf);
-               } else {
-                       fprintf(stderr,
-                               "%04d/%02d/%02d %2d:%02d:%02d.%03ld [%ld] %s",
-                               tim->tm_year + 1900, tim->tm_mon + 1,
-                               tim->tm_mday, tim->tm_hour, tim->tm_min,
-                               tim->tm_sec, (long)tv.tv_usec / 1000,
-                               (long)pthread_self(),
-                               buf);
-               }
+               va_start(ap, format);
+               vfprintf(stderr, format, ap);
+               va_end(ap);
                fflush(stderr);
        }
        return 1;