Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Windows: fix possible buffer overflows

Fix improper use of MultiByteToWideChar() that could have led to
buffer overflows.
  • Loading branch information...
commit 717f8e1b137f7a51a78ffbf12d1c0c15b1784bc3 1 parent 467f56a
@b4n b4n authored
Showing with 16 additions and 16 deletions.
  1. +16 −16 src/win32.c
View
32 src/win32.c
@@ -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,
Please sign in to comment.
Something went wrong with that request. Please try again.