mirror of
https://gitlab.xiph.org/xiph/icecast-server.git
synced 2024-11-03 04:17:17 -05:00
fix NULL pointer bug in yp.c for max_listeners. Add checks in config read
to avoid incomplete mount/relay settings svn path=/icecast/branches/kh/icecast/; revision=9554
This commit is contained in:
parent
95b4b3bb4e
commit
ba2e000b4b
153
src/cfgfile.c
153
src/cfgfile.c
@ -113,14 +113,56 @@ void config_init_configuration(ice_config_t *configuration)
|
||||
_set_defaults(configuration);
|
||||
}
|
||||
|
||||
|
||||
static void config_clear_relay (relay_server *relay)
|
||||
{
|
||||
xmlFree (relay->server);
|
||||
xmlFree (relay->mount);
|
||||
xmlFree (relay->localmount);
|
||||
free (relay);
|
||||
}
|
||||
|
||||
|
||||
static void config_clear_mount (mount_proxy *mount)
|
||||
{
|
||||
config_options_t *option;
|
||||
|
||||
xmlFree (mount->mountname);
|
||||
xmlFree (mount->username);
|
||||
xmlFree (mount->password);
|
||||
xmlFree (mount->dumpfile);
|
||||
xmlFree (mount->intro_filename);
|
||||
xmlFree (mount->on_connect);
|
||||
xmlFree (mount->on_disconnect);
|
||||
xmlFree (mount->fallback_mount);
|
||||
xmlFree (mount->stream_name);
|
||||
xmlFree (mount->stream_description);
|
||||
xmlFree (mount->stream_url);
|
||||
xmlFree (mount->stream_genre);
|
||||
xmlFree (mount->bitrate);
|
||||
xmlFree (mount->type);
|
||||
xmlFree (mount->cluster_password);
|
||||
|
||||
xmlFree (mount->auth_type);
|
||||
option = mount->auth_options;
|
||||
while (option)
|
||||
{
|
||||
config_options_t *nextopt = option->next;
|
||||
xmlFree (option->name);
|
||||
xmlFree (option->value);
|
||||
free (option);
|
||||
option = nextopt;
|
||||
}
|
||||
auth_release (mount->auth);
|
||||
free (mount);
|
||||
}
|
||||
|
||||
|
||||
void config_clear(ice_config_t *c)
|
||||
{
|
||||
ice_config_dir_t *dirnode, *nextdirnode;
|
||||
relay_server *relay, *nextrelay;
|
||||
mount_proxy *mount, *nextmount;
|
||||
aliases *alias, *nextalias;
|
||||
int i;
|
||||
config_options_t *option;
|
||||
|
||||
if (c->config_filename)
|
||||
free(c->config_filename);
|
||||
@ -169,53 +211,20 @@ void config_clear(ice_config_t *c)
|
||||
if (c->group) xmlFree(c->group);
|
||||
|
||||
thread_mutex_lock(&(_locks.relay_lock));
|
||||
relay = c->relay;
|
||||
while(relay) {
|
||||
nextrelay = relay->next;
|
||||
xmlFree(relay->server);
|
||||
xmlFree(relay->mount);
|
||||
xmlFree(relay->localmount);
|
||||
free(relay);
|
||||
relay = nextrelay;
|
||||
while (c->relay)
|
||||
{
|
||||
relay_server *to_go = c->relay;
|
||||
c->relay = to_go->next;
|
||||
config_clear_relay (to_go);
|
||||
}
|
||||
thread_mutex_unlock(&(_locks.relay_lock));
|
||||
|
||||
mount = c->mounts;
|
||||
while(mount) {
|
||||
nextmount = mount->next;
|
||||
xmlFree(mount->mountname);
|
||||
xmlFree(mount->username);
|
||||
xmlFree(mount->password);
|
||||
xmlFree(mount->dumpfile);
|
||||
xmlFree(mount->intro_filename);
|
||||
xmlFree(mount->on_connect);
|
||||
xmlFree(mount->on_disconnect);
|
||||
xmlFree(mount->fallback_mount);
|
||||
xmlFree(mount->stream_name);
|
||||
xmlFree(mount->stream_description);
|
||||
xmlFree(mount->stream_url);
|
||||
xmlFree(mount->stream_genre);
|
||||
xmlFree(mount->bitrate);
|
||||
xmlFree(mount->type);
|
||||
if (mount->cluster_password) {
|
||||
xmlFree(mount->cluster_password);
|
||||
}
|
||||
|
||||
xmlFree(mount->auth_type);
|
||||
option = mount->auth_options;
|
||||
while(option) {
|
||||
config_options_t *nextopt = option->next;
|
||||
xmlFree(option->name);
|
||||
xmlFree(option->value);
|
||||
free(option);
|
||||
option = nextopt;
|
||||
}
|
||||
auth_release (mount->auth);
|
||||
|
||||
free(mount);
|
||||
mount = nextmount;
|
||||
while (c->mounts)
|
||||
{
|
||||
mount_proxy *to_go = c->mounts;
|
||||
c->mounts = to_go->next;
|
||||
config_clear_mount (to_go);
|
||||
}
|
||||
|
||||
alias = c->aliases;
|
||||
while(alias) {
|
||||
nextalias = alias->next;
|
||||
@ -535,16 +544,6 @@ static void _parse_mount(xmlDocPtr doc, xmlNodePtr node,
|
||||
mount_proxy *current = configuration->mounts;
|
||||
mount_proxy *last=NULL;
|
||||
|
||||
while(current) {
|
||||
last = current;
|
||||
current = current->next;
|
||||
}
|
||||
|
||||
if(last)
|
||||
last->next = mount;
|
||||
else
|
||||
configuration->mounts = mount;
|
||||
|
||||
/* default <mount> settings */
|
||||
mount->max_listeners = -1;
|
||||
mount->burst_size = -1;
|
||||
@ -672,6 +671,21 @@ static void _parse_mount(xmlDocPtr doc, xmlNodePtr node,
|
||||
doc, node->xmlChildrenNode, 1);
|
||||
}
|
||||
} while ((node = node->next));
|
||||
|
||||
if (mount->mountname == NULL)
|
||||
{
|
||||
config_clear_mount (mount);
|
||||
return;
|
||||
}
|
||||
while(current) {
|
||||
last = current;
|
||||
current = current->next;
|
||||
}
|
||||
|
||||
if(last)
|
||||
last->next = mount;
|
||||
else
|
||||
configuration->mounts = mount;
|
||||
}
|
||||
|
||||
|
||||
@ -680,23 +694,12 @@ static void _parse_relay(xmlDocPtr doc, xmlNodePtr node,
|
||||
{
|
||||
char *tmp;
|
||||
relay_server *relay = calloc(1, sizeof(relay_server));
|
||||
relay_server *current = configuration->relay;
|
||||
relay_server *last=NULL;
|
||||
|
||||
while(current) {
|
||||
last = current;
|
||||
current = current->next;
|
||||
}
|
||||
|
||||
if(last)
|
||||
last->next = relay;
|
||||
else
|
||||
configuration->relay = relay;
|
||||
|
||||
relay->next = NULL;
|
||||
relay->mp3metadata = 1;
|
||||
relay->enable = 1;
|
||||
relay->on_demand = configuration->on_demand;
|
||||
relay->port = 8000;
|
||||
|
||||
do {
|
||||
if (node == NULL) break;
|
||||
@ -743,8 +746,20 @@ static void _parse_relay(xmlDocPtr doc, xmlNodePtr node,
|
||||
if (tmp) xmlFree(tmp);
|
||||
}
|
||||
} while ((node = node->next));
|
||||
|
||||
if (relay->server == NULL)
|
||||
{
|
||||
config_clear_relay (relay);
|
||||
return;
|
||||
}
|
||||
if (relay->mount == NULL)
|
||||
relay->mount = xmlStrdup ("/");
|
||||
|
||||
if (relay->localmount == NULL)
|
||||
relay->localmount = xmlStrdup (relay->mount);
|
||||
|
||||
relay->next = configuration->relay;
|
||||
configuration->relay = relay;
|
||||
}
|
||||
|
||||
static void _parse_listen_socket(xmlDocPtr doc, xmlNodePtr node,
|
||||
@ -1039,6 +1054,8 @@ mount_proxy *config_find_mount (ice_config_t *config, const char *mount)
|
||||
{
|
||||
mount_proxy *mountinfo = config->mounts, *global = NULL;
|
||||
|
||||
if (mount == NULL)
|
||||
return NULL;
|
||||
while (mountinfo)
|
||||
{
|
||||
if (strcmp (mountinfo->mountname, "all") == 0)
|
||||
|
@ -68,7 +68,7 @@
|
||||
#endif
|
||||
|
||||
static fserve_t *active_list = NULL;
|
||||
volatile static fserve_t *pending_list = NULL;
|
||||
static volatile fserve_t *pending_list = NULL;
|
||||
|
||||
static mutex_t pending_lock;
|
||||
static avl_tree *mimetypes = NULL;
|
||||
@ -235,7 +235,7 @@ static void wait_for_fds() {
|
||||
static void *fserv_thread_function(void *arg)
|
||||
{
|
||||
fserve_t *fclient, **trail;
|
||||
int sbytes, bytes;
|
||||
int bytes;
|
||||
|
||||
INFO0("file serving thread started");
|
||||
while (run_fserv)
|
||||
@ -275,7 +275,7 @@ static void *fserv_thread_function(void *arg)
|
||||
}
|
||||
|
||||
/* Now try and send current chunk. */
|
||||
sbytes = format_generic_write_to_client (client);
|
||||
format_generic_write_to_client (client);
|
||||
|
||||
if (client->con->error)
|
||||
{
|
||||
|
21
src/yp.c
21
src/yp.c
@ -85,11 +85,12 @@ typedef struct ypdata_tag
|
||||
static rwlock_t yp_lock;
|
||||
static mutex_t yp_pending_lock;
|
||||
|
||||
volatile static struct yp_server *active_yps = NULL, *pending_yps = NULL;
|
||||
static volatile struct yp_server *active_yps = NULL, *pending_yps = NULL;
|
||||
static volatile int yp_update = 0;
|
||||
static int yp_running;
|
||||
static time_t now;
|
||||
static thread_type *yp_thread;
|
||||
static volatile unsigned client_limit = 0;
|
||||
|
||||
static void *yp_update_thread(void *arg);
|
||||
static void add_yp_info (ypdata_t *yp, void *info, int type);
|
||||
@ -215,6 +216,7 @@ void yp_recheck_config (ice_config_t *config)
|
||||
server->remove = 1;
|
||||
server = server->next;
|
||||
}
|
||||
client_limit = config->client_limit;
|
||||
/* for each yp url in config, check to see if one exists
|
||||
if not, then add it. */
|
||||
for (i=0 ; i < config->num_yp_directories; i++)
|
||||
@ -387,10 +389,9 @@ static unsigned do_yp_add (ypdata_t *yp, char *s, unsigned len)
|
||||
|
||||
static unsigned do_yp_touch (ypdata_t *yp, char *s, unsigned len)
|
||||
{
|
||||
unsigned listeners = 0;
|
||||
unsigned listeners = 0, max_listeners = 1;
|
||||
char *val, *artist, *title;
|
||||
int ret;
|
||||
char *max_listeners;
|
||||
|
||||
artist = (char *)stats_get_value (yp->mount, "artist");
|
||||
title = (char *)stats_get_value (yp->mount, "title");
|
||||
@ -422,12 +423,15 @@ static unsigned do_yp_touch (ypdata_t *yp, char *s, unsigned len)
|
||||
listeners = atoi (val);
|
||||
free (val);
|
||||
}
|
||||
max_listeners = stats_get_value (yp->mount, "max_listeners");
|
||||
if (max_listeners == NULL || strcmp (max_listeners, "unlimited") == 0)
|
||||
val = stats_get_value (yp->mount, "max_listeners");
|
||||
if (val == NULL || strcmp (val, "unlimited") == 0)
|
||||
{
|
||||
free (max_listeners);
|
||||
max_listeners = (char *)stats_get_value (NULL, "client_limit");
|
||||
free (val);
|
||||
max_listeners = client_limit;
|
||||
}
|
||||
else
|
||||
max_listeners = atoi (val);
|
||||
|
||||
val = stats_get_value (yp->mount, "subtype");
|
||||
if (val)
|
||||
{
|
||||
@ -436,10 +440,9 @@ static unsigned do_yp_touch (ypdata_t *yp, char *s, unsigned len)
|
||||
}
|
||||
|
||||
ret = snprintf (s, len, "action=touch&sid=%s&st=%s"
|
||||
"&listeners=%u&max_listeners=%s&stype=%s\r\n",
|
||||
"&listeners=%u&max_listeners=%u&stype=%s\r\n",
|
||||
yp->sid, yp->current_song, listeners, max_listeners, yp->subtype);
|
||||
|
||||
free (max_listeners);
|
||||
if (ret >= (signed)len)
|
||||
return ret+1; /* space required for above text and nul*/
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user