Skip to content

Commit

Permalink
Improve relative path check for msi
Browse files Browse the repository at this point in the history
For posix-ish systems, we previously checked that a path was relative
by simpy checking if it included a '/' character. This meant that you
could not, for example, do
```
$ cat foo.substitutions
file rel/to/bar.template {
}

$ msi -I /some/path foo.substitutions
```
where our template file is located at `/some/path/rel/to/bar.template`.

Note that relateive paths work differently on Windows, so we carve out
an exception there.
  • Loading branch information
simon-ess committed Nov 6, 2024
1 parent 1f8851a commit 4822638
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions modules/database/src/ioc/dbtemplate/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ SRC_DIRS += $(IOCDIR)/dbtemplate
PROD_HOST += msi

msi_SRCS = msi.cpp
msi_LIBS_WIN32 = Shlwapi
DOCS += msi.md

INC += dbLoadTemplate.h
Expand Down
14 changes: 13 additions & 1 deletion modules/database/src/ioc/dbtemplate/msi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
#include <osiFileName.h>
#include <osiUnistd.h>

#ifdef _WIN32
#include <shlwapi.h>
#endif

#define MAX_BUFFER_SIZE 4096
#define MAX_DEPS 1024

Expand Down Expand Up @@ -493,6 +497,14 @@ static void inputErrPrint(const inputData *const pinputData)
EXIT;
}

static int isPathRelative(const char * const path) {
#ifdef _WIN32
return path && PathIsRelativeA(path);
#else
return path && path[0] != '/';
#endif
}

static void inputOpenFile(inputData *pinputData, const char * const filename)
{
std::list<std::string>& pathList = pinputData->pathList;
Expand All @@ -505,7 +517,7 @@ static void inputOpenFile(inputData *pinputData, const char * const filename)
STEP("Using stdin");
fp = stdin;
}
else if (pathList.empty() || strchr(filename, '/')){
else if (pathList.empty() || !isPathRelative(filename)){
STEPS("Opening ", filename);
fp = fopen(filename, "r");
}
Expand Down

0 comments on commit 4822638

Please sign in to comment.