Revision: 2092 http://geany.svn.sourceforge.net/geany/?rev=2092&view=rev Author: eht16 Date: 2007-12-06 08:38:13 -0800 (Thu, 06 Dec 2007)
Log Message: ----------- Prevent execution of commands by Geany if the VTE may contain any text on the prompt (thanks to "Jeff Pohlmeyer for reporting).
Modified Paths: -------------- trunk/ChangeLog trunk/src/build.c trunk/src/vte.c trunk/src/vte.h
Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2007-12-05 13:54:43 UTC (rev 2091) +++ trunk/ChangeLog 2007-12-06 16:38:13 UTC (rev 2092) @@ -1,3 +1,10 @@ +2007-12-06 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de> + + * src/build.c, src/vte.c, src/vte.h: + Prevent execution of commands by Geany if the VTE may contain any + text on the prompt (thanks to "Jeff Pohlmeyer for reporting). + + 2007-12-05 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
* src/document.c: Add "b" flag to fopen when saving files to avoid
Modified: trunk/src/build.c =================================================================== --- trunk/src/build.c 2007-12-05 13:54:43 UTC (rev 2091) +++ trunk/src/build.c 2007-12-06 16:38:13 UTC (rev 2092) @@ -770,7 +770,9 @@ gchar *vte_cmd = g_strconcat(RUN_SCRIPT_CMD, "\n", NULL); // change into current directory if it is not done by default if (! vc->follow_path) vte_cwd(doc_list[idx].file_name, TRUE); - vte_send_cmd(vte_cmd); + if (! vte_send_cmd(vte_cmd)) + ui_set_statusbar(FALSE, + _("Could not execute the file in the VTE because it probably contains a command."));
// show the VTE gtk_notebook_set_current_page(GTK_NOTEBOOK(msgwindow.notebook), MSG_VTE);
Modified: trunk/src/vte.c =================================================================== --- trunk/src/vte.c 2007-12-05 13:54:43 UTC (rev 2091) +++ trunk/src/vte.c 2007-12-06 16:38:13 UTC (rev 2092) @@ -47,6 +47,7 @@
extern gchar **environ; static pid_t pid; +static gboolean clean = TRUE; static GModule *module = NULL; static struct VteFunctions *vf; static gboolean popup_menu_created = FALSE; @@ -63,10 +64,12 @@ static void create_vte(); static void vte_start(GtkWidget *widget); static gboolean vte_button_pressed(GtkWidget *widget, GdkEventButton *event, gpointer user_data); +static gboolean vte_keyrelease(GtkWidget *widget, GdkEventKey *event, gpointer data); static gboolean vte_keypress(GtkWidget *widget, GdkEventKey *event, gpointer data); static void vte_register_symbols(GModule *module); static void vte_popup_menu_clicked(GtkMenuItem *menuitem, gpointer user_data); static GtkWidget *vte_create_popup_menu(void); +void vte_commit(VteTerminal *vte, gchar *arg1, guint arg2, gpointer user_data);
enum @@ -213,6 +216,8 @@ g_signal_connect(G_OBJECT(vte), "button-press-event", G_CALLBACK(vte_button_pressed), NULL); if (! vc->enable_bash_keys) g_signal_connect(G_OBJECT(vte), "event", G_CALLBACK(vte_keypress), NULL); + g_signal_connect(G_OBJECT(vte), "key-release-event", G_CALLBACK(vte_keyrelease), NULL); + g_signal_connect(G_OBJECT(vte), "commit", G_CALLBACK(vte_commit), NULL); g_signal_connect(G_OBJECT(vte), "motion-notify-event", G_CALLBACK(on_motion_event), NULL); //g_signal_connect(G_OBJECT(vte), "drag-data-received", G_CALLBACK(vte_drag_data_received), NULL); //g_signal_connect(G_OBJECT(vte), "drag-drop", G_CALLBACK(vte_drag_drop), NULL); @@ -246,6 +251,18 @@ }
+static gboolean vte_keyrelease(GtkWidget *widget, GdkEventKey *event, gpointer data) +{ + if (event->keyval == GDK_Return || + event->keyval == GDK_ISO_Enter || + event->keyval == GDK_KP_Enter) + { + clean = TRUE; // assume any text on the prompt has been executed when pressing Enter/Return + } + return FALSE; +} + + static gboolean vte_keypress(GtkWidget *widget, GdkEventKey *event, gpointer data) { g_assert(!vc->enable_bash_keys); @@ -276,6 +293,12 @@ }
+void vte_commit(VteTerminal *vte, gchar *arg1, guint arg2, gpointer user_data) +{ + clean = FALSE; +} + + static void vte_start(GtkWidget *widget) { VteTerminal *vte = VTE_TERMINAL(widget); @@ -295,6 +318,8 @@ } else pid = 0; // use 0 as invalid pid + + clean = TRUE; }
@@ -469,9 +494,18 @@ }
-void vte_send_cmd(const gchar *cmd) +/* if the command could be executed, TRUE is returned, FALSE otherwise (i.e. there was some text + * on the prompt). */ +gboolean vte_send_cmd(const gchar *cmd) { - vf->vte_terminal_feed_child(VTE_TERMINAL(vc->vte), cmd, strlen(cmd)); + if (clean) + { + vf->vte_terminal_feed_child(VTE_TERMINAL(vc->vte), cmd, strlen(cmd)); + clean = TRUE; // vte_terminal_feed_child() also marks the vte as not clean + return TRUE; + } + else + return FALSE; }
@@ -530,7 +564,9 @@ // use g_shell_quote to avoid problems with spaces, '!' or something else in path gchar *quoted_path = g_shell_quote(path); gchar *cmd = g_strconcat("cd ", quoted_path, "\n", NULL); - vte_send_cmd(cmd); + if (! vte_send_cmd(cmd)) + ui_set_statusbar(FALSE, + _("Could not change the directory in the VTE because it probably contains a command.")); g_free(quoted_path); g_free(cmd); }
Modified: trunk/src/vte.h =================================================================== --- trunk/src/vte.h 2007-12-05 13:54:43 UTC (rev 2091) +++ trunk/src/vte.h 2007-12-06 16:38:13 UTC (rev 2092) @@ -71,7 +71,7 @@
void vte_apply_user_settings(void);
-void vte_send_cmd(const gchar *cmd); +gboolean vte_send_cmd(const gchar *cmd);
const gchar* vte_get_working_directory(void);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.