$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
1998-12-03 Nathan Bryant <bryant@cs.usm.maine.edu>
* webserver.c: warning fix
-
a = client_gets(sock, buf);
if (a<1) return(-1);
} else {
- strcpy(buf, hold);
+ safestrncpy(buf, hold, SIZ);
}
strcpy(hold, "");
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 */
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
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);
}
/*
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");
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));
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);
}
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) {
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);
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;