aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2024-02-14 09:21:30 +0100
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2024-02-14 09:21:30 +0100
commit358073d713deb16460ae633d5a48a8e48180369f (patch)
tree9b5c5e3fe81fccc387b8b3ab5d5d6a44162a40c7
parent5f5097653c93af8cd417f8753738f86a655d34a1 (diff)
Fix win32 filename sanitation for cases were we have clashes
We fix filenames containing components like COM1 or PRN by appending an underscore ('_'). A squashfs archive may contain files that already have such a modifed name (e.g. COM1_) which would now potentially clash. This is fixed by matching any number of trailing '_' characters for the bad name and adding another one. So all existing names that start with an illegal prefix and have any number of underscores, will always have an additional one appended. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
-rw-r--r--lib/util/fix_win32_filename.c10
-rw-r--r--tests/libutil/fix_win32_filename.c4
2 files changed, 13 insertions, 1 deletions
diff --git a/lib/util/fix_win32_filename.c b/lib/util/fix_win32_filename.c
index 948de66..d368eb0 100644
--- a/lib/util/fix_win32_filename.c
+++ b/lib/util/fix_win32_filename.c
@@ -66,7 +66,15 @@ static const char *bad_names[] = {
static buffer_t *handle_component(buffer_t *buf, const char *comp, size_t len)
{
for (size_t i = 0; i < sizeof(bad_names) / sizeof(bad_names[0]); ++i) {
- if (!strncasecmp(comp, bad_names[i], len)) {
+ size_t badlen = strlen(bad_names[i]);
+
+ if (badlen > len || strncasecmp(comp, bad_names[i], badlen))
+ continue;
+
+ while (badlen < len && comp[badlen] == '_')
+ ++badlen;
+
+ if (badlen == len) {
buf = buffer_append(buf, comp, len);
if (buf != NULL)
buf = buffer_append(buf, "_", 1);
diff --git a/tests/libutil/fix_win32_filename.c b/tests/libutil/fix_win32_filename.c
index a4f71e8..e8932d6 100644
--- a/tests/libutil/fix_win32_filename.c
+++ b/tests/libutil/fix_win32_filename.c
@@ -22,6 +22,10 @@ static const struct {
{ "foo/bar/test.LPT1/bla", "foo/bar/test.LPT1_/bla" },
{ "C:\\/foo/COM1.bla/bar",
"C\xEF\x80\xBA\xEF\x81\x9c/foo/COM1_.bla/bar" },
+ { "com1", "com1_" },
+ { "COM1_", "COM1__" },
+ { "COM1__", "COM1___" },
+ { "COM1___", "COM1____" },
};
int main(int argc, char **argv)