Branch: refs/heads/master Author: Colomban Wendling ban@herbesfolles.org Committer: Colomban Wendling ban@herbesfolles.org Date: Thu, 06 Mar 2014 14:01:38 UTC Commit: 717f8e1b137f7a51a78ffbf12d1c0c15b1784bc3 https://github.com/geany/geany/commit/717f8e1b137f7a51a78ffbf12d1c0c15b1784b...
Log Message: ----------- Windows: fix possible buffer overflows
Fix improper use of MultiByteToWideChar() that could have led to buffer overflows.
Modified Paths: -------------- src/win32.c
Modified: src/win32.c 32 files changed, 16 insertions(+), 16 deletions(-) =================================================================== @@ -123,7 +123,7 @@ static wchar_t *get_file_filters(void) len = strlen(string); g_strdelimit(string, "\t", '\0'); g_assert(string[len - 1] == 0x0); - MultiByteToWideChar(CP_UTF8, 0, string, len, title, sizeof(title)); + MultiByteToWideChar(CP_UTF8, 0, string, len, title, G_N_ELEMENTS(title)); g_free(string);
return title; @@ -142,7 +142,7 @@ static wchar_t *get_file_filter_all_files(void) len = strlen(filter); g_strdelimit(filter, "\t", '\0'); g_assert(filter[len - 1] == 0x0); - MultiByteToWideChar(CP_UTF8, 0, filter, len, title, sizeof(title)); + MultiByteToWideChar(CP_UTF8, 0, filter, len, title, G_N_ELEMENTS(title)); g_free(filter);
return title; @@ -170,7 +170,7 @@ static wchar_t *get_filters(gboolean project_files) len = strlen(string); g_strdelimit(string, "\t", '\0'); g_assert(string[len - 1] == 0x0); - MultiByteToWideChar(CP_UTF8, 0, string, len, title, sizeof(title)); + MultiByteToWideChar(CP_UTF8, 0, string, len, title, G_N_ELEMENTS(title)); g_free(string);
return title; @@ -189,7 +189,7 @@ static wchar_t *get_dir_for_path(const gchar *utf8_filename) else result = g_path_get_dirname(utf8_filename);
- MultiByteToWideChar(CP_UTF8, 0, result, -1, w_dir, sizeof(w_dir)); + MultiByteToWideChar(CP_UTF8, 0, result, -1, w_dir, G_N_ELEMENTS(w_dir));
if (result != utf8_filename) g_free(result); @@ -237,7 +237,7 @@ gchar *win32_show_folder_dialog(GtkWidget *parent, const gchar *title, const gch wchar_t fname[MAX_PATH]; wchar_t w_title[512];
- MultiByteToWideChar(CP_UTF8, 0, title, -1, w_title, sizeof(w_title)); + MultiByteToWideChar(CP_UTF8, 0, title, -1, w_title, G_N_ELEMENTS(w_title));
if (parent == NULL) parent = main_widgets.window; @@ -284,7 +284,7 @@ gchar *win32_show_project_open_dialog(GtkWidget *parent, const gchar *title,
fname[0] = '\0';
- MultiByteToWideChar(CP_UTF8, 0, title, -1, w_title, sizeof(w_title)); + MultiByteToWideChar(CP_UTF8, 0, title, -1, w_title, G_N_ELEMENTS(w_title));
if (parent == NULL) parent = main_widgets.window; @@ -347,9 +347,9 @@ gboolean win32_show_document_open_dialog(GtkWindow *parent, const gchar *title, fname[0] = '\0';
if (initial_dir != NULL) - MultiByteToWideChar(CP_UTF8, 0, initial_dir, -1, w_dir, sizeof(w_dir)); + MultiByteToWideChar(CP_UTF8, 0, initial_dir, -1, w_dir, G_N_ELEMENTS(w_dir));
- MultiByteToWideChar(CP_UTF8, 0, title, -1, w_title, sizeof(w_title)); + MultiByteToWideChar(CP_UTF8, 0, title, -1, w_title, G_N_ELEMENTS(w_title));
/* initialise file dialog info struct */ memset(&of, 0, sizeof of); @@ -430,9 +430,9 @@ gchar *win32_show_document_save_as_dialog(GtkWindow *parent, const gchar *title, w_file[0] = '\0';
if (initial_file != NULL) - MultiByteToWideChar(CP_UTF8, 0, initial_file, -1, w_file, sizeof(w_file)); + MultiByteToWideChar(CP_UTF8, 0, initial_file, -1, w_file, G_N_ELEMENTS(w_file));
- MultiByteToWideChar(CP_UTF8, 0, title, -1, w_title, sizeof(w_title)); + MultiByteToWideChar(CP_UTF8, 0, title, -1, w_title, G_N_ELEMENTS(w_title));
/* initialise file dialog info struct */ memset(&of, 0, sizeof of); @@ -486,9 +486,9 @@ gchar *win32_show_file_dialog(GtkWindow *parent, const gchar *title, const gchar w_file[0] = '\0';
if (initial_file != NULL) - MultiByteToWideChar(CP_UTF8, 0, initial_file, -1, w_file, sizeof(w_file)); + MultiByteToWideChar(CP_UTF8, 0, initial_file, -1, w_file, G_N_ELEMENTS(w_file));
- MultiByteToWideChar(CP_UTF8, 0, title, -1, w_title, sizeof(w_title)); + MultiByteToWideChar(CP_UTF8, 0, title, -1, w_title, G_N_ELEMENTS(w_title));
/* initialise file dialog info struct */ memset(&of, 0, sizeof of); @@ -599,7 +599,7 @@ void win32_show_pref_file_dialog(GtkEntry *item) filename = g_find_program_in_path(field[0]); if (filename != NULL && g_file_test(filename, G_FILE_TEST_EXISTS)) { - MultiByteToWideChar(CP_UTF8, 0, filename, -1, fname, sizeof(fname)); + MultiByteToWideChar(CP_UTF8, 0, filename, -1, fname, G_N_ELEMENTS(fname)); g_free(filename); } } @@ -722,7 +722,7 @@ gboolean win32_message_dialog(GtkWidget *parent, GtkMessageType type, const gcha gint win32_check_write_permission(const gchar *dir) { static wchar_t w_dir[MAX_PATH]; - MultiByteToWideChar(CP_UTF8, 0, dir, -1, w_dir, sizeof w_dir); + MultiByteToWideChar(CP_UTF8, 0, dir, -1, w_dir, G_N_ELEMENTS(w_dir)); if (_waccess(w_dir, R_OK | W_OK) != 0) return errno; else @@ -1170,8 +1170,8 @@ static gboolean CreateChildProcess(geany_win32_spawn *gw_spawn, TCHAR *szCmdline /* Expand environment variables like %blah%. */ expandedCmdline = win32_expand_environment_variables(szCmdline);
- MultiByteToWideChar(CP_UTF8, 0, expandedCmdline, -1, w_commandline, sizeof(w_commandline)); - MultiByteToWideChar(CP_UTF8, 0, dir, -1, w_dir, sizeof(w_dir)); + MultiByteToWideChar(CP_UTF8, 0, expandedCmdline, -1, w_commandline, G_N_ELEMENTS(w_commandline)); + MultiByteToWideChar(CP_UTF8, 0, dir, -1, w_dir, G_N_ELEMENTS(w_dir));
/* Create the child process. */ bFuncRetn = CreateProcessW(NULL,
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).