win32: fix g_get_environ()

The current code create the strv array incorrectly, it is too big and
leaves invalid holes. This may result in crashes when freeing the
returned value.

https://bugzilla.gnome.org/show_bug.cgi?id=679617
This commit is contained in:
Marc-André Lureau 2012-07-09 03:54:55 +02:00
parent 11819933e2
commit 6007a4b0b1

View File

@ -633,10 +633,15 @@ g_get_environ (void)
gint i, n; gint i, n;
strings = GetEnvironmentStringsW (); strings = GetEnvironmentStringsW ();
for (n = 0; strings[n]; n += wcslen (strings + n) + 1); for (n = 0, i = 0; strings[n]; i++)
result = g_new (char *, n + 1); n += wcslen (strings + n) + 1;
for (i = 0; strings[i]; i += wcslen (strings + i) + 1)
result[i] = g_utf16_to_utf8 (strings + i, -1, NULL, NULL, NULL); result = g_new (char *, i + 1);
for (n = 0, i = 0; strings[n]; i++)
{
result[i] = g_utf16_to_utf8 (strings + n, -1, NULL, NULL, NULL);
n += wcslen (strings + n) + 1;
}
FreeEnvironmentStringsW (strings); FreeEnvironmentStringsW (strings);
result[i] = NULL; result[i] = NULL;