diff options
author | Josh Rickmar <jrick@devio.us> | 2012-06-06 14:40:29 -0400 |
---|---|---|
committer | Josh Rickmar <jrick@devio.us> | 2012-06-07 09:11:35 -0400 |
commit | 8c87a2283c7cec587d11bcd165dfe0408451aea6 (patch) | |
tree | f62dd6ec0c8f98a7e5a65754060bac8a6aca68b9 /xombrero.c | |
parent | 3298d9a24118b28173f3b606d7aed8fd8fee44f7 (diff) | |
download | xombrero-8c87a2283c7cec587d11bcd165dfe0408451aea6.tar.gz |
Set default char * setting pointers to NULL and g_strdup the default
values from static memory, as they will be g_free()'d later if changed at runtime or from parsing the config. "Special" settings (struct special) do not need this as they use their own set functions. This also fixes a bad bug where default_script pointed to "" somewhere in static memory instead of an array of PATH_MAX size. This fixes a crash when compiled with clang where changing this setting would try to write a string possibly as large as PATH_MAX and overwrite other static data. Finally, make ssl_ca_file static to match all the other strings that represent files or directories. Make it a special setting so static memory is never freed. As an added bonus, ssl_ca_file is now tilde expanded.
Diffstat (limited to 'xombrero.c')
-rw-r--r-- | xombrero.c | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/xombrero.c b/xombrero.c index 3dcae0f..1d63855 100644 --- a/xombrero.c +++ b/xombrero.c @@ -455,7 +455,7 @@ get_current_tab(void) } int -set_ssl_ca_file(char *file) +set_ssl_ca_file(struct settings *s, char *file) { struct stat sb; @@ -465,9 +465,7 @@ set_ssl_ca_file(char *file) warnx("no CA file: %s", file); return (-1); } - if (ssl_ca_file) - g_free(ssl_ca_file); - ssl_ca_file = g_strdup(file); + expand_tilde(ssl_ca_file, sizeof ssl_ca_file, file); g_object_set(session, SOUP_SESSION_SSL_CA_FILE, ssl_ca_file, SOUP_SESSION_SSL_STRICT, ssl_strict_certs, @@ -1937,6 +1935,7 @@ done: int cert_cmd(struct tab *t, struct karg *args) { + struct stat sb; const gchar *uri, *error_str = NULL; char domain[8182]; int s = -1; @@ -1948,7 +1947,7 @@ cert_cmd(struct tab *t, struct karg *args) if (t == NULL) return (1); - if (ssl_ca_file == NULL) { + if (stat(ssl_ca_file, &sb)) { show_oops(t, "Can't open CA file: %s", ssl_ca_file); return (1); } @@ -3611,6 +3610,7 @@ void show_ca_status(struct tab *t, const char *uri) { GdkColor color; + struct stat sb; gchar *col_str = XT_COLOR_WHITE, *text, *base; DNPRINTF(XT_D_URL, "show_ca_status: %d %s %s\n", @@ -3621,7 +3621,7 @@ show_ca_status(struct tab *t, const char *uri) if (uri == NULL) goto done; - if (ssl_ca_file == NULL) { + if (stat(ssl_ca_file, &sb)) { if (g_str_has_prefix(uri, "http://")) goto done; if (g_str_has_prefix(uri, "https://")) { @@ -7932,7 +7932,7 @@ main(int argc, char **argv) /* compile buffer command regexes */ buffercmd_init(); - /* set default string settings */ + /* set default dynamic string settings */ home = g_strdup(XT_DS_HOME); search_string = g_strdup(XT_DS_SEARCH_STRING); resource_dir = g_strdup("/usr/local/share/xombrero/"); @@ -7944,6 +7944,13 @@ main(int argc, char **argv) statusbar_elems = g_strdup("BP"); spell_check_languages = g_strdup(XT_DS_SPELL_CHECK_LANGUAGES); encoding = g_strdup(XT_DS_ENCODING); + spell_check_languages = g_strdup(XT_DS_SPELL_CHECK_LANGUAGES); + + /* set statically allocated (struct special) settings */ + expand_tilde(default_script, sizeof default_script, + XT_DS_DEFAULT_SCRIPT); + expand_tilde(ssl_ca_file, sizeof ssl_ca_file, + XT_DS_SSL_CA_FILE); /* read config file */ if (strlen(conf) == 0) @@ -8071,9 +8078,6 @@ main(int argc, char **argv) session = webkit_get_default_session(); setup_cookies(); - /* certs */ - set_ssl_ca_file(ssl_ca_file); - /* guess_search regex */ if (url_regex == NULL) url_regex = g_strdup(XT_URL_REGEX); |