config: protect against potential out-of-bounds indexing.

This commit is contained in:
Peter Hutterer 2008-08-01 15:52:07 +09:30
parent 92c51b183c
commit 3c6a9c531f

View File

@ -260,7 +260,7 @@ device_added(LibHalContext *hal_ctx, const char *udi)
* Since we can't predict the order in which the keys * Since we can't predict the order in which the keys
* arrive, we need to store them. * arrive, we need to store them.
*/ */
if ((tmp = strcasestr(psi_key, "xkb"))) if ((tmp = strcasestr(psi_key, "xkb")) && strlen(tmp) >= 4)
{ {
if (!strcasecmp(&tmp[3], "layout")) if (!strcasecmp(&tmp[3], "layout"))
{ {
@ -298,6 +298,7 @@ device_added(LibHalContext *hal_ctx, const char *udi)
{ {
/* server 1.4 had xkb_options as strlist. */ /* server 1.4 had xkb_options as strlist. */
if ((tmp = strcasestr(psi_key, "xkb")) && if ((tmp = strcasestr(psi_key, "xkb")) &&
(strlen(tmp) >= 4) &&
(!strcasecmp(&tmp[3], "options")) && (!strcasecmp(&tmp[3], "options")) &&
(tmp_val = get_prop_string_array(hal_ctx, udi, psi_key))) (tmp_val = get_prop_string_array(hal_ctx, udi, psi_key)))
{ {
@ -312,7 +313,7 @@ device_added(LibHalContext *hal_ctx, const char *udi)
/* only support strings for all values */ /* only support strings for all values */
tmp_val = get_prop_string(hal_ctx, udi, psi_key); tmp_val = get_prop_string(hal_ctx, udi, psi_key);
if (tmp_val){ if (tmp_val && strlen(psi_key) >= sizeof(LIBHAL_XKB_PROP_KEY)) {
tmp = &psi_key[sizeof(LIBHAL_XKB_PROP_KEY) - 1]; tmp = &psi_key[sizeof(LIBHAL_XKB_PROP_KEY) - 1];
@ -342,7 +343,7 @@ device_added(LibHalContext *hal_ctx, const char *udi)
{ {
/* server 1.4 had xkb options as strlist */ /* server 1.4 had xkb options as strlist */
tmp_val = get_prop_string_array(hal_ctx, udi, psi_key); tmp_val = get_prop_string_array(hal_ctx, udi, psi_key);
if (tmp_val) if (tmp_val && strlen(psi_key) >= sizeof(LIBHAL_XKB_PROP_KEY))
{ {
tmp = &psi_key[sizeof(LIBHAL_XKB_PROP_KEY) - 1]; tmp = &psi_key[sizeof(LIBHAL_XKB_PROP_KEY) - 1];
if (!strcasecmp(tmp, ".options") && (!xkb_opts.options)) if (!strcasecmp(tmp, ".options") && (!xkb_opts.options))