summaryrefslogtreecommitdiffstats
path: root/gtk/src
diff options
context:
space:
mode:
authorJohn Stebbins <[email protected]>2018-06-20 11:07:10 -0700
committerJohn Stebbins <[email protected]>2018-06-20 11:08:53 -0700
commit826d1a7fb862c292195d766f72c51dce120b47bd (patch)
tree97f9cffeaf176bbe7409caef17c904403578e973 /gtk/src
parent5c67bc7dd3be7e2a0e71c4fe9dc6b871d354091d (diff)
LinGui: handle missing $HOME directory
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
Diffstat (limited to 'gtk/src')
-rw-r--r--gtk/src/callbacks.c17
-rw-r--r--gtk/src/main.c7
-rw-r--r--gtk/src/presets.c37
3 files changed, 37 insertions, 24 deletions
diff --git a/gtk/src/callbacks.c b/gtk/src/callbacks.c
index b14f849b0..940b9b975 100644
--- a/gtk/src/callbacks.c
+++ b/gtk/src/callbacks.c
@@ -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,
diff --git a/gtk/src/main.c b/gtk/src/main.c
index c0abea34b..0cf616f74 100644
--- a/gtk/src/main.c
+++ b/gtk/src/main.c
@@ -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)
diff --git a/gtk/src/presets.c b/gtk/src/presets.c
index 4ca147c07..58e9da11c 100644
--- a/gtk/src/presets.c
+++ b/gtk/src/presets.c
@@ -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);