Revision: 4855 http://geany.svn.sourceforge.net/geany/?rev=4855&view=rev Author: eht16 Date: 2010-04-25 17:42:01 +0000 (Sun, 25 Apr 2010)
Log Message: ----------- Replace g_vsnprintf() by g_strdup_vprintf() to avoid truncated strings in case of reaching the buffer size limit (part of #2979697).
Modified Paths: -------------- trunk/ChangeLog trunk/src/dialogs.c trunk/src/msgwindow.c trunk/src/ui_utils.c
Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2010-04-22 17:16:46 UTC (rev 4854) +++ trunk/ChangeLog 2010-04-25 17:42:01 UTC (rev 4855) @@ -1,3 +1,10 @@ +2010-04-25 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de> + + * src/build.c, src/dialogs.c, src/msgwindow.c, src/ui_utils.c: + Replace g_vsnprintf() by g_strdup_vprintf() to avoid truncated + strings in case of reaching the buffer size limit (part of #2979697). + + 2010-04-22 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
* src/plugindata.h, src/pluginutils.c, src/pluginutils.h, THANKS:
Modified: trunk/src/dialogs.c =================================================================== --- trunk/src/dialogs.c 2010-04-22 17:16:46 UTC (rev 4854) +++ trunk/src/dialogs.c 2010-04-25 17:42:01 UTC (rev 4855) @@ -607,12 +607,12 @@ #ifndef G_OS_WIN32 GtkWidget *dialog; #endif - gchar string[512]; + gchar *string; va_list args; GtkWindow *parent = (main_status.main_window_realized) ? GTK_WINDOW(main_widgets.window) : NULL;
va_start(args, text); - g_vsnprintf(string, 511, text, args); + string = g_strdup_vprintf(text, args); va_end(args);
#ifdef G_OS_WIN32 @@ -622,6 +622,7 @@ type, GTK_BUTTONS_OK, "%s", string); show_msgbox_dialog(dialog, type, parent); #endif + g_free(string); }
@@ -1465,18 +1466,21 @@ **/ gboolean dialogs_show_question(const gchar *text, ...) { - gchar string[512]; + gchar *string; va_list args; GtkWidget *parent = (main_status.main_window_realized) ? main_widgets.window : NULL; + gint result;
va_start(args, text); - g_vsnprintf(string, 511, text, args); + string = g_strdup_vprintf(text, args); va_end(args); - return show_prompt(parent, + result = show_prompt(parent, NULL, GTK_RESPONSE_NONE, GTK_STOCK_NO, GTK_RESPONSE_NO, GTK_STOCK_YES, GTK_RESPONSE_YES, - string, NULL) == GTK_RESPONSE_YES; + string, NULL); + g_free(string); + return (result == GTK_RESPONSE_YES); }
@@ -1486,17 +1490,20 @@ gboolean dialogs_show_question_full(GtkWidget *parent, const gchar *yes_btn, const gchar *no_btn, const gchar *extra_text, const gchar *main_text, ...) { - gchar string[512]; + gint result; + gchar *string; va_list args;
va_start(args, main_text); - g_vsnprintf(string, 511, main_text, args); + string = g_strdup_vprintf(main_text, args); va_end(args); - return show_prompt(parent, + result = show_prompt(parent, NULL, GTK_RESPONSE_NONE, no_btn, GTK_RESPONSE_NO, yes_btn, GTK_RESPONSE_YES, - string, extra_text) == GTK_RESPONSE_YES; + string, extra_text); + g_free(string); + return (result == GTK_RESPONSE_YES); }
@@ -1510,14 +1517,17 @@ const gchar *btn_3, GtkResponseType response_3, const gchar *extra_text, const gchar *main_text, ...) { - gchar string[512]; + gchar *string; va_list args; + gint result;
va_start(args, main_text); - g_vsnprintf(string, 511, main_text, args); + string = g_strdup_vprintf(main_text, args); va_end(args); - return show_prompt(parent, btn_1, response_1, btn_2, response_2, btn_3, response_3, + result = show_prompt(parent, btn_1, response_1, btn_2, response_2, btn_3, response_3, string, extra_text); + g_free(string); + return result; }
Modified: trunk/src/msgwindow.c =================================================================== --- trunk/src/msgwindow.c 2010-04-22 17:16:46 UTC (rev 4854) +++ trunk/src/msgwindow.c 2010-04-25 17:42:01 UTC (rev 4855) @@ -252,13 +252,14 @@ **/ void msgwin_compiler_add(gint msg_color, const gchar *format, ...) { - gchar string[512]; + gchar *string; va_list args;
va_start(args, format); - g_vsnprintf(string, 512, format, args); + string = g_strdup_vprintf(format, args); va_end(args); msgwin_compiler_add_string(msg_color, string); + g_free(string); }
@@ -314,14 +315,15 @@ **/ void msgwin_msg_add(gint msg_color, gint line, GeanyDocument *doc, const gchar *format, ...) { - gchar string[512]; + gchar *string; va_list args;
va_start(args, format); - g_vsnprintf(string, 512, format, args); + string = g_strdup_vprintf(format, args); va_end(args);
msgwin_msg_add_string(msg_color, line, doc, string); + g_free(string); }
@@ -361,18 +363,19 @@ void msgwin_status_add(const gchar *format, ...) { GtkTreeIter iter; - gchar string[512]; + gchar *string; gchar *statusmsg, *time_str; va_list args;
va_start(args, format); - g_vsnprintf(string, 512, format, args); + string = g_strdup_vprintf(format, args); va_end(args);
/* add a timestamp to status messages */ time_str = utils_get_current_time_string(); statusmsg = g_strconcat(time_str, ": ", string, NULL); g_free(time_str); + g_free(string);
/* add message to Status window */ gtk_list_store_append(msgwindow.store_status, &iter);
Modified: trunk/src/ui_utils.c =================================================================== --- trunk/src/ui_utils.c 2010-04-22 17:16:46 UTC (rev 4854) +++ trunk/src/ui_utils.c 2010-04-25 17:42:01 UTC (rev 4855) @@ -140,11 +140,11 @@ * @param format A @c printf -style string. */ void ui_set_statusbar(gboolean log, const gchar *format, ...) { - gchar string[512]; + gchar *string; va_list args;
va_start(args, format); - g_vsnprintf(string, 512, format, args); + string = g_strdup_vprintf(format, args); va_end(args);
if (! prefs.suppress_status_messages) @@ -152,6 +152,8 @@
if (log || prefs.suppress_status_messages) msgwin_status_add("%s", string); + + g_free(string); }
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.