File fix-CVE-2013-4509-support-input-purpose.patch of Package ibus-chewing.openSUSE_13.1_Update

From eea7a170ba329a825644956ac390bb63c1a4e667 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?ChangZhuo=20Chen=20=28=E9=99=B3=E6=98=8C=E5=80=AC=29?=
 <czchen@gmail.com>
Date: Sun, 15 Dec 2013 12:22:05 +0800
Subject: [PATCH] Skip key event when input purpose is password

---
 src/IBusChewingEngine-input-events.c | 16 ++++++++++++++++
 src/IBusChewingEngine.gob            | 15 +++++++++++++++
 2 files changed, 31 insertions(+)

diff --git a/src/IBusChewingEngine-input-events.c b/src/IBusChewingEngine-input-events.c
index 974cf75..ef78c4c 100644
--- a/src/IBusChewingEngine-input-events.c
+++ b/src/IBusChewingEngine-input-events.c
@@ -29,6 +29,7 @@ gboolean ibus_chewing_engine_process_key_event(IBusEngine *engine,
     gboolean result=TRUE;
 
     IBusChewingEngine *self=IBUS_CHEWING_ENGINE(engine);
+    if (ibus_chewing_engine_is_password(self)) return FALSE;
     guint kSym=ibus_chewing_engine_keycode_to_keysym(self,keysym, keycode, modifiers);
 
     if (modifiers & IBUS_RELEASE_MASK){
@@ -282,6 +283,7 @@ void ibus_chewing_engine_handle_Default(IBusChewingEngine *self, guint keyval, g
 void ibus_chewing_engine_candidate_clicked(IBusEngine *engine, guint index, guint button, guint state){
     G_DEBUG_MSG(2,"***[I2] candidate_clicked(-, %u, %u, %u) ... proceed.", index, button, state);
     IBusChewingEngine *self=IBUS_CHEWING_ENGINE(engine);
+    if (ibus_chewing_engine_is_password(self)) return;
     if (index >= chewing_get_candPerPage(self->context) || index <0) {
 	G_DEBUG_MSG(3,"[I3]  candidate_clicked() index out of ranged");
 	return;
@@ -329,3 +331,17 @@ void ibus_chewing_engine_property_activate(IBusEngine *engine, const gchar  *pro
     if (needRefresh)
 	self_refresh_property(self,prop_name);
 }
+
+#if IBUS_CHECK_VERSION(1, 5, 4)
+void ibus_chewing_engine_set_content_type(IBusEngine *engine, guint purpose, guint hints){
+    G_DEBUG_MSG(5,"[I5] set_content_type(%d, %d)", purpose, hints);
+
+    Self *self=SELF(engine);
+    if (purpose == IBUS_INPUT_PURPOSE_PASSWORD ||
+	purpose == IBUS_INPUT_PURPOSE_PIN) {
+	ibus_chewing_engine_set_status_flag(self, ENGINE_STATUS_IS_PASSWORD);
+    } else {
+	ibus_chewing_engine_clear_status_flag(self, ENGINE_STATUS_IS_PASSWORD);
+    }
+}
+#endif
diff --git a/src/IBusChewingEngine.gob b/src/IBusChewingEngine.gob
index 8bb742a..68986ad 100644
--- a/src/IBusChewingEngine.gob
+++ b/src/IBusChewingEngine.gob
@@ -110,6 +110,7 @@ enum CHEWING_FLAG{
  * @SHOW_CANDIDATE:     Whether the candidate selection should be shown. Important for Plain Zhuyin.
  * @NEED_COMMIT:        There's Something to commit.
  * @FORCE_COMMIT:       The engine should commit
+ * @IS_PASSWORD:        Current input is password.
  *
  * Engine status show the current states of engine,
  * Thus this will change quite often.
@@ -124,6 +125,7 @@ enum ENGINE_STATUS{
     SHOW_CANDIDATE=		0x8,
     NEED_COMMIT=		0x10,
     FORCE_COMMIT=		0x20,
+    IS_PASSWORD=		0x40,
 } Engine:Status;
 
 %h{
@@ -152,6 +154,7 @@ void ibus_chewing_engine_handle_Default(IBusChewingEngine *self, guint keyval, g
 gboolean ibus_chewing_engine_process_key_event(IBusEngine *engine, guint keysym,  guint keycode, guint modifiers);
 void ibus_chewing_engine_candidate_clicked(IBusEngine *engine, guint index, guint button, guint state);
 void ibus_chewing_engine_property_activate(IBusEngine *engine, const gchar  *prop_name, guint  prop_state);
+void ibus_chewing_engine_set_content_type(IBusEngine *engine, guint purpose, guint hints);
 
 %}
 
@@ -268,6 +271,9 @@ class IBus:Chewing:Engine from IBus:Engine{
 	ibus_engine_class->property_activate= ibus_chewing_engine_property_activate;
 	ibus_engine_class->process_key_event = ibus_chewing_engine_process_key_event;
 	ibus_engine_class->candidate_clicked = ibus_chewing_engine_candidate_clicked;
+#if IBUS_CHECK_VERSION(1, 5, 4)
+	ibus_engine_class->set_content_type = ibus_chewing_engine_set_content_type;
+#endif
     }
 
     private  void load_setting(self){
@@ -633,6 +639,11 @@ class IBus:Chewing:Engine from IBus:Engine{
 	}
     }
 
+    protected gboolean is_password(self){
+	G_DEBUG_MSG(5, "[I5] is_password = %d", self->chewingFlags & ENGINE_STATUS_IS_PASSWORD);
+	return !!(self->_priv->statusFlags & ENGINE_STATUS_IS_PASSWORD);
+    }
+
     /**
      * refresh_property_list:
      * @self: this instances.
@@ -952,6 +963,7 @@ class IBus:Chewing:Engine from IBus:Engine{
     override (IBus:Engine) void
     page_up(IBus:Engine *engine){
 	Self *self=SELF(engine);
+	if (self_is_password(self)) return;
 	chewing_handle_PageUp(self->context);
 	self_update(self);
     }
@@ -960,6 +972,7 @@ class IBus:Chewing:Engine from IBus:Engine{
     override (IBus:Engine) void
     page_down(IBus:Engine *engine){
 	Self *self=SELF(engine);
+	if (self_is_password(self)) return;
 	chewing_handle_PageDown(self->context);
 	self_update(self);
     }
@@ -967,6 +980,7 @@ class IBus:Chewing:Engine from IBus:Engine{
     override (IBus:Engine) void
     cursor_up(IBus:Engine *engine){
 	Self *self=SELF(engine);
+	if (self_is_password(self)) return;
 	chewing_handle_Up(self->context);
 	self_update(self);
     }
@@ -974,6 +988,7 @@ class IBus:Chewing:Engine from IBus:Engine{
     override (IBus:Engine) void
     cursor_down(IBus:Engine *engine){
 	Self *self=SELF(engine);
+	if (self_is_password(self)) return;
 	chewing_handle_Down(self->context);
 	self_update(self);
     }
-- 
1.8.5.1

openSUSE Build Service is sponsored by