Don't write out of bounds.
authorMatthias Clasen <mclasen@redhat.com>
Tue, 8 Feb 2005 15:14:31 +0000 (15:14 +0000)
committerMatthias Clasen <matthiasc@src.gnome.org>
Tue, 8 Feb 2005 15:14:31 +0000 (15:14 +0000)
2005-02-08  Matthias Clasen  <mclasen@redhat.com>

* glib/gkeyfile.c (g_key_file_parse_value_as_string): Don't
write out of bounds.

* glib/goption.c (g_option_context_parse): Fix a
one-too-short memory allocation.  (#166609, Nicolas Laurent)

* tests/Makefile.am (TESTS_ENVIRONMENT): Add tests with
MALLOC_CHECK_.

* tests/option-test.c: Add a test for unkown short options.

ChangeLog
ChangeLog.pre-2-10
ChangeLog.pre-2-12
ChangeLog.pre-2-8
glib/gkeyfile.c
glib/goption.c
tests/Makefile.am
tests/option-test.c

index 3101db1c578d67d3aa1003c7a531e7fc99d64760..49b5ef8bcb0de82ea5f0273aedb148c3a5f13ec9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2005-02-08  Matthias Clasen  <mclasen@redhat.com>
+
+       * glib/gkeyfile.c (g_key_file_parse_value_as_string): Don't
+       write out of bounds.
+
+       * glib/goption.c (g_option_context_parse): Fix a 
+       one-too-short memory allocation.  (#166609, Nicolas Laurent)
+
+       * tests/Makefile.am (TESTS_ENVIRONMENT): Add tests with
+       MALLOC_CHECK_.
+
+       * tests/option-test.c: Add a test for unkown short options.
+
 2005-02-07  Matthias Clasen  <mclasen@redhat.com>
 
        * glib/glib.symbols: 
index 3101db1c578d67d3aa1003c7a531e7fc99d64760..49b5ef8bcb0de82ea5f0273aedb148c3a5f13ec9 100644 (file)
@@ -1,3 +1,16 @@
+2005-02-08  Matthias Clasen  <mclasen@redhat.com>
+
+       * glib/gkeyfile.c (g_key_file_parse_value_as_string): Don't
+       write out of bounds.
+
+       * glib/goption.c (g_option_context_parse): Fix a 
+       one-too-short memory allocation.  (#166609, Nicolas Laurent)
+
+       * tests/Makefile.am (TESTS_ENVIRONMENT): Add tests with
+       MALLOC_CHECK_.
+
+       * tests/option-test.c: Add a test for unkown short options.
+
 2005-02-07  Matthias Clasen  <mclasen@redhat.com>
 
        * glib/glib.symbols: 
index 3101db1c578d67d3aa1003c7a531e7fc99d64760..49b5ef8bcb0de82ea5f0273aedb148c3a5f13ec9 100644 (file)
@@ -1,3 +1,16 @@
+2005-02-08  Matthias Clasen  <mclasen@redhat.com>
+
+       * glib/gkeyfile.c (g_key_file_parse_value_as_string): Don't
+       write out of bounds.
+
+       * glib/goption.c (g_option_context_parse): Fix a 
+       one-too-short memory allocation.  (#166609, Nicolas Laurent)
+
+       * tests/Makefile.am (TESTS_ENVIRONMENT): Add tests with
+       MALLOC_CHECK_.
+
+       * tests/option-test.c: Add a test for unkown short options.
+
 2005-02-07  Matthias Clasen  <mclasen@redhat.com>
 
        * glib/glib.symbols: 
index 3101db1c578d67d3aa1003c7a531e7fc99d64760..49b5ef8bcb0de82ea5f0273aedb148c3a5f13ec9 100644 (file)
@@ -1,3 +1,16 @@
+2005-02-08  Matthias Clasen  <mclasen@redhat.com>
+
+       * glib/gkeyfile.c (g_key_file_parse_value_as_string): Don't
+       write out of bounds.
+
+       * glib/goption.c (g_option_context_parse): Fix a 
+       one-too-short memory allocation.  (#166609, Nicolas Laurent)
+
+       * tests/Makefile.am (TESTS_ENVIRONMENT): Add tests with
+       MALLOC_CHECK_.
+
+       * tests/option-test.c: Add a test for unkown short options.
+
 2005-02-07  Matthias Clasen  <mclasen@redhat.com>
 
        * glib/glib.symbols: 
index 6fe8eeed0b20d293600711349728d3b103a644ba..f0479197459bab93218b691c3ce3d6a6f8c12abf 100644 (file)
@@ -3014,6 +3014,13 @@ g_key_file_parse_value_as_string (GKeyFile     *key_file,
               *q = '\\';
               break;
 
+           case '\0':
+             g_set_error (error, G_KEY_FILE_ERROR,
+                          G_KEY_FILE_ERROR_INVALID_VALUE,
+                          _("Key file contains escape character "
+                            "at end of line"));
+             break;
+
             default:
              if (pieces && *p == key_file->list_separator)
                *q = key_file->list_separator;
@@ -3049,15 +3056,13 @@ g_key_file_parse_value_as_string (GKeyFile     *key_file,
            }
        }
 
+      if (*p == '\0')
+       break;
+
       q++;
       p++;
     }
 
-  if (p > value && p[-1] == '\\' && q[-1] != '\\' && *error == NULL)
-    g_set_error (error, G_KEY_FILE_ERROR,
-                G_KEY_FILE_ERROR_INVALID_VALUE,
-                _("Key file contains escape character at end of line"));
-
   *q = '\0';
   if (pieces)
   {
index a8a124e86ac2e366d0684d533cdf61a3d3f999b0..a7ff836bcd5d0c75ef7335815f2e372922bcd2a9 100644 (file)
@@ -1297,7 +1297,7 @@ g_option_context_parse (GOptionContext   *context,
                          if (!nulled_out[j])
                            {
                              if (!new_arg)
-                               new_arg = g_malloc (strlen (arg));
+                               new_arg = g_malloc (strlen (arg) + 1);
                              new_arg[arg_index++] = arg[j];
                            }
                        }
index e78fd00fa89f742bbd6d3e458e75bc7a8ca9920c..a3507aa302cd71e22d82ecee6b53cb366e7957b5 100644 (file)
@@ -111,7 +111,8 @@ check_PROGRAMS = $(test_programs) $(test_script_support_programs)
 
 TESTS = $(test_programs) $(test_scripts)
 TESTS_ENVIRONMENT = srcdir=$(srcdir) \
-       LIBCHARSET_ALIAS_DIR=$(top_builddir)/glib/libcharset
+       LIBCHARSET_ALIAS_DIR=$(top_builddir)/glib/libcharset \
+       MALLOC_CHECK_=2
 
 progs_ldadd = $(EFENCE) $(libglib) $(EFENCE)
 thread_ldadd = $(libgthread) $(G_THREAD_LIBS) $(progs_ldadd)
index a40faecf061153b17dc214002ec7f905f3c21470..9642b0fecdc6cf1748909f71fc47125b88915858 100644 (file)
@@ -1,5 +1,4 @@
 #include <glib.h>
-#include "goption.h"
 #include <string.h>
 
 int error_test1_int;
@@ -837,6 +836,28 @@ rest_test5 (void)
   g_option_context_free (context);
 }
 
+void
+unknown_short_test (void)
+{
+  GOptionContext *context;
+  gboolean retval;
+  GError *error = NULL;
+  gchar **argv;
+  int argc;
+  GOptionEntry entries [] = { { NULL } };
+
+  context = g_option_context_new (NULL);
+  g_option_context_add_main_entries (context, entries, NULL);
+
+  /* Now try parsing */
+  argv = split_string ("program -0", &argc);
+
+  retval = g_option_context_parse (context, &argc, &argv, &error);
+  g_assert (!retval);
+
+  g_strfreev (argv);
+  g_option_context_free (context);
+}
 
 int
 main (int argc, char **argv)
@@ -880,5 +901,8 @@ main (int argc, char **argv)
   rest_test4 ();
   rest_test5 ();
 
+  /* test for bug 166609 */
+  unknown_short_test ();
+
   return 0;
 }