settings: Don't overwrite values in-place
This is not thread safe. If threads are reading from pointers to existing values they could get a partially updated invalid value. Refactored assignment to a separate function.
This commit is contained in:
@@ -474,26 +474,7 @@ static void set_value(private_settings_t *this, section_t *section,
|
||||
TRUE);
|
||||
if (kv)
|
||||
{
|
||||
if (!value)
|
||||
{
|
||||
if (kv->value)
|
||||
{
|
||||
array_insert(this->contents, ARRAY_TAIL, kv->value);
|
||||
}
|
||||
kv->value = NULL;
|
||||
}
|
||||
else if (kv->value && (strlen(value) <= strlen(kv->value)))
|
||||
{ /* overwrite in-place, if possible */
|
||||
strcpy(kv->value, value);
|
||||
}
|
||||
else
|
||||
{ /* otherwise clone the string and cache the replaced one */
|
||||
if (kv->value)
|
||||
{
|
||||
array_insert(this->contents, ARRAY_TAIL, kv->value);
|
||||
}
|
||||
kv->value = strdup(value);
|
||||
}
|
||||
settings_kv_set(kv, strdupnull(value), this->contents);
|
||||
}
|
||||
this->lock->unlock(this->lock);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user