diff options
author | Marc-André Lureau <marcandre.lureau@gmail.com> | 2012-07-09 03:54:55 +0200 |
---|---|---|
committer | Marc-André Lureau <marcandre.lureau@gmail.com> | 2012-07-16 12:49:24 +0200 |
commit | 6007a4b0b109855f8521ba93ed10b3a1d2bf77f2 (patch) | |
tree | 3d0957dd1f3fa8ed566410ccee1037d16eb401ec | |
parent | 11819933e2d0b8833dfd7a0173f66be989a5a914 (diff) | |
download | glib-6007a4b0b109855f8521ba93ed10b3a1d2bf77f2.tar.gz |
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
-rw-r--r-- | glib/genviron.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/glib/genviron.c b/glib/genviron.c index 59a8bbec2..4abf77676 100644 --- a/glib/genviron.c +++ b/glib/genviron.c @@ -633,10 +633,15 @@ g_get_environ (void) gint i, n; strings = GetEnvironmentStringsW (); - for (n = 0; strings[n]; n += wcslen (strings + n) + 1); - result = g_new (char *, n + 1); - for (i = 0; strings[i]; i += wcslen (strings + i) + 1) - result[i] = g_utf16_to_utf8 (strings + i, -1, NULL, NULL, NULL); + for (n = 0, i = 0; strings[n]; i++) + n += wcslen (strings + n) + 1; + + 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); result[i] = NULL; |