/*
- * $Id: cache_cf.cc,v 1.223 1997/08/25 22:35:50 wessels Exp $
+ * $Id: cache_cf.cc,v 1.224 1997/10/13 22:09:03 kostas Exp $
*
* DEBUG: section 3 Configuration File Parsing
* AUTHOR: Harvest Derived
static void
self_destruct(void)
{
- sprintf(fatal_str, "Bungled %s line %d: %s",
+ snprintf(fatal_str,BUFSIZ, "Bungled %s line %d: %s",
cfg_filename, config_lineno, config_input_line);
fatal(fatal_str);
}
free_all();
default_all();
if ((fp = fopen(file_name, "r")) == NULL) {
- sprintf(fatal_str, "Unable to open configuration file: %s: %s",
+ snprintf(fatal_str, BUFSIZ, "Unable to open configuration file: %s: %s",
file_name, xstrerror());
fatal(fatal_str);
}
vhost_mode = 1;
if (Config.Port.http == NULL)
fatal("No http_port specified!");
- sprintf(ThisCache, "%s:%d (Squid/%s)",
+ snprintf(ThisCache, SQUIDHOSTNAMELEN << 1, "%s:%d (Squid/%s)",
getMyHostname(),
(int) Config.Port.http->i,
SQUID_VERSION);
/*
- * $Id: cachemgr.cc,v 1.60 1997/08/26 17:30:35 wessels Exp $
+ * $Id: cachemgr.cc,v 1.61 1997/10/13 22:09:04 kostas Exp $
*
* DEBUG: section 0 CGI Cache Manager
* AUTHOR: Harvest Derived
#include "ansiproto.h"
#include "util.h"
+#include "snprintf.h"
#define MAX_ENTRIES 10000
if (then < 0)
return "NEVER";
if (delta < ONE_MINUTE)
- sprintf(buf, "%ds", (int) (delta / ONE_SECOND));
+ snprintf(buf, 128, "%ds", (int) (delta / ONE_SECOND));
else if (delta < ONE_HOUR)
- sprintf(buf, "%dm", (int) (delta / ONE_MINUTE));
+ snprintf(buf, 128, "%dm", (int) (delta / ONE_MINUTE));
else if (delta < ONE_DAY)
- sprintf(buf, "%dh", (int) (delta / ONE_HOUR));
+ snprintf(buf, 128, "%dh", (int) (delta / ONE_HOUR));
else if (delta < ONE_WEEK)
- sprintf(buf, "%dD", (int) (delta / ONE_DAY));
+ snprintf(buf, 128, "%dD", (int) (delta / ONE_DAY));
else if (delta < ONE_MONTH)
- sprintf(buf, "%dW", (int) (delta / ONE_WEEK));
+ snprintf(buf, 128, "%dW", (int) (delta / ONE_WEEK));
else if (delta < ONE_YEAR)
- sprintf(buf, "%dM", (int) (delta / ONE_MONTH));
+ snprintf(buf, 128, "%dM", (int) (delta / ONE_MONTH));
else
- sprintf(buf, "%dY", (int) (delta / ONE_YEAR));
- sprintf(buf2, fmt, buf);
+ snprintf(buf, 128, "%dY", (int) (delta / ONE_YEAR));
+ snprintf(buf2,128, fmt, buf);
return buf2;
}
/* convert hostname:portnum to host=hostname&port=portnum */
if (*s && !strchr(s, '=') && !strchr(s, '&')) {
char *p;
- buffer = xmalloc(strlen(s) + sizeof "host=&port=");
+ int len_buff=strlen(s) + sizeof "host=&port=";
+ buffer = xmalloc(len_buff);
if ((p = strchr(s, ':')))
if (p != s) {
*p = '\0';
- sprintf(buffer, "host=%s&port=%s", s, p + 1);
+ snprintf(buffer, len_buff,"host=%s&port=%s", s, p + 1);
} else {
- sprintf(buffer, "port=%s", p + 1);
+ snprintf(buffer, len_buff, "port=%s", p + 1);
} else
- sprintf(buffer, "host=%s", s);
+ snprintf(buffer, len_buff, "host=%s", s);
} else {
buffer = xstrdup(s);
}
case STATS_NETDB:
case PCONN:
case SHUTDOWN:
- sprintf(msg, "GET cache_object://%s/%s@%s HTTP/1.0\r\n\r\n",
+ snprintf(msg, 1024, "GET cache_object://%s/%s@%s HTTP/1.0\r\n\r\n",
hostname, op_cmds[op], password);
break;
case REFRESH:
- sprintf(msg, "GET %s HTTP/1.0\r\nPragma: no-cache\r\nAccept: */*\r\n\r\n", url);
+ snprintf(msg, 1024, "GET %s HTTP/1.0\r\nPragma: no-cache\r\nAccept: */*\r\n\r\n", url);
break;
#ifdef REMOVE_OBJECT
case REMOVE:
/*
- * $Id: client.cc,v 1.29 1997/08/25 23:45:24 wessels Exp $
+ * $Id: client.cc,v 1.30 1997/10/13 22:09:05 kostas Exp $
*
* DEBUG: section 0 WWW Client
* AUTHOR: Harvest Derived
fprintf(stderr, "client: ERROR: Cannot connect to %s:%d: Host unknown.\n", hostname, port);
} else {
char tbuf[BUFSIZ];
- sprintf(tbuf, "client: ERROR: Cannot connect to %s:%d",
+ snprintf(tbuf, BUFSIZ, "client: ERROR: Cannot connect to %s:%d",
hostname, port);
perror(tbuf);
}
exit(1);
}
/* Build the HTTP request */
- sprintf(msg, "%s %s HTTP/1.0\r\n", method, url);
+ snprintf(msg, BUFSIZ, "%s %s HTTP/1.0\r\n", method, url);
if (reload) {
- sprintf(buf, "Pragma: no-cache\r\n");
+ snprintf(buf, BUFSIZ, "Pragma: no-cache\r\n");
strcat(msg, buf);
}
if (opt_noaccept == 0) {
- sprintf(buf, "Accept: */*\r\n");
+ snprintf(buf, BUFSIZ, "Accept: */*\r\n");
strcat(msg, buf);
}
if (ims) {
- sprintf(buf, "If-Modified-Since: %s\r\n", mkrfc1123(ims));
+ snprintf(buf, BUFSIZ, "If-Modified-Since: %s\r\n", mkrfc1123(ims));
strcat(msg, buf);
}
if (max_forwards > -1) {
- sprintf(buf, "Max-Forwards: %d\r\n", max_forwards);
+ snprintf(buf, BUFSIZ, "Max-Forwards: %d\r\n", max_forwards);
strcat(msg, buf);
}
if (keep_alive) {
- sprintf(buf, "Proxy-Connection: Keep-Alive\r\n");
+ snprintf(buf, BUFSIZ, "Proxy-Connection: Keep-Alive\r\n");
strcat(msg, buf);
}
- sprintf(buf, "\r\n");
+ snprintf(buf, BUFSIZ, "\r\n");
strcat(msg, buf);
/* Send the HTTP request */
/*
- * $Id: client_side.cc,v 1.125 1997/08/25 23:45:25 wessels Exp $
+ * $Id: client_side.cc,v 1.126 1997/10/13 22:09:05 kostas Exp $
*
* DEBUG: section 33 Client-side Routines
* AUTHOR: Duane Wessels
LOCAL_ARRAY(char, buf, 8192);
size_t len;
memset(buf, '\0', 8192);
- sprintf(buf, "HTTP/1.0 200 OK\r\n");
- sprintf(line, "Date: %s\r\n", mkrfc1123(squid_curtime));
+ snprintf(buf, 8192, "HTTP/1.0 200 OK\r\n");
+ snprintf(line, 256, "Date: %s\r\n", mkrfc1123(squid_curtime));
strcat(buf, line);
- sprintf(line, "Server: Squid/%s\r\n", SQUID_VERSION);
+ snprintf(line, 256, "Server: Squid/%s\r\n", SQUID_VERSION);
strcat(buf, line);
- sprintf(line, "Content-Type: message/http\r\n");
+ snprintf(line, 256, "Content-Type: message/http\r\n");
strcat(buf, line);
strcat(buf, "\r\n");
len = strlen(buf);
/*
- * $Id: debug.cc,v 1.51 1997/07/26 04:48:27 wessels Exp $
+ * $Id: debug.cc,v 1.52 1997/10/13 22:09:06 kostas Exp $
*
* DEBUG: section 0 Debug Routines
* AUTHOR: Harvest Derived
if (debug_log == NULL)
return;
- sprintf(f, "%s| %s",
+ snprintf(f, BUFSIZ, "%s| %s",
accessLogTime(squid_curtime),
format);
#if HAVE_SYSLOG
/* level 0 go to syslog */
if (_db_level == 0 && opt_syslog_enable) {
tmpbuf[0] = '\0';
- vsprintf(tmpbuf, format, args);
+ vsnprintf(tmpbuf, BUFSIZ, format, args);
tmpbuf[1023] = '\0';
syslog(LOG_ERR, "%s", tmpbuf);
}
/* Rotate numbers 0 through N up one */
for (i = Config.Log.rotateNumber; i > 1;) {
i--;
- sprintf(from, "%s.%d", debug_log_file, i - 1);
- sprintf(to, "%s.%d", debug_log_file, i);
+ snprintf(from, MAXPATHLEN, "%s.%d", debug_log_file, i - 1);
+ snprintf(to, MAXPATHLEN, "%s.%d", debug_log_file, i);
rename(from, to);
}
/* Rotate the current log to .0 */
if (Config.Log.rotateNumber > 0) {
- sprintf(to, "%s.%d", debug_log_file, 0);
+ snprintf(to, MAXPATHLEN, "%s.%d", debug_log_file, 0);
rename(debug_log_file, to);
}
/* Close and reopen the log. It may have been renamed "manually"
/*
- * $Id: dns.cc,v 1.40 1997/08/10 06:34:28 wessels Exp $
+ * $Id: dns.cc,v 1.41 1997/10/13 22:09:06 kostas Exp $
*
* DEBUG: section 34 Dnsserver interface
* AUTHOR: Harvest Derived
s++;
else
s = prg;
- sprintf(fd_note_buf, "%s #%d", s, dns_child_table[k]->id);
+ snprintf(fd_note_buf,FD_DESC_SZ, "%s #%d", s, dns_child_table[k]->id);
fd_note(dns_child_table[k]->inpipe, fd_note_buf);
commSetNonBlocking(dns_child_table[k]->inpipe);
debug(34, 3) ("dnsOpenServers: 'dns_server' %d started\n", k);
/*
- * $Id: dnsserver.cc,v 1.34 1997/07/16 20:32:03 wessels Exp $
+ * $Id: dnsserver.cc,v 1.35 1997/10/13 22:09:07 kostas Exp $
*
* DEBUG: section 0 DNS Resolver
* AUTHOR: Harvest Derived
exit(0);
break;
case 'd':
- sprintf(buf, "dnsserver.%d.log", (int) getpid());
+ snprintf(buf, 256, "dnsserver.%d.log", (int) getpid());
logfile = fopen(buf, "a");
do_debug++;
if (!logfile)
msg[0] = '\0';
if (!result) {
if (h_errno == TRY_AGAIN) {
- sprintf(msg, "Name Server for domain '%s' is unavailable.\n",
+ snprintf(msg, 1024, "Name Server for domain '%s' is unavailable.\n",
request);
} else {
- sprintf(msg, "DNS Domain '%s' is invalid: %s.\n",
+ snprintf(msg, 1024, "DNS Domain '%s' is invalid: %s.\n",
request, my_h_msgs(h_errno));
}
}
/*
- * $Id: errorpage.cc,v 1.69 1997/08/25 22:35:54 wessels Exp $
+ * $Id: errorpage.cc,v 1.70 1997/10/13 22:09:08 kostas Exp $
*
* DEBUG: section 4 Error Generation
* AUTHOR: Duane Wessels
case 'z':
p = err->dnsserver_msg;
break;
+ case 'e':
+ snprintf(buf, CVT_BUF_SZ, "%d", err->errno);
+ p=buf;
+ break;
+ case 'E':
+ snprintf(buf, CVT_BUF_SZ, "(%d) %s", err->errno, xstrerror());
+ break;
/*
- * e - errno
- * E - strerror()
+ * e - errno x
+ * E - strerror() x
* t - local time
* T - UTC
* c - Squid error code
/*
- * $Id: fqdncache.cc,v 1.59 1997/08/25 23:45:26 wessels Exp $
+ * $Id: fqdncache.cc,v 1.60 1997/10/13 22:09:08 kostas Exp $
*
* DEBUG: section 35 FQDN Cache
* AUTHOR: Harvest Derived
if (f->status != FQDN_PENDING)
debug_trap("fqdncache_dnsDispatch: status != FQDN_PENDING");
buf = xcalloc(1, 256);
- sprintf(buf, "%1.254s\n", f->name);
+ snprintf(buf, 256, "%1.254s\n", f->name);
dns->flags |= DNS_FLAG_BUSY;
dns->data = f;
f->status = FQDN_DISPATCHED;
debug_trap("fqdncacheChangeKey: hash_remove_link() failed\n");
return;
}
- sprintf(new_key, "%d/", ++index);
+ snprintf(new_key, 256, "%d/", ++index);
strncat(new_key, f->name, 128);
debug(14, 1) ("fqdncacheChangeKey: from '%s' to '%s'\n", f->name, new_key);
safe_free(f->name);
/*
- * $Id: ftp.cc,v 1.136 1997/07/28 06:40:55 wessels Exp $
+ * $Id: ftp.cc,v 1.137 1997/10/13 22:09:09 kostas Exp $
*
* DEBUG: section 9 File Transfer Protocol (FTP)
* AUTHOR: Harvest Derived
continue;
p->type = *tokens[0];
p->size = atoi(tokens[i - 1]);
- sprintf(sbuf, "%s %2s %5s",
+ snprintf(sbuf, 128, "%s %2s %5s",
tokens[i], tokens[i + 1], tokens[i + 2]);
if (!strstr(buf, sbuf))
- sprintf(sbuf, "%s %2s %-5s",
+ snprintf(sbuf, 128, "%s %2s %-5s",
tokens[i], tokens[i + 1], tokens[i + 2]);
if ((t = strstr(buf, sbuf))) {
p->date = xstrdup(sbuf);
p->type = '-';
p->size = atoi(tokens[2]);
}
- sprintf(sbuf, "%s %s", tokens[0], tokens[1]);
+ snprintf(sbuf, 128, "%s %s", tokens[0], tokens[1]);
p->date = xstrdup(sbuf);
p->name = xstrdup(tokens[3]);
}
ftpListParts *parts;
/* check .. as special case */
if (!strcmp(line, "..")) {
- sprintf(icon, "<IMG BORDER=0 SRC=\"%s%s\" ALT=\"%-6s\">",
+ snprintf(icon, 2048, "<IMG BORDER=0 SRC=\"%s%s\" ALT=\"%-6s\">",
"http://internal.squid/icons/",
ICON_DIRUP,
"[DIR]");
- sprintf(link, "<A HREF=\"%s\">%s</A>", "../", "Parent Directory");
- sprintf(html, "%s %s\n", icon, link);
+ snprintf(link, 2048, "<A HREF=\"%s\">%s</A>", "../", "Parent Directory");
+ snprintf(html, 8192, "%s %s\n", icon, link);
return html;
}
if (strlen(line) > 1024) {
- sprintf(html, "%s\n", line);
+ snprintf(html, 8192, "%s\n", line);
return html;
}
if ((parts = ftpListParseParts(line, flags)) == NULL) {
- sprintf(html, "%s\n", line);
+ snprintf(html, 8192, "%s\n", line);
return html;
}
if (!strcmp(parts->name, ".") || !strcmp(parts->name, "..")) {
ename = xstrdup(rfc1738_escape(parts->name));
switch (parts->type) {
case 'd':
- sprintf(icon, "<IMG SRC=\"%s%s\" ALT=\"%-6s\">",
+ snprintf(icon, 2048, "<IMG SRC=\"%s%s\" ALT=\"%-6s\">",
"http://internal.squid/icons/",
ICON_MENU,
"[DIR]");
- sprintf(link, "<A HREF=\"%s/\">%s</A>%s",
+ snprintf(link, 2048, "<A HREF=\"%s/\">%s</A>%s",
ename,
parts->showname,
dots_fill(strlen(parts->showname)));
- sprintf(html, "%s %s [%s]\n",
+ snprintf(html, 8192, "%s %s [%s]\n",
icon,
link,
parts->date);
break;
case 'l':
- sprintf(icon, "<IMG SRC=\"%s%s\" ALT=\"%-6s\">",
+ snprintf(icon, 2048, "<IMG SRC=\"%s%s\" ALT=\"%-6s\">",
"http://internal.squid/icons/",
ICON_LINK,
"[LINK]");
- sprintf(link, "<A HREF=\"%s\">%s</A>%s",
+ snprintf(link, 2048, "<A HREF=\"%s\">%s</A>%s",
ename,
parts->showname,
dots_fill(strlen(parts->showname)));
- sprintf(html, "%s %s [%s]\n",
+ snprintf(html, 8192, "%s %s [%s]\n",
icon,
link,
parts->date);
break;
case '-':
default:
- sprintf(icon, "<IMG SRC=\"%s%s\" ALT=\"%-6s\">",
+ snprintf(icon, 2048, "<IMG SRC=\"%s%s\" ALT=\"%-6s\">",
"http://internal.squid/icons/",
mimeGetIcon(parts->name),
"[FILE]");
- sprintf(link, "<A HREF=\"%s\">%s</A>%s",
+ snprintf(link, 2048, "<A HREF=\"%s\">%s</A>%s",
ename,
parts->showname,
dots_fill(strlen(parts->showname)));
- sprintf(html, "%s %s [%s] %6dk\n",
+ snprintf(html, 8192, "%s %s [%s] %6dk\n",
icon,
link,
parts->date,
}
strcat(t, request->host);
if (request->port != urlDefaultPort(PROTO_FTP))
- sprintf(&t[strlen(t)], ":%d", request->port);
+ snprintf(&t[strlen(t)], len-strlen(t), ":%d", request->port);
strcat(t, "/");
if (!EBIT_TEST(ftpState->flags, FTP_ROOT_DIR))
strcat(t, request->urlpath);
if (!ftpCheckAuth(ftpState, request->headers)) {
/* This request is not fully authenticated */
if (request->port == 21) {
- sprintf(realm, "ftp %s", ftpState->user);
+ snprintf(realm,8192, "ftp %s", ftpState->user);
} else {
- sprintf(realm, "ftp %s port %d",
+ snprintf(realm,8192, "ftp %s port %d",
ftpState->user, request->port);
}
response = ftpAuthRequired(request, realm);
if (strstr(ftpState->ctrl.message->key, "NetWare"))
EBIT_SET(ftpState->flags, FTP_SKIP_WHITESPACE);
if (ftpState->proxy_host != NULL)
- sprintf(cbuf, "USER %s@%s\r\n",
+ snprintf(cbuf,1024, "USER %s@%s\r\n",
ftpState->user,
ftpState->request->host);
else
- sprintf(cbuf, "USER %s\r\n", ftpState->user);
+ snprintf(cbuf,1024, "USER %s\r\n", ftpState->user);
ftpWriteCommand(cbuf, ftpState);
ftpState->state = SENT_USER;
} else {
if (code == 230) {
ftpReadPass(ftpState);
} else if (code == 331) {
- sprintf(cbuf, "PASS %s\r\n", ftpState->password);
+ snprintf(cbuf,1024, "PASS %s\r\n", ftpState->password);
ftpWriteCommand(cbuf, ftpState);
ftpState->state = SENT_PASS;
} else {
t = strrchr(ftpState->request->urlpath, '/');
filename = t ? t + 1 : ftpState->request->urlpath;
mode = mimeGetTransferMode(filename);
- sprintf(cbuf, "TYPE %c\r\n", mode);
+ snprintf(cbuf,1024, "TYPE %c\r\n", mode);
ftpWriteCommand(cbuf, ftpState);
ftpState->state = SENT_TYPE;
} else {
ftpSendPasv(ftpState);
return;
}
- sprintf(cbuf, "CWD %s\r\n", w->key);
+ snprintf(cbuf, 1024, "CWD %s\r\n", w->key);
ftpWriteCommand(cbuf, ftpState);
ftpState->state = SENT_CWD;
}
}
wordlistDestroy(&ftpState->pathcomps);
assert(*ftpState->filepath != '\0');
- sprintf(cbuf, "MDTM %s\r\n", ftpState->filepath);
+ snprintf(cbuf, 1024, "MDTM %s\r\n", ftpState->filepath);
ftpWriteCommand(cbuf, ftpState);
ftpState->state = SENT_MDTM;
}
}
assert(ftpState->filepath != NULL);
assert(*ftpState->filepath != '\0');
- sprintf(cbuf, "SIZE %s\r\n", ftpState->filepath);
+ snprintf(cbuf, 1024, "SIZE %s\r\n", ftpState->filepath);
ftpWriteCommand(cbuf, ftpState);
ftpState->state = SENT_SIZE;
}
}
ftpState->data.fd = fd;
commSetTimeout(fd, Config.Timeout.read, ftpTimeout, ftpState);
- sprintf(cbuf, "PASV\r\n");
+ snprintf(cbuf, 1024, "PASV\r\n");
ftpWriteCommand(cbuf, ftpState);
ftpState->state = SENT_PASV;
}
ftpSendPort(ftpState);
return;
}
- sprintf(junk, "%d.%d.%d.%d", h1, h2, h3, h4);
+ snprintf(junk,1024, "%d.%d.%d.%d", h1, h2, h3, h4);
if (!safe_inet_addr(junk, NULL)) {
debug(9, 1) ("unsafe address (%s)\n", junk);
ftpSendPort(ftpState);
{
debug(9, 3) ("This is ftpRestOrList\n");
if (EBIT_TEST(ftpState->flags, FTP_ISDIR)) {
- sprintf(cbuf, "LIST\r\n");
+ snprintf(cbuf, 1024, "LIST\r\n");
ftpWriteCommand(cbuf, ftpState);
ftpState->state = SENT_LIST;
} else if (ftpState->restart_offset > 0) {
- sprintf(cbuf, "REST\r\n");
+ snprintf(cbuf,1024, "REST\r\n");
ftpWriteCommand(cbuf, ftpState);
ftpState->state = SENT_REST;
} else {
assert(ftpState->filepath != NULL);
- sprintf(cbuf, "RETR %s\r\n", ftpState->filepath);
+ snprintf(cbuf,1024, "RETR %s\r\n", ftpState->filepath);
ftpWriteCommand(cbuf, ftpState);
ftpState->state = SENT_RETR;
}
assert(ftpState->restart_offset > 0);
if (code == 350) {
assert(ftpState->filepath != NULL);
- sprintf(cbuf, "RETR %s\r\n", ftpState->filepath);
+ snprintf(cbuf,1024, "RETR %s\r\n", ftpState->filepath);
ftpWriteCommand(cbuf, ftpState);
ftpState->state = SENT_RETR;
} else if (code > 0) {
return;
} else if (!EBIT_TEST(ftpState->flags, FTP_TRIED_NLST)) {
EBIT_SET(ftpState->flags, FTP_TRIED_NLST);
- sprintf(cbuf, "NLST\r\n");
+ snprintf(cbuf, 1024, "NLST\r\n");
ftpWriteCommand(cbuf, ftpState);
ftpState->state = SENT_NLST;
} else {
ftpState->data.fd = -1;
}
assert(ftpState->ctrl.fd > -1);
- sprintf(cbuf, "QUIT\r\n");
+ snprintf(cbuf,1024, "QUIT\r\n");
ftpWriteCommand(cbuf, ftpState);
ftpState->state = SENT_QUIT;
}
/*
- * $Id: gopher.cc,v 1.92 1997/07/28 06:40:56 wessels Exp $
+ * $Id: gopher.cc,v 1.93 1997/10/13 22:09:10 kostas Exp $
*
* DEBUG: section 10 Gopher
* AUTHOR: Harvest Derived
char *ctype = mimeGetContentType(name);
char *cenc = mimeGetContentEncoding(name);
if (cenc)
- sprintf(buf + strlen(buf), "Content-Encoding: %s\r\n", cenc);
- sprintf(buf + strlen(buf), "Content-Type: %s\r\n",
+ snprintf(buf + strlen(buf), MAX_MIME-strlen(buf), "Content-Encoding: %s\r\n", cenc);
+ snprintf(buf + strlen(buf), MAX_MIME-strlen(buf), "Content-Type: %s\r\n",
ctype ? ctype : def_ctype);
}
{
LOCAL_ARRAY(char, tempMIME, MAX_MIME);
- sprintf(tempMIME,
+ snprintf(tempMIME, MAX_MIME,
"HTTP/1.0 200 OK Gatewaying\r\n"
"Server: Squid/%s\r\n"
"Date: %s\r\n"
LOCAL_ARRAY(char, tmpbuf, TEMP_BUF_SIZE);
if (!gopherState->data_in) {
- sprintf(tmpbuf, "<HTML><HEAD><TITLE>Server Return Nothing.</TITLE>\n"
+ snprintf(tmpbuf, TEMP_BUF_SIZE,
+ "<HTML><HEAD><TITLE>Server Return Nothing.</TITLE>\n"
"</HEAD><BODY><HR><H1>Server Return Nothing.</H1></BODY></HTML>\n");
storeAppend(gopherState->entry, tmpbuf, strlen(tmpbuf));
return;
entry = gopherState->entry;
if (gopherState->conversion == HTML_INDEX_PAGE) {
- sprintf(outbuf, "<HTML><HEAD><TITLE>Gopher Index %s</TITLE></HEAD>\n"
+ snprintf(outbuf, TEMP_BUF_SIZE << 4,
+ "<HTML><HEAD><TITLE>Gopher Index %s</TITLE></HEAD>\n"
"<BODY><H1>%s<BR>Gopher Search</H1>\n"
"<p>This is a searchable Gopher index. Use the search\n"
"function of your browser to enter search terms.\n"
return;
}
if (gopherState->conversion == HTML_CSO_PAGE) {
- sprintf(outbuf, "<HTML><HEAD><TITLE>CSO Search of %s</TITLE></HEAD>\n"
+ snprintf(outbuf, TEMP_BUF_SIZE << 4,
+ "<HTML><HEAD><TITLE>CSO Search of %s</TITLE></HEAD>\n"
"<BODY><H1>%s<BR>CSO Search</H1>\n"
"<P>A CSO database usually contains a phonebook or\n"
"directory. Use the search function of your browser to enter\n"
memset(tmpbuf, '\0', TEMP_BUF_SIZE);
if ((gtype == GOPHER_TELNET) || (gtype == GOPHER_3270)) {
if (strlen(escaped_selector) != 0)
- sprintf(tmpbuf, "<IMG BORDER=0 SRC=\"%s\"> <A HREF=\"telnet://%s@%s/\">%s</A>\n",
+ snprintf(tmpbuf, TEMP_BUF_SIZE, "<IMG BORDER=0 SRC=\"%s\"> <A HREF=\"telnet://%s@%s/\">%s</A>\n",
icon_type, escaped_selector, host, name);
else
- sprintf(tmpbuf, "<IMG BORDER=0 SRC=\"%s\"> <A HREF=\"telnet://%s/\">%s</A>\n",
+ snprintf(tmpbuf, TEMP_BUF_SIZE, "<IMG BORDER=0 SRC=\"%s\"> <A HREF=\"telnet://%s/\">%s</A>\n",
icon_type, host, name);
} else {
- sprintf(tmpbuf, "<IMG BORDER=0 SRC=\"%s\"> <A HREF=\"gopher://%s/%c%s\">%s</A>\n",
+ snprintf(tmpbuf, TEMP_BUF_SIZE, "<IMG BORDER=0 SRC=\"%s\"> <A HREF=\"gopher://%s/%c%s\">%s</A>\n",
icon_type, host, gtype, escaped_selector, name);
}
safe_free(escaped_selector);
break;
if (gopherState->cso_recno != recno) {
- sprintf(tmpbuf, "</PRE><HR><H2>Record# %d<br><i>%s</i></H2>\n<PRE>", recno, result);
+ snprintf(tmpbuf,TEMP_BUF_SIZE, "</PRE><HR><H2>Record# %d<br><i>%s</i></H2>\n<PRE>", recno, result);
gopherState->cso_recno = recno;
} else {
- sprintf(tmpbuf, "%s\n", result);
+ snprintf(tmpbuf,TEMP_BUF_SIZE, "%s\n", result);
}
strcat(outbuf, tmpbuf);
gopherState->data_in = 1;
case 502: /* Too Many Matches */
{
/* Print the message the server returns */
- sprintf(tmpbuf, "</PRE><HR><H2>%s</H2>\n<PRE>", result);
+ snprintf(tmpbuf, TEMP_BUF_SIZE, "</PRE><HR><H2>%s</H2>\n<PRE>", result);
strcat(outbuf, tmpbuf);
gopherState->data_in = 1;
break;
char *t;
if (gopherState->type_id == GOPHER_CSO) {
sscanf(gopherState->request, "?%s", query);
- sprintf(buf, "query %s\r\nquit\r\n", query);
+ snprintf(buf, 4096, "query %s\r\nquit\r\n", query);
} else if (gopherState->type_id == GOPHER_INDEX) {
if ((t = strchr(gopherState->request, '?')))
*t = '\t';
- sprintf(buf, "%s\r\n", gopherState->request);
+ snprintf(buf, 4096, "%s\r\n", gopherState->request);
} else {
- sprintf(buf, "%s\r\n", gopherState->request);
+ snprintf(buf, 4096, "%s\r\n", gopherState->request);
}
debug(10, 5) ("gopherSendRequest: FD %d\n", fd);
comm_write(fd,
/*
- * $Id: http.cc,v 1.187 1997/08/26 04:21:19 wessels Exp $
+ * $Id: http.cc,v 1.188 1997/10/13 22:09:11 kostas Exp $
*
* DEBUG: section 11 Hypertext Transfer Protocol (HTTP)
* AUTHOR: Harvest Derived
debug(11, 3) ("httpBuildRequestHeader: INPUT:\n%s\n", hdr_in);
xstrncpy(fwdbuf, "X-Forwarded-For: ", 4096);
xstrncpy(viabuf, "Via: ", 4096);
- sprintf(ybuf, "%s %s HTTP/1.0",
+ snprintf(ybuf, MAX_URL + 32, "%s %s HTTP/1.0",
RequestMethodStr[request->method],
*request->urlpath ? request->urlpath : "/");
httpAppendRequestHeader(hdr_out, ybuf, &len, out_sz, 1);
/* Add IMS header */
if (entry && entry->lastmod && request->method == METHOD_GET) {
- sprintf(ybuf, "If-Modified-Since: %s", mkrfc1123(entry->lastmod));
+ snprintf(ybuf, MAX_URL + 32, "If-Modified-Since: %s", mkrfc1123(entry->lastmod));
httpAppendRequestHeader(hdr_out, ybuf, &len, out_sz, 1);
EBIT_SET(hdr_flags, HDR_IMS);
}
if (orig_request->method == METHOD_TRACE) {
for (s = xbuf + 13; *s && isspace(*s); s++);
n = atoi(s);
- sprintf(xbuf, "Max-Forwards: %d", n - 1);
+ snprintf(xbuf, 4096, "Max-Forwards: %d", n - 1);
}
}
httpAppendRequestHeader(hdr_out, xbuf, &len, out_sz - 512, 1);
}
hdr_len = t - hdr_in;
if (Config.fake_ua && strstr(hdr_out, "User-Agent") == NULL) {
- sprintf(ybuf, "User-Agent: %s", Config.fake_ua);
+ snprintf(ybuf,MAX_URL+32, "User-Agent: %s", Config.fake_ua);
httpAppendRequestHeader(hdr_out, ybuf, &len, out_sz, 0);
}
- /* Append Via: */
- sprintf(ybuf, "%3.1f %s", orig_request->http_ver, ThisCache);
+ /* Append Via: */
+ /* snprintf would fail here too */
+ snprintf(ybuf, MAX_URL+32, "%3.1f %s", orig_request->http_ver, ThisCache);
strcat(viabuf, ybuf);
httpAppendRequestHeader(hdr_out, viabuf, &len, out_sz, 1);
/* Append to X-Forwarded-For: */
strcat(fwdbuf, cfd < 0 ? "unknown" : fd_table[cfd].ipaddr);
httpAppendRequestHeader(hdr_out, fwdbuf, &len, out_sz, 1);
if (!EBIT_TEST(hdr_flags, HDR_HOST)) {
- sprintf(ybuf, "Host: %s", orig_request->host);
+ snprintf(ybuf,MAX_URL+32, "Host: %s", orig_request->host);
httpAppendRequestHeader(hdr_out, ybuf, &len, out_sz, 1);
}
if (!EBIT_TEST(cc_flags, CCC_MAXAGE)) {
url = entry ? entry->url : urlCanonical(orig_request, NULL);
- sprintf(ybuf, "Cache-control: Max-age=%d", (int) getMaxAge(url));
+ snprintf(ybuf, MAX_URL+32, "Cache-control: Max-age=%d", (int) getMaxAge(url));
httpAppendRequestHeader(hdr_out, ybuf, &len, out_sz, 1);
if (request->urlpath) {
assert(strstr(url, request->urlpath));
/* maybe append Connection: Keep-Alive */
if (BIT_TEST(flags, HTTP_KEEPALIVE)) {
if (BIT_TEST(flags, HTTP_PROXYING)) {
- sprintf(ybuf, "Proxy-Connection: Keep-Alive");
+ snprintf(ybuf,MAX_URL+32, "Proxy-Connection: Keep-Alive");
} else {
- sprintf(ybuf, "Connection: Keep-Alive");
+ snprintf(ybuf,MAX_URL+32, "Connection: Keep-Alive");
}
httpAppendRequestHeader(hdr_out, ybuf, &len, out_sz, 1);
}
int l = 0;
int s = HTTP_REPLY_BUF_SZ;
/* argh, ../lib/snprintf.c doesn't support '%f' */
- sprintf(float_buf, "%3.1f", ver);
+ snprintf(float_buf,64, "%3.1f", ver);
assert(strlen(float_buf) == 3);
l += snprintf(buf + l, s - l, "HTTP/%s %d %s\r\n",
float_buf,
/*
- * $Id: icmp.cc,v 1.41 1997/07/16 20:32:08 wessels Exp $
+ * $Id: icmp.cc,v 1.42 1997/10/13 22:09:12 kostas Exp $
*
* DEBUG: section 37 ICMP Routines
* AUTHOR: Duane Wessels
return;
}
if (pid == 0) { /* child */
- char *x = xcalloc(strlen(Config.debugOptions) + 32, 1);
- sprintf(x, "SQUID_DEBUG=%s", Config.debugOptions);
+ int tmp_s;
+ char *x = xcalloc((tmp_s=strlen(Config.debugOptions) + 32), 1);
+ snprintf(x,tmp_s, "SQUID_DEBUG=%s", Config.debugOptions);
putenv(x);
comm_close(icmp_sock);
dup2(child_sock, 0);
/*
- * $Id: ident.cc,v 1.32 1997/07/15 23:23:27 wessels Exp $
+ * $Id: ident.cc,v 1.33 1997/10/13 22:09:14 kostas Exp $
*
* DEBUG: section 30 Ident (RFC 931)
* AUTHOR: Duane Wessels
identCallback(connState);
return;
}
- sprintf(reqbuf, "%d, %d\r\n",
+ snprintf(reqbuf,BUFSIZ, "%d, %d\r\n",
ntohs(connState->peer.sin_port),
ntohs(connState->me.sin_port));
comm_write(fd,
/*
- * $Id: ipcache.cc,v 1.129 1997/08/25 23:45:28 wessels Exp $
+ * $Id: ipcache.cc,v 1.130 1997/10/13 22:09:15 kostas Exp $
*
* DEBUG: section 14 IP Cache
* AUTHOR: Harvest Derived
}
assert(i->status == IP_PENDING);
buf = xcalloc(1, 256);
- sprintf(buf, "%1.254s\n", i->name);
+ snprintf(buf, 256, "%1.254s\n", i->name);
dns->flags |= DNS_FLAG_BUSY;
dns->data = i;
i->status = IP_DISPATCHED;
debug_trap("ipcacheChangeKey: hash_remove_link() failed\n");
return;
}
- sprintf(new_key, "%d/", ++index);
+ snprintf(new_key,256, "%d/", ++index);
strncat(new_key, i->name, 128);
debug(14, 1) ("ipcacheChangeKey: from '%s' to '%s'\n", i->name, new_key);
safe_free(i->name);
/*
- * $Id: mime.cc,v 1.37 1997/08/25 03:51:50 wessels Exp $
+ * $Id: mime.cc,v 1.38 1997/10/13 22:09:16 kostas Exp $
*
* DEBUG: section 25 MIME Parsing
* AUTHOR: Harvest Derived
expiretime = ttl ? t + ttl : 0;
date[0] = expires[0] = last_modified[0] = '\0';
content_length[0] = result[0] = '\0';
- sprintf(date, "Date: %s\r\n", mkrfc1123(t));
+ snprintf(date,100, "Date: %s\r\n", mkrfc1123(t));
if (ttl >= 0)
- sprintf(expires, "Expires: %s\r\n", mkrfc1123(expiretime));
+ snprintf(expires, 100, "Expires: %s\r\n", mkrfc1123(expiretime));
if (lmt)
- sprintf(last_modified, "Last-Modified: %s\r\n", mkrfc1123(lmt));
+ snprintf(last_modified,100, "Last-Modified: %s\r\n", mkrfc1123(lmt));
if (size > 0)
- sprintf(content_length, "Content-Length: %d\r\n", size);
+ snprintf(content_length,100, "Content-Length: %d\r\n", size);
+
+ /* NOTE: don't know size of result thus didn't change
+ to snprintf(). Should be done sometime! */
+
sprintf(result, "Server: %s/%s\r\n%s%s%sContent-Type: %s\r\n%s",
appname,
version_string,
/*
- * $Id: neighbors.cc,v 1.159 1997/08/25 22:35:58 wessels Exp $
+ * $Id: neighbors.cc,v 1.160 1997/10/13 22:09:17 kostas Exp $
*
* DEBUG: section 15 Neighbor Routines
* AUTHOR: Harvest Derived
if (p->type != PEER_MULTICAST)
fatal_dump("peerCountMcastPeersStart: non-multicast peer");
p->mcast.flags &= ~PEER_COUNT_EVENT_PENDING;
- sprintf(url, "http://%s/", inet_ntoa(p->in_addr.sin_addr));
+ snprintf(url, MAX_URL, "http://%s/", inet_ntoa(p->in_addr.sin_addr));
fake = storeCreateEntry(url, url, 0, METHOD_GET);
psstate->request = requestLink(urlParse(METHOD_GET, url));
psstate->entry = fake;
/*
- * $Id: net_db.cc,v 1.48 1997/08/25 23:45:29 wessels Exp $
+ * $Id: net_db.cc,v 1.49 1997/10/13 22:09:17 kostas Exp $
*
* DEBUG: section 37 Network Measurement Database
* AUTHOR: Duane Wessels
net_db_name *x;
struct timeval start = current_time;
int count = 0;
- sprintf(path, "%s/netdb_state", storeSwapDir(0));
+ snprintf(path, SQUID_MAXPATHLEN, "%s/netdb_state", storeSwapDir(0));
fp = fopen(path, "w");
if (fp == NULL) {
debug(50, 1) ("netdbSaveState: %s: %s\n", path, xstrerror());
struct in_addr addr;
int count = 0;
struct timeval start = current_time;
- sprintf(path, "%s/netdb_state", storeSwapDir(0));
+ snprintf(path, SQUID_MAXPATHLEN, "%s/netdb_state", storeSwapDir(0));
fp = fopen(path, "r");
if (fp == NULL)
return;
/*
- * $Id: redirect.cc,v 1.45 1997/07/15 05:34:12 wessels Exp $
+ * $Id: redirect.cc,v 1.46 1997/10/13 22:09:18 kostas Exp $
*
* DEBUG: section 29 Redirector
* AUTHOR: Duane Wessels
if ((fqdn = fqdncache_gethostbyaddr(r->client_addr, 0)) == NULL)
fqdn = dash_str;
buf = get_free_8k_page();
- sprintf(buf, "%s %s/%s %s %s\n",
+ snprintf(buf,8192, "%s %s/%s %s %s\n",
r->orig_url,
inet_ntoa(r->client_addr),
fqdn,
s++;
else
s = prg;
- sprintf(fd_note_buf, "%s #%d",
+ snprintf(fd_note_buf, FD_DESC_SZ, "%s #%d",
s,
redirect_child_table[k]->index + 1);
fd_note(redirect_child_table[k]->fd, fd_note_buf);
/*
- * $Id: send-announce.cc,v 1.42 1997/07/26 04:48:34 wessels Exp $
+ * $Id: send-announce.cc,v 1.43 1997/10/13 22:09:19 kostas Exp $
*
* DEBUG: section 27 Cache Announcer
* AUTHOR: Duane Wessels
}
debug(27, 0) ("Sending Announcement to %s\n", host);
sndbuf[0] = '\0';
- sprintf(tbuf, "cache_version SQUID/%s\n", version_string);
+ snprintf(tbuf,256, "cache_version SQUID/%s\n", version_string);
strcat(sndbuf, tbuf);
assert(Config.Port.http);
- sprintf(tbuf, "Running on %s %d %d\n",
+ snprintf(tbuf,256, "Running on %s %d %d\n",
getMyHostname(),
(int) Config.Port.http->i,
(int) Config.Port.icp);
strcat(sndbuf, tbuf);
if (Config.adminEmail) {
- sprintf(tbuf, "cache_admin: %s\n", Config.adminEmail);
+ snprintf(tbuf,256, "cache_admin: %s\n", Config.adminEmail);
strcat(sndbuf, tbuf);
}
- sprintf(tbuf, "generated %d [%s]\n",
+ snprintf(tbuf, 256, "generated %d [%s]\n",
(int) squid_curtime,
mkhttpdlogtime(&squid_curtime));
strcat(sndbuf, tbuf);
/*
- * $Id: ssl.cc,v 1.61 1997/08/10 04:42:46 wessels Exp $
+ * $Id: ssl.cc,v 1.62 1997/10/13 22:09:20 kostas Exp $
*
* DEBUG: section 26 Secure Sockets Layer Proxy
* AUTHOR: Duane Wessels
{
SslStateData *sslState = data;
debug(26, 3) ("sslProxyConnected: FD %d sslState=%p\n", fd, sslState);
- sprintf(sslState->client.buf, "CONNECT %s HTTP/1.0\r\n\r\n", sslState->url);
+ snprintf(sslState->client.buf, sslState->client.len, "CONNECT %s HTTP/1.0\r\n\r\n", sslState->url);
debug(26, 3) ("sslProxyConnected: Sending 'CONNECT %s HTTP/1.0'\n", sslState->url);
sslState->client.len = strlen(sslState->client.buf);
sslState->client.offset = 0;
/*
- * $Id: stat.cc,v 1.156 1997/08/25 22:36:00 wessels Exp $
+ * $Id: stat.cc,v 1.157 1997/10/13 22:09:20 kostas Exp $
*
* DEBUG: section 18 Cache Manager Statistics
* AUTHOR: Harvest Derived
describeStatuses(const StoreEntry * entry)
{
LOCAL_ARRAY(char, buf, 256);
- sprintf(buf, "%-13s %-13s %-12s %-12s",
+ snprintf(buf,256, "%-13s %-13s %-12s %-12s",
storeStatusStr[entry->store_status],
memStatusStr[entry->mem_status],
swapStatusStr[entry->swap_status],
describeTimestamps(const StoreEntry * entry)
{
LOCAL_ARRAY(char, buf, 256);
- sprintf(buf, "LV:%-9d LU:%-9d LM:%-9d EX:%-9d",
+ snprintf(buf,256, "LV:%-9d LU:%-9d LM:%-9d EX:%-9d",
(int) entry->timestamp,
(int) entry->lastref,
(int) entry->lastmod,
LOCAL_ARRAY(char, buf, 32);
if (f->type != FD_SOCKET)
return null_string;
- sprintf(buf, "%s.%d", f->ipaddr, (int) f->remote_port);
+ snprintf(buf, 32, "%s.%d", f->ipaddr, (int) f->remote_port);
return buf;
}
/*
- * $Id: store.cc,v 1.284 1997/08/25 23:45:30 wessels Exp $
+ * $Id: store.cc,v 1.285 1997/10/13 22:09:22 kostas Exp $
*
* DEBUG: section 20 Storeage Manager
* AUTHOR: Harvest Derived
mem->log_url = xstrdup(e->url);
}
reply = mem->reply;
- sprintf(logmsg, "%9d.%03d %-7s %08X %4d %9d %9d %9d %s %d/%d %s %s\n",
+ snprintf(logmsg, MAX_URL<<1 , "%9d.%03d %-7s %08X %4d %9d %9d %9d %s %d/%d %s %s\n",
(int) current_time.tv_sec,
(int) current_time.tv_usec / 1000,
storeLogTags[tag],
}
debug(20, 3) ("storeGeneratePrivateKey: '%s'\n", url);
key_temp_buffer[0] = '\0';
- sprintf(key_temp_buffer, "%d/%s/%s",
+ snprintf(key_temp_buffer, MAX_URL+100, "%d/%s/%s",
num,
RequestMethodStr[method],
url);
case METHOD_HEAD:
case METHOD_CONNECT:
case METHOD_TRACE:
- sprintf(key_temp_buffer, "/%s/%s", RequestMethodStr[method], url);
+ snprintf(key_temp_buffer,MAX_URL+100, "/%s/%s", RequestMethodStr[method], url);
return key_temp_buffer;
/* NOTREACHED */
break;
fmt = va_arg(args, char *);
#endif
buf[0] = '\0';
- vsprintf(buf, fmt, args);
+ vsnprintf(buf,4096, fmt, args);
storeAppend(e, buf, strlen(buf));
va_end(args);
}
assert(dirn < Config.cacheSwap.n_configured);
if (fd[dirn] < 0)
continue;
- sprintf(line, "%08x %08x %08x %08x %08x %9d %6d %08x %s\n",
+ snprintf(line, 16384, "%08x %08x %08x %08x %08x %9d %6d %08x %s\n",
(int) e->swap_file_number,
(int) e->timestamp,
(int) e->lastref,
/* Rotate numbers 0 through N up one */
for (i = Config.Log.rotateNumber; i > 1;) {
i--;
- sprintf(from, "%s.%d", fname, i - 1);
- sprintf(to, "%s.%d", fname, i);
+ snprintf(from,MAXPATHLEN, "%s.%d", fname, i - 1);
+ snprintf(to, MAXPATHLEN, "%s.%d", fname, i);
rename(from, to);
}
/* Rotate the current log to .0 */
if (Config.Log.rotateNumber > 0) {
- sprintf(to, "%s.%d", fname, 0);
+ snprintf(to,MAXPATHLEN, "%s.%d", fname, 0);
rename(fname, to);
}
storelog_fd = file_open(fname, O_WRONLY | O_CREAT, NULL, NULL);
/*
- * $Id: store_dir.cc,v 1.27 1997/07/16 22:58:26 wessels Exp $
+ * $Id: store_dir.cc,v 1.28 1997/10/13 22:09:23 kostas Exp $
*
* DEBUG: section 47 Store Directory Routines
* AUTHOR: Duane Wessels
if (!fullpath)
fullpath = fullfilename;
fullpath[0] = '\0';
- sprintf(fullpath, "%s/%02X/%02X/%08X",
+ snprintf(fullpath,SQUID_MAXPATHLEN, "%s/%02X/%02X/%08X",
Config.cacheSwap.swapDirs[dirn].path,
filn % Config.cacheSwap.swapDirs[dirn].l1,
filn / Config.cacheSwap.swapDirs[dirn].l1 % Config.cacheSwap.swapDirs[dirn].l2,
if (!fullpath)
fullpath = fullfilename;
fullpath[0] = '\0';
- sprintf(fullpath, "%s/%02X/%02X",
+ snprintf(fullpath,SQUID_MAXPATHLEN, "%s/%02X/%02X",
Config.cacheSwap.swapDirs[dirn].path,
filn % Config.cacheSwap.swapDirs[dirn].l1,
filn / Config.cacheSwap.swapDirs[dirn].l1 % Config.cacheSwap.swapDirs[dirn].l2);
}
safeunlink(path, 1);
if (mkdir(path, 0777) < 0) {
- if (errno != EEXIST) {
+ if (errno != EEXIST) {
+ /* NOTE: couldn't figure size of tmp_error_buf, thus didn't
+ change to snprintf() ... yet */
sprintf(tmp_error_buf, "Failed to create swap directory %s: %s",
path,
xstrerror());
}
debug(47, 1) ("Created directory %s\n", path);
if (stat(path, &sb) < 0 || !S_ISDIR(sb.st_mode)) {
+ /* NOTE: couldn't figure size of tmp_error_buf, thus didn't
+ change to snprintf() ... yet */
sprintf(tmp_error_buf,
"Failed to create directory %s: %s", path, xstrerror());
fatal(tmp_error_buf);
SwapDir *SD = &Config.cacheSwap.swapDirs[j];
LOCAL_ARRAY(char, name, MAXPATHLEN);
for (i = 0; i < SD->l1; i++) {
- sprintf(name, "%s/%02X", SD->path, i);
+ snprintf(name,MAXPATHLEN, "%s/%02X", SD->path, i);
if (storeVerifyOrCreateDir(name) == 0)
continue;
debug(47, 1) ("Making directories in %s\n", name);
for (k = 0; k < SD->l2; k++) {
- sprintf(name, "%s/%02X/%02X", SD->path, i, k);
+ snprintf(name, MAXPATHLEN, "%s/%02X/%02X", SD->path, i, k);
storeVerifyOrCreateDir(name);
}
}
if (BIT_TEST(e->flag, KEY_PRIVATE))
debug(0, 0) ("storeDirSwapLog: PRIVATE: %s\n", e->url);
/* Note this printf format appears in storeWriteCleanLog() too */
- sprintf(logmsg, "%08x %08x %08x %08x %08x %9d %6d %08x %s\n",
+ snprintf(logmsg, MAX_URL << 1 , "%08x %08x %08x %08x %08x %9d %6d %08x %s\n",
(int) e->swap_file_number,
(int) e->timestamp,
(int) e->lastref,
if (Config.Log.swap) {
xstrncpy(path, Config.Log.swap, SQUID_MAXPATHLEN - 64);
strcat(path, ".");
- sprintf(digit, "%02d", dirn);
+ snprintf(digit, 32, "%02d", dirn);
strncat(path, digit, 3);
} else {
xstrncpy(path, storeSwapDir(dirn), SQUID_MAXPATHLEN - 64);
/*
- * $Id: tools.cc,v 1.120 1997/08/25 22:36:03 wessels Exp $
+ * $Id: tools.cc,v 1.121 1997/10/13 22:09:24 kostas Exp $
*
* DEBUG: section 21 Misc Functions
* AUTHOR: Harvest Derived
dead_msg(void)
{
LOCAL_ARRAY(char, msg, 1024);
- sprintf(msg, DEAD_MSG, version_string, version_string);
+ snprintf(msg,1024, DEAD_MSG, version_string, version_string);
return msg;
}
fprintf(fp, "To: %s\n", Config.adminEmail);
fprintf(fp, "Subject: %s\n", dead_msg());
fclose(fp);
- sprintf(command, "mail %s < %s", Config.adminEmail, filename);
+ snprintf(command,256, "mail %s < %s", Config.adminEmail, filename);
system(command); /* XXX should avoid system(3) */
unlink(filename);
}
debug_trap("Could not write pid file");
return;
}
- sprintf(buf, "%d\n", (int) getpid());
+ snprintf(buf,32, "%d\n", (int) getpid());
write(fd, buf, strlen(buf));
file_close(fd);
}
if (rl.rlim_cur > rl.rlim_max)
Squid_MaxFD = rl.rlim_cur = rl.rlim_max;
if (setrlimit(RLIMIT_NOFILE, &rl) < 0) {
+ /* NOTE: couldn't figure size of tmp_error_buf, thus didn't
+ change to snprintf() ... yet */
sprintf(tmp_error_buf, "setrlimit: RLIMIT_NOFILE: %s", xstrerror());
fatal_dump(tmp_error_buf);
}
if (rl.rlim_cur > rl.rlim_max)
Squid_MaxFD = rl.rlim_cur = rl.rlim_max;
if (setrlimit(RLIMIT_OFILE, &rl) < 0) {
+ /* NOTE: couldn't figure size of tmp_error_buf, thus didn't
+ change to snprintf() ... yet */
sprintf(tmp_error_buf, "setrlimit: RLIMIT_OFILE: %s", xstrerror());
fatal_dump(tmp_error_buf);
}
} else if (rl.rlim_max > rl.rlim_cur) {
rl.rlim_cur = rl.rlim_max; /* set it to the max */
if (setrlimit(RLIMIT_DATA, &rl) < 0) {
+ /* NOTE: couldn't figure size of tmp_error_buf, thus didn't
+ change to snprintf() ... yet */
sprintf(tmp_error_buf, "setrlimit: RLIMIT_DATA: %s", xstrerror());
fatal_dump(tmp_error_buf);
}
} else if (rl.rlim_max > rl.rlim_cur) {
rl.rlim_cur = rl.rlim_max; /* set it to the max */
if (setrlimit(RLIMIT_VMEM, &rl) < 0) {
+ /* NOTE: couldn't figure size of tmp_error_buf, thus didn't
+ change to snprintf() ... yet */
sprintf(tmp_error_buf, "setrlimit: RLIMIT_VMEM: %s", xstrerror());
fatal_dump(tmp_error_buf);
}
/*
- * $Id: tunnel.cc,v 1.61 1997/08/10 04:42:46 wessels Exp $
+ * $Id: tunnel.cc,v 1.62 1997/10/13 22:09:20 kostas Exp $
*
* DEBUG: section 26 Secure Sockets Layer Proxy
* AUTHOR: Duane Wessels
{
SslStateData *sslState = data;
debug(26, 3) ("sslProxyConnected: FD %d sslState=%p\n", fd, sslState);
- sprintf(sslState->client.buf, "CONNECT %s HTTP/1.0\r\n\r\n", sslState->url);
+ snprintf(sslState->client.buf, sslState->client.len, "CONNECT %s HTTP/1.0\r\n\r\n", sslState->url);
debug(26, 3) ("sslProxyConnected: Sending 'CONNECT %s HTTP/1.0'\n", sslState->url);
sslState->client.len = strlen(sslState->client.buf);
sslState->client.offset = 0;
/*
- * $Id: url.cc,v 1.63 1997/08/24 01:49:26 wessels Exp $
+ * $Id: url.cc,v 1.64 1997/10/13 22:09:25 kostas Exp $
*
* DEBUG: section 23 URL Parsing
* AUTHOR: Duane Wessels
buf = urlbuf;
switch (request->method) {
case METHOD_CONNECT:
- sprintf(buf, "%s:%d", request->host, request->port);
+ snprintf(buf,MAX_URL, "%s:%d", request->host, request->port);
break;
default:
portbuf[0] = '\0';
if (request->port != urlDefaultPort(request->protocol))
- sprintf(portbuf, ":%d", request->port);
- sprintf(buf, "%s://%s%s%s%s%s",
+ snprintf(portbuf,32, ":%d", request->port);
+ snprintf(buf, MAX_URL, "%s://%s%s%s%s%s",
ProtocolStr[request->protocol],
request->login,
*request->login ? "@" : null_string,
char *t;
switch (request->method) {
case METHOD_CONNECT:
- sprintf(buf, "%s:%d", request->host, request->port);
+ snprintf(buf, MAX_URL, "%s:%d", request->host, request->port);
break;
default:
portbuf[0] = '\0';
if (request->port != urlDefaultPort(request->protocol))
- sprintf(portbuf, ":%d", request->port);
- sprintf(buf, "%s://%s%s%s",
+ snprintf(portbuf,32, ":%d", request->port);
+ snprintf(buf,MAX_URL, "%s://%s%s%s",
ProtocolStr[request->protocol],
request->host,
portbuf,
/*
- * $Id: useragent.cc,v 1.10 1997/07/26 04:48:35 wessels Exp $
+ * $Id: useragent.cc,v 1.11 1997/10/13 22:09:26 kostas Exp $
*
* DEBUG: section 40 User-Agent logging
* AUTHOR: Joe Ramey <ramey@csc.ti.com>
/* Rotate numbers 0 through N up one */
for (i = Config.Log.rotateNumber; i > 1;) {
i--;
- sprintf(from, "%s.%d", fname, i - 1);
- sprintf(to, "%s.%d", fname, i);
+ snprintf(from,MAXPATHLEN, "%s.%d", fname, i - 1);
+ snprintf(to,MAXPATHLEN, "%s.%d", fname, i);
rename(from, to);
}
/* Rotate the current log to .0 */
if (Config.Log.rotateNumber > 0) {
- sprintf(to, "%s.%d", fname, 0);
+ snprintf(to, MAXPATHLEN, "%s.%d", fname, 0);
rename(fname, to);
}
useragentOpenLog();
/*
- * $Id: wais.cc,v 1.80 1997/07/28 06:41:07 wessels Exp $
+ * $Id: wais.cc,v 1.81 1997/10/13 22:09:26 kostas Exp $
*
* DEBUG: section 24 WAIS Relay
* AUTHOR: Harvest Derived
buf = xcalloc(1, len + 1);
if (waisState->request_hdr)
- sprintf(buf, "%s %s %s\r\n", Method, waisState->request,
+ snprintf(buf, len+1, "%s %s %s\r\n", Method, waisState->request,
waisState->request_hdr);
else
- sprintf(buf, "%s %s\r\n", Method, waisState->request);
+ snprintf(buf, len+1, "%s %s\r\n", Method, waisState->request);
debug(24, 6) ("waisSendRequest: buf: %s\n", buf);
comm_write(fd,
buf,