anonymous: fix segfault loading config item
unlike other functions called from the config parser code, anonymous_insert() accesses the global config variable rather than passing it as an argument. however the global variable is only set after successful loading of the entire config. we fix this by adding a conf argument to each anonymous_* function, passing the global pointer in calls done from outside the config parser. fixes #292
This commit is contained in:
parent
2e02dce0c3
commit
3230ce0bc2
@ -28,21 +28,21 @@
|
||||
#include "log.h"
|
||||
#include "conf.h"
|
||||
|
||||
short int is_anonymous_enabled (void)
|
||||
short int is_anonymous_enabled (struct config_s *conf)
|
||||
{
|
||||
return (config->anonymous_map != NULL) ? 1 : 0;
|
||||
return (conf->anonymous_map != NULL) ? 1 : 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Search for the header. This function returns a positive value greater than
|
||||
* zero if the string was found, zero if it wasn't and negative upon error.
|
||||
*/
|
||||
int anonymous_search (const char *s)
|
||||
int anonymous_search (struct config_s *conf, const char *s)
|
||||
{
|
||||
assert (s != NULL);
|
||||
assert (config->anonymous_map != NULL);
|
||||
assert (conf->anonymous_map != NULL);
|
||||
|
||||
return hashmap_search (config->anonymous_map, s);
|
||||
return hashmap_search (conf->anonymous_map, s);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -51,23 +51,23 @@ int anonymous_search (const char *s)
|
||||
* Return -1 if there is an error, otherwise a 0 is returned if the insert was
|
||||
* successful.
|
||||
*/
|
||||
int anonymous_insert (const char *s)
|
||||
int anonymous_insert (struct config_s *conf, const char *s)
|
||||
{
|
||||
char data = 1;
|
||||
|
||||
assert (s != NULL);
|
||||
|
||||
if (!config->anonymous_map) {
|
||||
config->anonymous_map = hashmap_create (32);
|
||||
if (!config->anonymous_map)
|
||||
if (!conf->anonymous_map) {
|
||||
conf->anonymous_map = hashmap_create (32);
|
||||
if (!conf->anonymous_map)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (hashmap_search (config->anonymous_map, s) > 0) {
|
||||
if (hashmap_search (conf->anonymous_map, s) > 0) {
|
||||
/* The key was already found, so return a positive number. */
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Insert the new key */
|
||||
return hashmap_insert (config->anonymous_map, s, &data, sizeof (data));
|
||||
return hashmap_insert (conf->anonymous_map, s, &data, sizeof (data));
|
||||
}
|
||||
|
@ -21,8 +21,8 @@
|
||||
#ifndef _TINYPROXY_ANONYMOUS_H_
|
||||
#define _TINYPROXY_ANONYMOUS_H_
|
||||
|
||||
extern short int is_anonymous_enabled (void);
|
||||
extern int anonymous_search (const char *s);
|
||||
extern int anonymous_insert (const char *s);
|
||||
extern short int is_anonymous_enabled (struct config_s *conf);
|
||||
extern int anonymous_search (struct config_s *conf, const char *s);
|
||||
extern int anonymous_insert (struct config_s *conf, const char *s);
|
||||
|
||||
#endif
|
||||
|
@ -624,7 +624,7 @@ static HANDLE_FUNC (handle_anonymous)
|
||||
if (!arg)
|
||||
return -1;
|
||||
|
||||
anonymous_insert (arg);
|
||||
anonymous_insert (conf, arg);
|
||||
safefree (arg);
|
||||
return 0;
|
||||
}
|
||||
|
@ -325,9 +325,9 @@ main (int argc, char **argv)
|
||||
* in the list of allowed headers, since it is required in a
|
||||
* HTTP/1.0 request. Also add the Content-Type header since it
|
||||
* goes hand in hand with Content-Length. */
|
||||
if (is_anonymous_enabled ()) {
|
||||
anonymous_insert ("Content-Length");
|
||||
anonymous_insert ("Content-Type");
|
||||
if (is_anonymous_enabled (config)) {
|
||||
anonymous_insert (config, "Content-Length");
|
||||
anonymous_insert (config, "Content-Type");
|
||||
}
|
||||
|
||||
if (daemonized == TRUE) {
|
||||
|
@ -919,8 +919,8 @@ process_client_headers (struct conn_s *connptr, hashmap_t hashofheaders)
|
||||
hashmap_return_entry (hashofheaders,
|
||||
iter, &data, (void **) &header);
|
||||
|
||||
if (!is_anonymous_enabled ()
|
||||
|| anonymous_search (data) > 0) {
|
||||
if (!is_anonymous_enabled (config)
|
||||
|| anonymous_search (config, data) > 0) {
|
||||
ret =
|
||||
write_message (connptr->server_fd,
|
||||
"%s: %s\r\n", data, header);
|
||||
|
Loading…
Reference in New Issue
Block a user