Replace g_vsnprintf() by g_strdup_vprintf() to avoid truncated strings in case of reaching the buffer size limit (part of #2979697).

git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@4855 ea778897-0a13-0410-b9d1-a72fbfd435f5
This commit is contained in:
Enrico Tröger 2010-04-25 17:42:01 +00:00
parent 751f8be508
commit 2f63860908
4 changed files with 43 additions and 21 deletions

View File

@ -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> 2010-04-22 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
* src/plugindata.h, src/pluginutils.c, src/pluginutils.h, THANKS: * src/plugindata.h, src/pluginutils.c, src/pluginutils.h, THANKS:

View File

@ -607,12 +607,12 @@ void dialogs_show_msgbox(GtkMessageType type, const gchar *text, ...)
#ifndef G_OS_WIN32 #ifndef G_OS_WIN32
GtkWidget *dialog; GtkWidget *dialog;
#endif #endif
gchar string[512]; gchar *string;
va_list args; va_list args;
GtkWindow *parent = (main_status.main_window_realized) ? GTK_WINDOW(main_widgets.window) : NULL; GtkWindow *parent = (main_status.main_window_realized) ? GTK_WINDOW(main_widgets.window) : NULL;
va_start(args, text); va_start(args, text);
g_vsnprintf(string, 511, text, args); string = g_strdup_vprintf(text, args);
va_end(args); va_end(args);
#ifdef G_OS_WIN32 #ifdef G_OS_WIN32
@ -622,6 +622,7 @@ void dialogs_show_msgbox(GtkMessageType type, const gchar *text, ...)
type, GTK_BUTTONS_OK, "%s", string); type, GTK_BUTTONS_OK, "%s", string);
show_msgbox_dialog(dialog, type, parent); show_msgbox_dialog(dialog, type, parent);
#endif #endif
g_free(string);
} }
@ -1465,18 +1466,21 @@ static gint show_prompt(GtkWidget *parent,
**/ **/
gboolean dialogs_show_question(const gchar *text, ...) gboolean dialogs_show_question(const gchar *text, ...)
{ {
gchar string[512]; gchar *string;
va_list args; va_list args;
GtkWidget *parent = (main_status.main_window_realized) ? main_widgets.window : NULL; GtkWidget *parent = (main_status.main_window_realized) ? main_widgets.window : NULL;
gint result;
va_start(args, text); va_start(args, text);
g_vsnprintf(string, 511, text, args); string = g_strdup_vprintf(text, args);
va_end(args); va_end(args);
return show_prompt(parent, result = show_prompt(parent,
NULL, GTK_RESPONSE_NONE, NULL, GTK_RESPONSE_NONE,
GTK_STOCK_NO, GTK_RESPONSE_NO, GTK_STOCK_NO, GTK_RESPONSE_NO,
GTK_STOCK_YES, GTK_RESPONSE_YES, 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(const gchar *text, ...)
gboolean dialogs_show_question_full(GtkWidget *parent, const gchar *yes_btn, const gchar *no_btn, gboolean dialogs_show_question_full(GtkWidget *parent, const gchar *yes_btn, const gchar *no_btn,
const gchar *extra_text, const gchar *main_text, ...) const gchar *extra_text, const gchar *main_text, ...)
{ {
gchar string[512]; gint result;
gchar *string;
va_list args; va_list args;
va_start(args, main_text); va_start(args, main_text);
g_vsnprintf(string, 511, main_text, args); string = g_strdup_vprintf(main_text, args);
va_end(args); va_end(args);
return show_prompt(parent, result = show_prompt(parent,
NULL, GTK_RESPONSE_NONE, NULL, GTK_RESPONSE_NONE,
no_btn, GTK_RESPONSE_NO, no_btn, GTK_RESPONSE_NO,
yes_btn, GTK_RESPONSE_YES, 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 @@ gint dialogs_show_prompt(GtkWidget *parent,
const gchar *btn_3, GtkResponseType response_3, const gchar *btn_3, GtkResponseType response_3,
const gchar *extra_text, const gchar *main_text, ...) const gchar *extra_text, const gchar *main_text, ...)
{ {
gchar string[512]; gchar *string;
va_list args; va_list args;
gint result;
va_start(args, main_text); va_start(args, main_text);
g_vsnprintf(string, 511, main_text, args); string = g_strdup_vprintf(main_text, args);
va_end(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); string, extra_text);
g_free(string);
return result;
} }

View File

@ -252,13 +252,14 @@ static const GdkColor *get_color(gint msg_color)
**/ **/
void msgwin_compiler_add(gint msg_color, const gchar *format, ...) void msgwin_compiler_add(gint msg_color, const gchar *format, ...)
{ {
gchar string[512]; gchar *string;
va_list args; va_list args;
va_start(args, format); va_start(args, format);
g_vsnprintf(string, 512, format, args); string = g_strdup_vprintf(format, args);
va_end(args); va_end(args);
msgwin_compiler_add_string(msg_color, string); msgwin_compiler_add_string(msg_color, string);
g_free(string);
} }
@ -314,14 +315,15 @@ void msgwin_show_hide(gboolean show)
**/ **/
void msgwin_msg_add(gint msg_color, gint line, GeanyDocument *doc, const gchar *format, ...) void msgwin_msg_add(gint msg_color, gint line, GeanyDocument *doc, const gchar *format, ...)
{ {
gchar string[512]; gchar *string;
va_list args; va_list args;
va_start(args, format); va_start(args, format);
g_vsnprintf(string, 512, format, args); string = g_strdup_vprintf(format, args);
va_end(args); va_end(args);
msgwin_msg_add_string(msg_color, line, doc, string); msgwin_msg_add_string(msg_color, line, doc, string);
g_free(string);
} }
@ -361,18 +363,19 @@ void msgwin_msg_add_string(gint msg_color, gint line, GeanyDocument *doc, const
void msgwin_status_add(const gchar *format, ...) void msgwin_status_add(const gchar *format, ...)
{ {
GtkTreeIter iter; GtkTreeIter iter;
gchar string[512]; gchar *string;
gchar *statusmsg, *time_str; gchar *statusmsg, *time_str;
va_list args; va_list args;
va_start(args, format); va_start(args, format);
g_vsnprintf(string, 512, format, args); string = g_strdup_vprintf(format, args);
va_end(args); va_end(args);
/* add a timestamp to status messages */ /* add a timestamp to status messages */
time_str = utils_get_current_time_string(); time_str = utils_get_current_time_string();
statusmsg = g_strconcat(time_str, ": ", string, NULL); statusmsg = g_strconcat(time_str, ": ", string, NULL);
g_free(time_str); g_free(time_str);
g_free(string);
/* add message to Status window */ /* add message to Status window */
gtk_list_store_append(msgwindow.store_status, &iter); gtk_list_store_append(msgwindow.store_status, &iter);

View File

@ -140,11 +140,11 @@ static void set_statusbar(const gchar *text, gboolean allow_override)
* @param format A @c printf -style string. */ * @param format A @c printf -style string. */
void ui_set_statusbar(gboolean log, const gchar *format, ...) void ui_set_statusbar(gboolean log, const gchar *format, ...)
{ {
gchar string[512]; gchar *string;
va_list args; va_list args;
va_start(args, format); va_start(args, format);
g_vsnprintf(string, 512, format, args); string = g_strdup_vprintf(format, args);
va_end(args); va_end(args);
if (! prefs.suppress_status_messages) if (! prefs.suppress_status_messages)
@ -152,6 +152,8 @@ void ui_set_statusbar(gboolean log, const gchar *format, ...)
if (log || prefs.suppress_status_messages) if (log || prefs.suppress_status_messages)
msgwin_status_add("%s", string); msgwin_status_add("%s", string);
g_free(string);
} }