MXS-1847: Fix server_get_parameter

The function now takes an output buffer as a parameter. This prevents race
conditions by copying the parameter value into a local buffer.
This commit is contained in:
Markus Mäkelä
2018-05-02 22:21:18 +03:00
parent e311b86800
commit 612b4e1a32
5 changed files with 43 additions and 29 deletions

View File

@ -924,24 +924,35 @@ static void server_parameter_free(SERVER_PARAM *tofree)
/**
* Retrieve a parameter value from a server
*
* @param server The server we are looking for a parameter of
* @param name The name of the parameter we require
* @return The parameter value or NULL if not found
* @param server The server we are looking for a parameter of
* @param name The name of the parameter we require
* @param out Buffer where value is stored, use NULL to check if the parameter exists
* @param size Size of @c out, ignored if @c out is NULL
*
* @return True if parameter was found
*/
const char *
server_get_parameter(const SERVER *server, const char *name)
bool server_get_parameter(const SERVER *server, const char *name, char* out, size_t size)
{
bool found = false;
SERVER_PARAM *param = server->parameters;
spinlock_acquire(&server->lock);
while (param)
{
if (strcmp(param->name, name) == 0 && param->active)
{
return param->value;
if (out)
{
snprintf(out, size, "%s", param->value);
}
found = true;
break;
}
param = param->next;
}
return NULL;
spinlock_release(&server->lock);
return found;
}
/**