aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2021-07-30 12:47:45 +0000
committerDaniel Eklöf <daniel@ekloef.se>2021-07-30 12:57:35 +0000
commit7cfa48f369403d86dda2944511df0c23ce3dabd0 (patch)
tree6ee9e36daea90e02926a2bf83be7dbac91406549
parentconfig: include: add support for ~-expansion (diff)
config: include: handle get_user_home_dir() returning NULL
-rw-r--r--config.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/config.c b/config.c
index 6b51c506..2c76ffa5 100644
--- a/config.c
+++ b/config.c
@@ -650,6 +650,13 @@ parse_section_main(const char *key, const char *value, struct config *conf,
if (value[0] == '~' && value[1] == '/') {
const char *home_dir = get_user_home_dir();
+ if (home_dir == NULL) {
+ LOG_AND_NOTIFY_ERRNO(
+ "%s:%d: [default]: include: %s: failed to expand '~'",
+ path, lineno, value);
+ return false;
+ }
+
int chars = snprintf(NULL, 0, "%s/%s", home_dir, &value[2]);
_include_path = malloc(chars + 1);
snprintf(_include_path, chars + 1, "%s/%s", home_dir, &value[2]);
@@ -659,7 +666,7 @@ parse_section_main(const char *key, const char *value, struct config *conf,
if (include_path[0] != '/') {
LOG_AND_NOTIFY_ERR(
- "%s:%d: [default]: %s: not an absolute path",
+ "%s:%d: [default]: include: %s: not an absolute path",
path, lineno, include_path);
free(_include_path);
return false;
@@ -669,7 +676,7 @@ parse_section_main(const char *key, const char *value, struct config *conf,
if (include == NULL) {
LOG_AND_NOTIFY_ERRNO(
- "%s:%d: [default]: %s: failed to open",
+ "%s:%d: [default]: include: %s: failed to open",
path, lineno, include_path);
free(_include_path);
return false;