From 91737269d67a0403727faaa70521ff904dba695b Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Mon, 17 Dec 2018 21:55:46 +0100 Subject: git-receiver: make: runserver: improved realpath(3) usage --- src/blogc-make/ctx.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'src/blogc-make') diff --git a/src/blogc-make/ctx.c b/src/blogc-make/ctx.c index eb0fa22..fd71137 100644 --- a/src/blogc-make/ctx.c +++ b/src/blogc-make/ctx.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -170,8 +171,16 @@ bm_ctx_new(bm_ctx_t *base, const char *settings_file, const char *argv0, if (settings_file == NULL || err == NULL || *err != NULL) return NULL; + char real_filename[PATH_MAX]; + if (NULL == realpath(settings_file, real_filename)) { + *err = bc_error_new_printf(BLOGC_MAKE_ERROR_SETTINGS, + "Failed to resolve settings file (%s): %s", settings_file, + strerror(errno)); + return NULL; + } + size_t content_len; - char *content = bc_file_get_contents(settings_file, true, &content_len, + char *content = bc_file_get_contents(real_filename, true, &content_len, err); if (*err != NULL) return NULL; @@ -217,10 +226,8 @@ bm_ctx_new(bm_ctx_t *base, const char *settings_file, const char *argv0, } rv->settings = settings; - char *real_filename = realpath(settings_file, NULL); rv->settings_fctx = bm_filectx_new(rv, real_filename, NULL, NULL); - rv->root_dir = realpath(dirname(real_filename), NULL); - free(real_filename); + rv->root_dir = bc_strdup(dirname(real_filename)); const char *output_dir = getenv("OUTPUT_DIR"); rv->short_output_dir = bc_strdup(output_dir != NULL ? output_dir : "_build"); -- cgit v1.2.3-18-g5258