From f09e36acfe2db50e0452ba1e19b13f4395a8d704 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Tue, 23 Apr 2019 22:41:31 +0200 Subject: make: do not follow symlinks when resolving blogcfile path --- src/blogc-make/utils.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'src/blogc-make/utils.c') diff --git a/src/blogc-make/utils.c b/src/blogc-make/utils.c index 0c984f6..91b7b53 100644 --- a/src/blogc-make/utils.c +++ b/src/blogc-make/utils.c @@ -6,10 +6,18 @@ * See the file LICENSE. */ +#include +#include #include #include +#include +#include "../common/error.h" #include "../common/utils.h" +#ifndef PATH_MAX +#define PATH_MAX 4096 +#endif + char* bm_generate_filename(const char *dir, const char *prefix, const char *fname, @@ -59,3 +67,30 @@ bm_generate_filename(const char *dir, const char *prefix, const char *fname, return bc_string_free(rv, false); } + + +char* +bm_abspath(const char *path, bc_error_t **err) +{ + if (err == NULL || *err != NULL) + return NULL; + + if (path[0] == '/') { + return bc_strdup(path); + } + + char cwd[PATH_MAX]; + if (NULL == getcwd(cwd, sizeof(cwd))) { + *err = bc_error_new_printf(BLOGC_MAKE_ERROR_UTILS, + "Failed to detect absolute path (%s): %s", path, strerror(errno)); + return NULL; + } + + if (cwd[0] != '/') { + *err = bc_error_new_printf(BLOGC_MAKE_ERROR_UTILS, + "Failed to get current working directory: %s", cwd); + return NULL; + } + + return bc_strdup_printf("%s/%s", cwd, path); +} -- cgit v1.2.3-18-g5258