[PATCH] windows.c: Use a zeroed buffer when retrieving the module path

Lubomir I. Ivanov neolit123 at gmail.com
Tue Mar 5 12:24:15 PST 2013


From: "Lubomir I. Ivanov" <neolit123 at gmail.com>

There is a small API note on GetModuleFileName(), which says:
"Windows XP: The string is truncated to nSize characters
and is not null-terminated."

Which means that on XP it will be only safe if we pass a zeroed
buffer to it, otherwise the next call to wcsrchr (which is
a strchr for wchar_t) may not find a relative terminating \0 in
the buffer, returning a wrong pointer and resulting in a corrupted
string.

Signed-off-by: Lubomir I. Ivanov <neolit123 at gmail.com>
---

apparently i've missed a small API note. sorry about that...

---
 windows.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/windows.c b/windows.c
index 6f40a26..f06ffc7 100644
--- a/windows.c
+++ b/windows.c
@@ -243,7 +243,7 @@ extern int __wgetmainargs(int *, wchar_t ***, wchar_t ***, int, int *);
 /* expand-convert the UTF-16 argument list to a list of UTF-8 strings */
 void subsurface_command_line_init(gint *argc, gchar ***argv)
 {
-	wchar_t **wargv, **wenviron, *p, path[MAX_PATH];
+	wchar_t **wargv, **wenviron, *p, path[MAX_PATH] = {0};
 	gchar **argv_new;
 	gchar *s;
 	/* for si we assume that a struct address will equal the address
-- 
1.7.11.msysgit.0



More information about the subsurface mailing list