]> granicus.if.org Git - handbrake/commitdiff
LinGui: handle missing $HOME directory
authorJohn Stebbins <jstebbins.hb@gmail.com>
Wed, 20 Jun 2018 18:07:10 +0000 (11:07 -0700)
committerJohn Stebbins <jstebbins.hb@gmail.com>
Wed, 20 Jun 2018 18:08:53 +0000 (11:08 -0700)
Improves determination of a user config dir under these circumstances
and prevents access to NULL file pointer

Fixes https://github.com/HandBrake/HandBrake/issues/1432

gtk/src/callbacks.c
gtk/src/main.c
gtk/src/presets.c

index b14f849b03373725fa80486c78eba70ab9607967..940b9b975d4b33db0bffdfd1707f8666c5a0d4e5 100644 (file)
@@ -4488,17 +4488,20 @@ ghb_log_cb(GIOChannel *source, GIOCondition cond, gpointer data)
                 scroll_tok = g_idle_add((GSourceFunc)activity_scroll_to_bottom,
                                         ud);
             }
+            if (ud->activity_log != NULL)
+            {
 #if defined(_WIN32)
-            gsize one = 1;
-            utf8_text[length-1] = '\r';
+                gsize one = 1;
+                utf8_text[length-1] = '\r';
 #endif
-            g_io_channel_write_chars (ud->activity_log, utf8_text,
-                                    length, &outlength, NULL);
+                g_io_channel_write_chars (ud->activity_log, utf8_text,
+                                        length, &outlength, NULL);
 #if defined(_WIN32)
-            g_io_channel_write_chars (ud->activity_log, "\n",
-                                    one, &one, NULL);
+                g_io_channel_write_chars (ud->activity_log, "\n",
+                                        one, &one, NULL);
 #endif
-            g_io_channel_flush(ud->activity_log, NULL);
+                g_io_channel_flush(ud->activity_log, NULL);
+            }
             if (ud->job_activity_log)
             {
                 g_io_channel_write_chars (ud->job_activity_log, utf8_text,
index c0abea34b34174678b0823fcda07c6c6c1db5060..0cf616f74d371d35ff586a59cf90d80d101616c5 100644 (file)
@@ -625,8 +625,11 @@ IoRedirect(signal_user_data_t *ud)
     g_free(str);
     g_free(path);
     g_free(config);
-    // Set encoding to raw.
-    g_io_channel_set_encoding(ud->activity_log, NULL, NULL);
+    if (ud->activity_log != NULL)
+    {
+        // Set encoding to raw.
+        g_io_channel_set_encoding(ud->activity_log, NULL, NULL);
+    }
     // redirect stderr to the writer end of the pipe
 
 #if defined(_WIN32)
index 4ca147c07ca1a61fbedc31f01900a846c97400a9..58e9da11ca63968b467ca21684258f4dbbc8cad1 100644 (file)
@@ -636,11 +636,11 @@ ghb_select_default_preset(signal_user_data_t *ud)
     }
 }
 
-gchar*
+gchar *
 ghb_get_user_config_dir(gchar *subdir)
 {
-    const gchar *dir;
-    gchar       *config;
+    const gchar * dir, * ghb = "ghb";
+    gchar       * config;
 
     if (override_user_config_dir != NULL)
     {
@@ -650,19 +650,20 @@ ghb_get_user_config_dir(gchar *subdir)
     {
         dir = g_get_user_config_dir();
     }
-    if (!g_file_test(dir, G_FILE_TEST_IS_DIR))
+    if (dir == NULL || !g_file_test(dir, G_FILE_TEST_IS_DIR))
     {
-        dir    = g_get_home_dir();
-        config = g_strdup_printf ("%s/.ghb", dir);
-        if (!g_file_test(config, G_FILE_TEST_IS_DIR))
-            g_mkdir (config, 0755);
+        dir = g_get_home_dir();
+        ghb = ".ghb";
     }
-    else
+    if (dir == NULL || !g_file_test(dir, G_FILE_TEST_IS_DIR))
     {
-        config = g_strdup_printf ("%s/ghb", dir);
-        if (!g_file_test(config, G_FILE_TEST_IS_DIR))
-            g_mkdir (config, 0755);
+        // Last ditch, use CWD
+        dir = "./";
+        ghb = ".ghb";
     }
+    config = g_strdup_printf("%s/%s", dir, ghb);
+    if (!g_file_test(config, G_FILE_TEST_IS_DIR))
+        g_mkdir (config, 0755);
     if (subdir)
     {
         gchar **split;
@@ -835,11 +836,17 @@ ghb_write_pid_file()
     path   = g_strdup_printf ("%s/ghb.pid.%d", config, pid);
     fp     = g_fopen(path, "w");
 
-    fprintf(fp, "%d\n", pid);
-    fclose(fp);
+    if (fp != NULL)
+    {
+        fprintf(fp, "%d\n", pid);
+        fclose(fp);
+    }
 
     fd = open(path, O_RDWR|O_CREAT, S_IRUSR|S_IWUSR);
-    lockf(fd, F_TLOCK, 0);
+    if (fd >= 0)
+    {
+        lockf(fd, F_TLOCK, 0);
+    }
 
     g_free(config);
     g_free(path);