From 6e3b71aec363e41035bbe7f7bda30a14a40c9662 Mon Sep 17 00:00:00 2001 From: Roozbeh Pournader Date: Wed, 26 Nov 2003 13:22:42 +0000 Subject: [PATCH] Fixed a bad pointer comparison in g_ascii_strtod that came up in fa_IR Wed Nov 26 16:45:16 2003 Roozbeh Pournader * glib/gstrfuncs.c: Fixed a bad pointer comparison in g_ascii_strtod that came up in fa_IR locale (#126640, Behdad Esfahbod). * tests/strtod-test.c: Fixed the tests to catch the above. --- ChangeLog | 8 ++++++++ ChangeLog.pre-2-10 | 8 ++++++++ ChangeLog.pre-2-12 | 8 ++++++++ ChangeLog.pre-2-4 | 8 ++++++++ ChangeLog.pre-2-6 | 8 ++++++++ ChangeLog.pre-2-8 | 8 ++++++++ glib/gstrfuncs.c | 2 +- tests/strtod-test.c | 12 +++++++++++- 8 files changed, 60 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index c57480c17..c5719123e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +Wed Nov 26 16:45:16 2003 Roozbeh Pournader + + * glib/gstrfuncs.c: Fixed a bad pointer comparison in + g_ascii_strtod that came up in fa_IR locale (#126640, Behdad + Esfahbod). + + * tests/strtod-test.c: Fixed the tests to catch the above. + Sat Nov 22 14:16:51.15 2003 Andrew Lanoix * glib/giowin32.c: Bind inter-thread comminication diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index c57480c17..c5719123e 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,11 @@ +Wed Nov 26 16:45:16 2003 Roozbeh Pournader + + * glib/gstrfuncs.c: Fixed a bad pointer comparison in + g_ascii_strtod that came up in fa_IR locale (#126640, Behdad + Esfahbod). + + * tests/strtod-test.c: Fixed the tests to catch the above. + Sat Nov 22 14:16:51.15 2003 Andrew Lanoix * glib/giowin32.c: Bind inter-thread comminication diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index c57480c17..c5719123e 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -1,3 +1,11 @@ +Wed Nov 26 16:45:16 2003 Roozbeh Pournader + + * glib/gstrfuncs.c: Fixed a bad pointer comparison in + g_ascii_strtod that came up in fa_IR locale (#126640, Behdad + Esfahbod). + + * tests/strtod-test.c: Fixed the tests to catch the above. + Sat Nov 22 14:16:51.15 2003 Andrew Lanoix * glib/giowin32.c: Bind inter-thread comminication diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index c57480c17..c5719123e 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,11 @@ +Wed Nov 26 16:45:16 2003 Roozbeh Pournader + + * glib/gstrfuncs.c: Fixed a bad pointer comparison in + g_ascii_strtod that came up in fa_IR locale (#126640, Behdad + Esfahbod). + + * tests/strtod-test.c: Fixed the tests to catch the above. + Sat Nov 22 14:16:51.15 2003 Andrew Lanoix * glib/giowin32.c: Bind inter-thread comminication diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index c57480c17..c5719123e 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,11 @@ +Wed Nov 26 16:45:16 2003 Roozbeh Pournader + + * glib/gstrfuncs.c: Fixed a bad pointer comparison in + g_ascii_strtod that came up in fa_IR locale (#126640, Behdad + Esfahbod). + + * tests/strtod-test.c: Fixed the tests to catch the above. + Sat Nov 22 14:16:51.15 2003 Andrew Lanoix * glib/giowin32.c: Bind inter-thread comminication diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index c57480c17..c5719123e 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,11 @@ +Wed Nov 26 16:45:16 2003 Roozbeh Pournader + + * glib/gstrfuncs.c: Fixed a bad pointer comparison in + g_ascii_strtod that came up in fa_IR locale (#126640, Behdad + Esfahbod). + + * tests/strtod-test.c: Fixed the tests to catch the above. + Sat Nov 22 14:16:51.15 2003 Andrew Lanoix * glib/giowin32.c: Bind inter-thread comminication diff --git a/glib/gstrfuncs.c b/glib/gstrfuncs.c index 31c655401..a4d6b1737 100644 --- a/glib/gstrfuncs.c +++ b/glib/gstrfuncs.c @@ -433,7 +433,7 @@ g_ascii_strtod (const gchar *nptr, if (fail_pos) { - if (fail_pos > decimal_point_pos) + if (fail_pos - copy > decimal_point_pos - nptr) fail_pos = (char *)nptr + (fail_pos - copy) - (decimal_point_len - 1); else fail_pos = (char *)nptr + (fail_pos - copy); diff --git a/tests/strtod-test.c b/tests/strtod-test.c index 180d926a9..df1755907 100644 --- a/tests/strtod-test.c +++ b/tests/strtod-test.c @@ -13,6 +13,14 @@ test_string (char *number, double res) char *locales[] = {"sv_SE", "en_US", "fa_IR", "C"}; int l; char *end; + char *dummy; + + /* we try a copy of number, with some free space for malloc before that. + * This is supposed to smash the some wrong pointer calculations. */ + + dummy = g_malloc (100000); + number = g_strdup (number); + g_free (dummy); for (l = 0; l < G_N_ELEMENTS (locales); l++) { @@ -20,9 +28,11 @@ test_string (char *number, double res) d = g_ascii_strtod (number, &end); if (d != res) g_print ("g_ascii_strtod for locale %s failed\n", locales[l]); - if (*end != 0) + if (end - number != strlen(number)) g_print ("g_ascii_strtod for locale %s endptr was wrong\n", locales[l]); } + + g_free (number); }