summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornpmccallum <npmccallum@c587cffe-e639-0410-9787-d7902ae8ed56>2007-10-16 00:25:24 +0000
committernpmccallum <npmccallum@c587cffe-e639-0410-9787-d7902ae8ed56>2007-10-16 00:25:24 +0000
commit074dfc7e4f16746a129513fb544182765f717c35 (patch)
tree5d6bbff35aa41d8c8eb62f0c75f2994afc9fb4cd
parent293f6b5801d87558c31a67f8f8d314d840c79141 (diff)
downloadlibproxy-074dfc7e4f16746a129513fb544182765f717c35.tar.gz
crasher fixes
git-svn-id: http://libproxy.googlecode.com/svn/trunk@15 c587cffe-e639-0410-9787-d7902ae8ed56
-rw-r--r--src/lib/dns.c13
-rw-r--r--src/lib/misc.c6
-rw-r--r--src/lib/proxy_factory.c18
-rw-r--r--src/lib/proxy_factory.h2
-rw-r--r--src/lib/url.c2
5 files changed, 21 insertions, 20 deletions
diff --git a/src/lib/dns.c b/src/lib/dns.c
index a3ee1a7..f67da83 100644
--- a/src/lib/dns.c
+++ b/src/lib/dns.c
@@ -79,13 +79,16 @@ get_domain_name()
// Lookup the hostname
struct hostent *host_info = gethostbyname(tmp);
- px_free(tmp); tmp = NULL;
- if (!host_info) return NULL;
+ if (host_info)
+ {
+ px_free(tmp);
+ tmp = px_strdup(host_info->h_name);
+ }
// Get domain portion
- if (!strchr(host_info->h_name, '.')) return NULL;
- if (!strcmp(".", strchr(host_info->h_name, '.'))) return NULL;
- return px_strdup(strchr(host_info->h_name, '.') + 1);
+ if (!strchr(tmp, '.')) return NULL;
+ if (!strcmp(".", strchr(tmp, '.'))) return NULL;
+ return px_strdup(strchr(tmp, '.') + 1);
}
static pxURL **
diff --git a/src/lib/misc.c b/src/lib/misc.c
index 3c77f82..b8b4fae 100644
--- a/src/lib/misc.c
+++ b/src/lib/misc.c
@@ -99,8 +99,10 @@ px_strjoin(const char **strv, const char *delimiter)
// Do the join
char *str = px_malloc0(length);
for (int i=0 ; strv[i]; i++)
- sprintf(str, "%s%s%s", str, strv[i], delimiter);
- str[strlen(str) - strlen(delimiter)] = 0;
+ {
+ strcat(str, strv[i]);
+ if (strv[i+1]) strcat(str, delimiter);
+ }
return str;
}
diff --git a/src/lib/proxy_factory.c b/src/lib/proxy_factory.c
index 3c6d02f..ef89abd 100644
--- a/src/lib/proxy_factory.c
+++ b/src/lib/proxy_factory.c
@@ -91,11 +91,7 @@ px_proxy_factory_new ()
// Open the plugin dir
DIR *plugindir = opendir(PLUGIN_DIR);
- if (!plugindir)
- {
- px_proxy_factory_free(self);
- return NULL;
- }
+ if (!plugindir) return self;
// Count the number of plugins
for (i=0 ; readdir(plugindir) ; i++);
@@ -211,7 +207,7 @@ px_proxy_factory_get_proxy (pxProxyFactory *self, char *url)
if (!realurl) goto do_return;
// Call the events
- for (int i=0 ; self->on_get_proxy[i] ; i++)
+ for (int i=0 ; self->on_get_proxy && self->on_get_proxy[i] ; i++)
self->on_get_proxy[i](self);
// Get the configuration order
@@ -223,7 +219,7 @@ px_proxy_factory_get_proxy (pxProxyFactory *self, char *url)
strcat(tmp, ",");
}
else
- order = px_malloc0(strlen(DEFAULT_CONFIG_ORDER) + 1);
+ tmp = px_malloc0(strlen(DEFAULT_CONFIG_ORDER) + 1);
strcat(tmp, DEFAULT_CONFIG_ORDER);
order = px_strsplit(tmp, ",");
px_free(tmp);
@@ -242,7 +238,7 @@ px_proxy_factory_get_proxy (pxProxyFactory *self, char *url)
else
category = PX_CONFIG_CATEGORY_NONE;
- for (int j=0 ; self->configs[j] && !config ; j++)
+ for (int j=0 ; self->configs && self->configs[j] && !config ; j++)
{
if (category != PX_CONFIG_CATEGORY_NONE && self->configs[j]->category == category)
config = self->configs[j]->callback(self);
@@ -253,7 +249,7 @@ px_proxy_factory_get_proxy (pxProxyFactory *self, char *url)
px_strfreev(order);
// No config was found via search order, call all plugins
- for (int i=0 ; self->configs[i] && !config ; i++)
+ for (int i=0 ; self->configs && self->configs[i] && !config ; i++)
config = self->configs[i]->callback(self);
// No plugin returned a valid config, fall back to 'wpad://'
@@ -302,7 +298,7 @@ px_proxy_factory_get_proxy (pxProxyFactory *self, char *url)
if (self->pac_runner)
{
px_strfreev(response);
- response = _format_pac_response(self->pac_runner(self, self->pac, url, px_url_get_host(realurl)));
+ response = _format_pac_response(self->pac_runner(self, self->pac, realurl));
}
// No PAC runner found, fall back to direct
@@ -349,7 +345,7 @@ px_proxy_factory_get_proxy (pxProxyFactory *self, char *url)
if (self->pac_runner)
{
px_strfreev(response);
- response = _format_pac_response(self->pac_runner(self, self->pac, url, px_url_get_host(realurl)));
+ response = _format_pac_response(self->pac_runner(self, self->pac, realurl));
}
else
fprintf(stderr, "*** PAC found, but no active PAC runner! Falling back to direct...\n");
diff --git a/src/lib/proxy_factory.h b/src/lib/proxy_factory.h
index 1c78791..8cb22c4 100644
--- a/src/lib/proxy_factory.h
+++ b/src/lib/proxy_factory.h
@@ -51,7 +51,7 @@ typedef struct _pxConfig pxConfig;
typedef void (*pxProxyFactoryVoidCallback) (pxProxyFactory *self);
typedef bool (*pxProxyFactoryBoolCallback) (pxProxyFactory *self);
typedef void *(*pxProxyFactoryPtrCallback) (pxProxyFactory *self);
-typedef char *(*pxPACRunnerCallback) (pxProxyFactory *self, const pxPAC *pac, const char *url, const char *hostname);
+typedef char *(*pxPACRunnerCallback) (pxProxyFactory *self, const pxPAC *pac, const pxURL *url);
bool px_proxy_factory_config_add (pxProxyFactory *self, char *name, pxConfigCategory category, pxProxyFactoryPtrCallback callback);
bool px_proxy_factory_config_del (pxProxyFactory *self, char *name);
diff --git a/src/lib/url.c b/src/lib/url.c
index ba35f2b..b4793b9 100644
--- a/src/lib/url.c
+++ b/src/lib/url.c
@@ -134,7 +134,7 @@ static int
px_url_get_default_port(pxURL *self)
{
struct servent *serv;
- if ((serv = getservbyname(self->scheme, NULL))) return ntohl(serv->s_port);
+ if ((serv = getservbyname(self->scheme, NULL))) return ntohs(serv->s_port);
return 0;
}