[gjs/gnome-3-24] context: Avoid null pointer dereference



commit a87e35cb88cac7eb1bbbc2c78f2f900e16c3fc4a
Author: Philip Chimento <philip endlessm com>
Date:   Wed Aug 30 13:41:34 2017 -0700

    context: Avoid null pointer dereference
    
    gjs_context_eval_file() was returning false but not setting the error
    parameter if the file did not exist.
    
    That check makes no sense anyway, since it is also done by
    g_file_load_contents(). Therefore we remove it and take the opportunity
    to refactor the function to use autoptrs.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=786995

 gjs/context.cpp |   32 +++++++++-----------------------
 1 files changed, 9 insertions(+), 23 deletions(-)
---
diff --git a/gjs/context.cpp b/gjs/context.cpp
index 0d84f75..c816dc0 100644
--- a/gjs/context.cpp
+++ b/gjs/context.cpp
@@ -810,31 +810,17 @@ gjs_context_eval_file(GjsContext    *js_context,
                       int           *exit_status_p,
                       GError       **error)
 {
-    char     *script = NULL;
-    gsize    script_len;
-    bool ret = true;
+    char *script;
+    size_t script_len;
+    GjsAutoUnref<GFile> file = g_file_new_for_commandline_arg(filename);
 
-    GFile *file = g_file_new_for_commandline_arg(filename);
-
-    if (!g_file_query_exists(file, NULL)) {
-        ret = false;
-        goto out;
-    }
-
-    if (!g_file_load_contents(file, NULL, &script, &script_len, NULL, error)) {
-        ret = false;
-        goto out;
-    }
-
-    if (!gjs_context_eval(js_context, script, script_len, filename, exit_status_p, error)) {
-        ret = false;
-        goto out;
-    }
+    if (!g_file_load_contents(file, nullptr, &script, &script_len, nullptr,
+                              error))
+        return false;
+    GjsAutoChar script_ref = script;
 
-out:
-    g_free(script);
-    g_object_unref(file);
-    return ret;
+    return gjs_context_eval(js_context, script, script_len, filename,
+                            exit_status_p, error);
 }
 
 bool


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