Compare commits

..
1 Commits
Author SHA1 Message Date
cvs2svn 1736b918ec This commit was manufactured by cvs2svn to create tag 'rel_1-4-2'. 2001-08-29 15:56:49 +00:00
11 changed files with 126 additions and 103 deletions

No files matched your search

-36
View File
@@ -1,39 +1,3 @@
2001-09-04 Robert James Kaes <rjkaes@flarenet.com>
* src/reqs.c (process_client_headers): Moved the skip header test
in front of the compare_header() function.
* src/ternary.c (ternary_search): Switched to doing case
insensitive searching.
* src/log.c (log_message): Thanks to NeilK for finding and fixing
a problem with the syslog code which can lead to a format string
attack.
2001-08-30 Robert James Kaes <rjkaes@flarenet.com>
* src/dnscache.c: Removed the insert_data() function and replaced
the "replace" logic in dns_insert() with a call to
ternary_replace(). This fixes the segmentation fault problem which
I introduced when I "tried" to fix the memory leak. Also changed
the LOCKing to be around the entire dnscache() again since I still
need to work out how locking should be done when accessing the
ternary tree.
* src/ternary.c (ternary_insert_replace): Renamed ternary_insert()
to ternary_insert_replace() and added a extra argument. The
function can now "replace" data already in the tree without
causing a memory leak. Added two DEFINES to make coding easier:
ternary_insert() and ternary_replace() which both call this
function with the right arguments.
* src/utils.c: Removed xstrstr() since it was only used in one
place, and could be safely replaced with strstr. I can't even
remember why we had this function to begin with.
* src/reqs.c (compare_header): Removed the call to xstrstr() since
it's been removed from the source.
2001-08-28 Robert James Kaes <rjkaes@flarenet.com> 2001-08-28 Robert James Kaes <rjkaes@flarenet.com>
* src/log.c (log_message): Handle a debug enabled compile better. * src/log.c (log_message): Handle a debug enabled compile better.
+19 -20
View File
@@ -1,26 +1,25 @@
Tuesday, September 4, 2001 Wednesday, August 29, 2001
-------------------------- --------------------------
I finally fixed a problem with the anonymous header code. The searches There has been a tonne of work done on tinyproxy since the beginning
are now all case insensitive. This fixes a problem where the spelling of last week. I have been releasing minor-minor-minor point releases,
of the HTTP headers could be different. It also helps with various but the changes in this release constitute a minor-minor point
spellings of domain names. There is also a security fix for a format release. Please see the ChangeLog for detail descriptions of all the
string problem with the syslog feature. This problem doesn't affect changes, but here is a brief list.
you if you use the log file instead.
-- Robert The most serious fix is to the DNS caching system. There was a memory
leak in the system whenever a domain was already in the database, but
had expired. The new domain information was placed in the database,
but the old information wasn't freed.
The second change is in regard to the regular expression library. For
a while now tinyproxy has included it's own library (the GNU version)
in case the system did not have a working copy. Due to a bug in the
configure.in script the included REGEX library was being used even if
a working copy was detected. This was making tinyproxy larger than it
needed.
Thursday, August 30, 2001 I would suggest that everyone upgrade to this version; especially
------------------------- anyone who is still running 1.4.0 or below.
Maybe I just shouldn't be working on the code base this week. The -- Robert
memory fix I added in the last release contained a serious bug which
would cause a segmentation fault. I actually fixed this by removing
the code I added and just fixing the problem in ternary_insert()
instead. I don't know why I didn't do this in the first place. I also
removed the xstrstr() function since strstr() will do what tinyproxy
needs. Removing code is _always_ a good idea. Less code, less chance
of bugs.
-- Robert
+2 -2
View File
@@ -1,4 +1,4 @@
dnl $Id: configure.in,v 1.25 2001-09-04 16:52:04 rjkaes Exp $ dnl $Id: configure.in,v 1.23 2001-08-29 15:29:29 rjkaes Exp $
dnl Devlopers, please strive to achieve this order: dnl Devlopers, please strive to achieve this order:
dnl dnl
@@ -19,7 +19,7 @@ AC_INIT()
AC_CANONICAL_SYSTEM AC_CANONICAL_SYSTEM
AC_DEFINE_UNQUOTED(TARGET_SYSTEM, "$target") AC_DEFINE_UNQUOTED(TARGET_SYSTEM, "$target")
AM_INIT_AUTOMAKE(tinyproxy,1.4.2.2) AM_INIT_AUTOMAKE(tinyproxy,1.4.2)
AM_CONFIG_HEADER(config.h) AM_CONFIG_HEADER(config.h)
dnl dnl
+2 -3
View File
@@ -114,7 +114,6 @@ Allow 192.168.1.0/25
# If an Anonymous keyword is present, then anonymous proxying is enabled. # If an Anonymous keyword is present, then anonymous proxying is enabled.
# The headers listed are allowed through, while all others are denied. If # The headers listed are allowed through, while all others are denied. If
# no Anonymous keyword is present, then all header are allowed through. # no Anonymous keyword is present, then all header are allowed through.
# You must include quotes around the headers.
# #
#Anonymous "Host" #Anonymous Host
#Anonymous "Authorization" #Anonymous Authorization
+56 -14
View File
@@ -1,4 +1,4 @@
/* $Id: dnscache.c,v 1.11 2001-08-30 16:50:42 rjkaes Exp $ /* $Id: dnscache.c,v 1.10 2001-08-29 03:57:51 rjkaes Exp $
* *
* This is a caching DNS system. When a host name is needed we look it up here * This is a caching DNS system. When a host name is needed we look it up here
* and see if there is already an answer for it. The domains are placed in a * and see if there is already an answer for it. The domains are placed in a
@@ -51,6 +51,20 @@ struct dnscache_s {
static TERNARY dns_tree = -1; static TERNARY dns_tree = -1;
/*
* Insert the data into the DNS tree.
*/
static int insert_data(char *domain, struct dnscache_s *newptr)
{
int ret;
LOCK();
ret = ternary_insert(dns_tree, domain, newptr);
UNLOCK();
return ret;
}
static int dns_lookup(struct in_addr *addr, char *domain) static int dns_lookup(struct in_addr *addr, char *domain)
{ {
int ret; int ret;
@@ -59,14 +73,17 @@ static int dns_lookup(struct in_addr *addr, char *domain)
assert(addr != NULL); assert(addr != NULL);
assert(domain != NULL); assert(domain != NULL);
LOCK();
ret = ternary_search(dns_tree, domain, (void *)&ptr); ret = ternary_search(dns_tree, domain, (void *)&ptr);
if (TE_ISERROR(ret) if (TE_ISERROR(ret)
|| difftime(time(NULL), ptr->expire) > DNSEXPIRE) { || difftime(time(NULL), ptr->expire) > DNSEXPIRE) {
UNLOCK();
return -1; return -1;
} }
memcpy(addr, &ptr->ipaddr, sizeof(struct in_addr)); memcpy(addr, &ptr->ipaddr, sizeof(struct in_addr));
UNLOCK();
return 0; return 0;
} }
@@ -74,6 +91,7 @@ static int dns_lookup(struct in_addr *addr, char *domain)
static int dns_insert(struct in_addr *addr, char *domain) static int dns_insert(struct in_addr *addr, char *domain)
{ {
struct dnscache_s *newptr; struct dnscache_s *newptr;
int ret;
assert(addr != NULL); assert(addr != NULL);
assert(domain != NULL); assert(domain != NULL);
@@ -87,9 +105,37 @@ static int dns_insert(struct in_addr *addr, char *domain)
memcpy(&newptr->ipaddr, addr, sizeof(struct in_addr)); memcpy(&newptr->ipaddr, addr, sizeof(struct in_addr));
newptr->expire = time(NULL); newptr->expire = time(NULL);
if (TE_ISERROR(ternary_replace(dns_tree, domain, newptr))) { ret = insert_data(domain, newptr);
safefree(newptr);
return -1; if (TE_ISERROR(ret)) {
if (ret == TE_EXISTS) {
/*
* The value already exists. First search for the
* value and then delete the data before inserting
* the new value.
*/
struct dnscache_s *existing;
DEBUG2("[%s] already exists in DNS cache", domain);
LOCK();
ret = ternary_search(dns_tree, domain, (void *)&existing);
UNLOCK();
if (TE_ISERROR(ret))
goto INSERT_ERROR;
safefree(existing);
ret = insert_data(domain, newptr);
if (TE_ISERROR(ret))
goto INSERT_ERROR;
} else {
INSERT_ERROR:
safefree(newptr);
return -1;
}
} }
return 0; return 0;
@@ -102,34 +148,30 @@ int dnscache(struct in_addr *addr, char *domain)
assert(addr != NULL); assert(addr != NULL);
assert(domain != NULL); assert(domain != NULL);
LOCK();
/* If the DNS tree doesn't exist, build a new one */ /* If the DNS tree doesn't exist, build a new one */
LOCK();
if (dns_tree < 0) if (dns_tree < 0)
dns_tree = ternary_new(); dns_tree = ternary_new();
UNLOCK();
if (inet_aton(domain, (struct in_addr *)addr) != 0) { if (inet_aton(domain, (struct in_addr *)addr) != 0)
UNLOCK();
return 0; return 0;
}
/* Well, we're not dotted-decimal so we need to look it up */ /* Well, we're not dotted-decimal so we need to look it up */
if (dns_lookup(addr, domain) == 0) { if (dns_lookup(addr, domain) == 0)
UNLOCK();
return 0; return 0;
}
/* Okay, so not in the list... need to actually look it up. */ /* Okay, so not in the list... need to actually look it up. */
LOCK();
if (!(resolv = gethostbyname(domain))) { if (!(resolv = gethostbyname(domain))) {
UNLOCK(); UNLOCK();
return -1; return -1;
} }
memcpy(addr, resolv->h_addr_list[0], (size_t)resolv->h_length); memcpy(addr, resolv->h_addr_list[0], (size_t)resolv->h_length);
UNLOCK();
dns_insert(addr, domain); dns_insert(addr, domain);
UNLOCK();
return 0; return 0;
} }
+2 -2
View File
@@ -1,4 +1,4 @@
/* $Id: log.c,v 1.14 2001-09-04 16:50:22 rjkaes Exp $ /* $Id: log.c,v 1.13 2001-08-29 03:59:12 rjkaes Exp $
* *
* Logs the various messages which tinyproxy produces to either a log file or * Logs the various messages which tinyproxy produces to either a log file or
* the syslog daemon. Not much to it... * the syslog daemon. Not much to it...
@@ -93,7 +93,7 @@ void log_message(short int level, char *fmt, ...)
vsyslog(level, fmt, args); vsyslog(level, fmt, args);
# else # else
vsnprintf(str, STRING_LENGTH, fmt, args); vsnprintf(str, STRING_LENGTH, fmt, args);
syslog(level, "%s", str); syslog(level, str);
# endif # endif
} else { } else {
#endif #endif
+5 -5
View File
@@ -1,4 +1,4 @@
/* $Id: reqs.c,v 1.19 2001-09-04 18:22:00 rjkaes Exp $ /* $Id: reqs.c,v 1.17 2001-08-28 04:32:14 rjkaes Exp $
* *
* This is where all the work in tinyproxy is actually done. Incoming * This is where all the work in tinyproxy is actually done. Incoming
* connections have a new thread created for them. The thread then * connections have a new thread created for them. The thread then
@@ -326,7 +326,7 @@ static int compare_header(char *line)
char *ptr; char *ptr;
int ret; int ret;
if ((ptr = strstr(line, ":")) == NULL) if ((ptr = xstrstr(line, ":", strlen(line), FALSE)) == NULL)
return -1; return -1;
if ((buffer = malloc(ptr - line + 1)) == NULL) if ((buffer = malloc(ptr - line + 1)) == NULL)
@@ -424,6 +424,9 @@ static int process_client_headers(struct conn_s *connptr)
if (connptr->output_message) if (connptr->output_message)
continue; continue;
if (is_anonymous_enabled() && compare_header(header) < 0)
continue;
/* /*
* Don't send certain headers. * Don't send certain headers.
*/ */
@@ -435,9 +438,6 @@ static int process_client_headers(struct conn_s *connptr)
if (i != (sizeof(skipheaders) / sizeof(char *))) if (i != (sizeof(skipheaders) / sizeof(char *)))
continue; continue;
if (is_anonymous_enabled() && compare_header(header) < 0)
continue;
if (content_length == -1 if (content_length == -1
&& strncasecmp(header, "content-length", 14) == 0) { && strncasecmp(header, "content-length", 14) == 0) {
char *content_ptr = strchr(header, ':') + 1; char *content_ptr = strchr(header, ':') + 1;
+5 -13
View File
@@ -1,4 +1,4 @@
/* $Id: ternary.c,v 1.7 2001-09-04 17:53:41 rjkaes Exp $ /* $Id: ternary.c,v 1.5 2001-05-23 17:59:53 rjkaes Exp $
* *
* This module creates a Ternary Search Tree which can store both string * This module creates a Ternary Search Tree which can store both string
* keys, and arbitrary data for each key. It works similar to a hash, and * keys, and arbitrary data for each key. It works similar to a hash, and
@@ -29,7 +29,6 @@
# include <sys/types.h> # include <sys/types.h>
#endif #endif
#include <ctype.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@@ -295,8 +294,7 @@ int ternary_destroy(TERNARY tno, void (*freeptr)(void *))
* TE_TOOFULL tree is full, so no new elements can be added. * TE_TOOFULL tree is full, so no new elements can be added.
* Exceptions: none * Exceptions: none
*/ */
int ternary_insert_replace(TERNARY tno, const char *s, void *data, int ternary_insert(TERNARY tno, const char *s, void *data)
short int replace)
{ {
int cur; /* index of current tree */ int cur; /* index of current tree */
Ttree *tree; /* pointer to tree structure */ Ttree *tree; /* pointer to tree structure */
@@ -316,13 +314,7 @@ int ternary_insert_replace(TERNARY tno, const char *s, void *data,
while ((pp = *p)) { while ((pp = *p)) {
if ((d = *s - pp->splitchar) == 0) { if ((d = *s - pp->splitchar) == 0) {
if (*s++ == 0) { if (*s++ == 0) {
if (!replace) return TE_EXISTS;
return TE_EXISTS;
else {
free(pp->eqkid);
pp->eqkid = (Tnode *)data;
return TE_NONE;
}
} }
p = &(pp->eqkid); p = &(pp->eqkid);
} else if (d < 0) } else if (d < 0)
@@ -387,9 +379,9 @@ int ternary_search(TERNARY tno, const char *s, void **data)
p = trees[cur]->tree_root; p = trees[cur]->tree_root;
while (p) { while (p) {
if (toupper(*s) < toupper(p->splitchar)) if (*s < p->splitchar)
p = p->lokid; p = p->lokid;
else if (toupper(*s) == toupper(p->splitchar)) { else if (*s == p->splitchar) {
if (*s++ == 0) { if (*s++ == 0) {
if (data) if (data)
*data = (void *)p->eqkid; *data = (void *)p->eqkid;
+2 -6
View File
@@ -1,4 +1,4 @@
/* $Id: ternary.h,v 1.3 2001-08-30 16:52:09 rjkaes Exp $ /* $Id: ternary.h,v 1.2 2000-09-26 04:59:20 rjkaes Exp $
* *
* See 'ternary.c' for a detailed description. * See 'ternary.c' for a detailed description.
* *
@@ -58,11 +58,7 @@ extern char te_errbuf[256];
extern TERNARY ternary_new(void); extern TERNARY ternary_new(void);
extern int ternary_destroy(TERNARY tno, void (*freeptr)(void *)); extern int ternary_destroy(TERNARY tno, void (*freeptr)(void *));
#define ternary_insert(x, y, z) ternary_insert_replace(x, y, z, 0) extern int ternary_insert(TERNARY tno, const char *s, void *data);
#define ternary_replace(x, y, z) ternary_insert_replace(x, y, z, 1)
extern int ternary_insert_replace(TERNARY tno, const char *s, void *data,
short int replace);
extern int ternary_search(TERNARY tno, const char *s, void **data); extern int ternary_search(TERNARY tno, const char *s, void **data);
#endif #endif
+29 -1
View File
@@ -1,4 +1,4 @@
/* $Id: utils.c,v 1.8 2001-08-30 16:52:56 rjkaes Exp $ /* $Id: utils.c,v 1.7 2001-08-28 04:33:54 rjkaes Exp $
* *
* Misc. routines which are used by the various functions to handle strings * Misc. routines which are used by the various functions to handle strings
* and memory allocation and pretty much anything else we can think of. Also, * and memory allocation and pretty much anything else we can think of. Also,
@@ -30,6 +30,34 @@
#include "sock.h" #include "sock.h"
#include "utils.h" #include "utils.h"
/*
* Find the start of the needle in the haystack. Limits the search to less
* than "length" characters. Returns NULL if the needle is not found.
*/
char *xstrstr(char *haystack, char *needle, size_t length,
bool_t case_sensitive)
{
unsigned int i;
/* Used to specify which function to use... need the decl. */
int (*fn) (const char *s1, const char *s2, size_t n);
if (case_sensitive)
fn = strncmp;
else
fn = strncasecmp;
if (strlen(needle) > length)
return NULL;
for (i = 0; i <= length - strlen(needle); i++) {
if ((*fn) (haystack + i, needle, strlen(needle)) == 0)
return (haystack + i);
}
return NULL;
}
/* /*
* Display an error to the client. * Display an error to the client.
*/ */
+4 -1
View File
@@ -1,4 +1,4 @@
/* $Id: utils.h,v 1.6 2001-08-30 16:52:56 rjkaes Exp $ /* $Id: utils.h,v 1.5 2001-08-27 03:45:34 rjkaes Exp $
* *
* See 'utils.h' for a detailed description. * See 'utils.h' for a detailed description.
* *
@@ -21,6 +21,9 @@
#include "tinyproxy.h" #include "tinyproxy.h"
extern char *xstrstr(char *haystack, char *needle, size_t length,
bool_t case_sensitive);
extern int httperr(struct conn_s *connptr, int err, const char *msg); extern int httperr(struct conn_s *connptr, int err, const char *msg);
extern void makedaemon(void); extern void makedaemon(void);