mirror of
https://github.com/keymanapp/keyman.git
synced 2026-08-14 12:49:25 +00:00
Fix use-after0free in abstract_processor::lookup_option() design
Since option was not assigned to non temporary storage the string was deleted and caused the API to return freed memory.
This commit is contained in:
parent
f8f1407fb8
commit
da815eb92e
7 changed files with 9 additions and 9 deletions
|
|
@ -44,7 +44,7 @@ km_kbp_state_option_lookup(km_kbp_state const *state,
|
|||
|
||||
auto & processor = state->processor();
|
||||
|
||||
*value_out = processor.lookup_option(km_kbp_option_scope(scope), key).value;
|
||||
*value_out = processor.lookup_option(km_kbp_option_scope(scope), key);
|
||||
if (!*value_out) return KM_KBP_STATUS_KEY_ERROR;
|
||||
|
||||
return KM_KBP_STATUS_OK;
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ int KMX_Options::_GetIndex(std::u16string const &key) const {
|
|||
for (auto sp = _kp->Keyboard->dpStoreArray;
|
||||
i != _kp->Keyboard->cxStoreArray; ++i, ++sp)
|
||||
{
|
||||
if (sp->dpName && sp->dpName == key) break;
|
||||
if (sp->dpName && sp->dpName == key) return i;
|
||||
}
|
||||
|
||||
return -1;
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ namespace km {
|
|||
}
|
||||
|
||||
|
||||
option kmx_processor::lookup_option(km_kbp_option_scope scope, std::u16string const & key) const
|
||||
char16_t const * kmx_processor::lookup_option(km_kbp_option_scope scope, std::u16string const & key) const
|
||||
{
|
||||
char16_t const * pValue = nullptr;
|
||||
switch(scope)
|
||||
|
|
@ -48,7 +48,7 @@ namespace km {
|
|||
break;
|
||||
}
|
||||
|
||||
return pValue ? option(scope, key, pValue) : option();
|
||||
return pValue ? pValue : nullptr;
|
||||
}
|
||||
|
||||
option kmx_processor::update_option(km_kbp_option_scope scope, std::u16string const & key, std::u16string const & value)
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ namespace kbp
|
|||
km_kbp_attr const & attributes() const override;
|
||||
km_kbp_status validate() const override;
|
||||
|
||||
option lookup_option(km_kbp_option_scope,
|
||||
char16_t const * lookup_option(km_kbp_option_scope,
|
||||
std::u16string const & key) const override;
|
||||
option update_option(km_kbp_option_scope scope,
|
||||
std::u16string const & key,
|
||||
|
|
|
|||
|
|
@ -84,11 +84,11 @@ namespace km {
|
|||
{
|
||||
}
|
||||
|
||||
option mock_processor::lookup_option(km_kbp_option_scope scope,
|
||||
char16_t const * mock_processor::lookup_option(km_kbp_option_scope scope,
|
||||
std::u16string const & key) const
|
||||
{
|
||||
auto i = _options.find(char16_t(scope) + key);
|
||||
return i != _options.end() ? option(scope, key, i->second) : option();
|
||||
return i != _options.end() ? i->second.c_str() : nullptr;
|
||||
}
|
||||
|
||||
option mock_processor::update_option(km_kbp_option_scope scope,
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ namespace kbp
|
|||
|
||||
|
||||
|
||||
option lookup_option(km_kbp_option_scope,
|
||||
char16_t const * lookup_option(km_kbp_option_scope,
|
||||
std::u16string const & key) const override;
|
||||
option update_option(km_kbp_option_scope,
|
||||
std::u16string const & key,
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ namespace kbp
|
|||
virtual km_kbp_attr const & attributes() const = 0;
|
||||
virtual km_kbp_status validate() const = 0;
|
||||
|
||||
virtual option lookup_option(km_kbp_option_scope,
|
||||
virtual char16_t const * lookup_option(km_kbp_option_scope,
|
||||
std::u16string const & key) const = 0;
|
||||
virtual option update_option(km_kbp_option_scope,
|
||||
std::u16string const & key,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue