[yelp/wip/amigadave/webkit2-port: 1/24] Fix crash when viewing man pages



commit e39830936572fab020de49d3e7ac520478214aab
Author: David King <amigadave amigadave com>
Date:   Mon Feb 16 19:58:42 2015 +0000

    Fix crash when viewing man pages
    
    Calling g_strfreev() on a stack-allocated array is a bad idea.

 libyelp/yelp-man-parser.c |   13 ++++++++-----
 libyelp/yelp-uri.c        |   16 ++++++++++------
 2 files changed, 18 insertions(+), 11 deletions(-)
---
diff --git a/libyelp/yelp-man-parser.c b/libyelp/yelp-man-parser.c
index 508487c..46073a2 100644
--- a/libyelp/yelp-man-parser.c
+++ b/libyelp/yelp-man-parser.c
@@ -369,21 +369,24 @@ get_troff (gchar *path, GError **error)
 {
     gint ystdout;
     GError *err = NULL;
-    gchar *argv[] = { g_strdup ("man"), g_strdup ("-Z"), g_strdup ("-Tutf8"),
-                      g_strdup ("-EUTF-8"), g_strdup (path), NULL };
+    const gchar *argv[] = { "man", "-Z", "-Tutf8", "-EUTF-8", path, NULL };
+    gchar **my_argv;
 
-    if (!g_spawn_async_with_pipes (NULL, argv, NULL,
+    /* g_strdupv() should accept a "const gchar **". */
+    my_argv = g_strdupv ((gchar **) argv);
+
+    if (!g_spawn_async_with_pipes (NULL, my_argv, NULL,
                                    G_SPAWN_SEARCH_PATH, NULL, NULL,
                                    NULL, NULL, &ystdout, NULL, &err)) {
         /* We failed to run the man program. Return a "Huh?" error. */
         *error = g_error_new (YELP_ERROR, YELP_ERROR_UNKNOWN,
                               "%s", err->message);
         g_error_free (err);
-        g_strfreev (argv);
+        g_strfreev (my_argv);
         return NULL;
     }
 
-    g_strfreev (argv);
+    g_strfreev (my_argv);
 
     return (GInputStream*) g_unix_input_stream_new (ystdout, TRUE);
 }
diff --git a/libyelp/yelp-uri.c b/libyelp/yelp-uri.c
index 81f2c3c..662da24 100644
--- a/libyelp/yelp-uri.c
+++ b/libyelp/yelp-uri.c
@@ -916,7 +916,8 @@ resolve_help_list_uri (YelpUri *uri)
 static gchar*
 find_man_path (gchar* name, gchar* section)
 {
-    gchar* argv[] = { g_strdup ("man"), g_strdup ("-w"), NULL, NULL, NULL };
+    const gchar* argv[] = { "man", "-w", NULL, NULL, NULL };
+    gchar **my_argv;
     gchar *ystdout = NULL;
     gint status;
     gchar **lines;
@@ -925,13 +926,16 @@ find_man_path (gchar* name, gchar* section)
     /* Syntax for man is "man -w <section> <name>", possibly omitting
        section */
     if (section) {
-        argv[2] = g_strdup (section);
-        argv[3] = g_strdup (name);
+        argv[2] = section;
+        argv[3] = name;
     } else {
-        argv[2] = g_strdup (name);
+        argv[2] = name;
     }
 
-    if (!g_spawn_sync (NULL, argv, NULL,
+    /* g_strdupv() should accept a "const gchar **". */
+    my_argv = g_strdupv ((gchar **) argv);
+
+    if (!g_spawn_sync (NULL, my_argv, NULL,
                        G_SPAWN_SEARCH_PATH | G_SPAWN_STDERR_TO_DEV_NULL,
                        NULL, NULL,
                        &ystdout, NULL, &status, &error)) {
@@ -940,7 +944,7 @@ find_man_path (gchar* name, gchar* section)
         g_error_free (error);
     }
 
-    g_strfreev (argv);
+    g_strfreev (my_argv);
 
     if (status == 0) {
         lines = g_strsplit (ystdout, "\n", 2);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]