aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2018-09-26 19:52:05 -0700
committerH. Peter Anvin <hpa@zytor.com>2018-09-26 19:52:05 -0700
commit1382f299e8886594ca6946d463462eb95cfb0305 (patch)
tree88f8dad16099c9c10fdab70090254e5c13ec91a5
parent2f8817bad26ea903a02c7bd014af819af4ed2602 (diff)
downloadabc80sim-1382f299e8886594ca6946d463462eb95cfb0305.tar.gz
abc80sim-1382f299e8886594ca6946d463462eb95cfb0305.tar.xz
abc80sim-1382f299e8886594ca6946d463462eb95cfb0305.zip
hostfile: don't add the directory to an absolute filename
-rw-r--r--hostfile.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/hostfile.c b/hostfile.c
index 267addd..29574f1 100644
--- a/hostfile.c
+++ b/hostfile.c
@@ -86,6 +86,19 @@ static inline bool is_path_separator(char c)
}
}
+static inline bool filename_is_absolute(const char *name)
+{
+ if (*name == '/')
+ return true;
+
+#ifdef __WIN32__
+ if (*name == '\\' || strchr(name, ':'))
+ return true;
+#endif
+
+ return false;
+}
+
int stat_file(const char *dir, const char *filename, struct stat *st)
{
size_t dl;
@@ -148,7 +161,7 @@ struct host_file *open_host_file(enum host_file_mode mode, const char *dir,
hf->nuke = !!(openflags & O_EXCL);
p = hf->filename;
- if (dl > 0) {
+ if (dl > 0 && !filename_is_absolute(filename)) {
p = mempcpy(p, dir, dl);
if (!is_path_separator(p[-1]))
*p++ = '/';