|
|
4b6aa8 |
From 54ecf8d017580b495d6501e53ca54e453a73a364 Mon Sep 17 00:00:00 2001
|
|
|
4b6aa8 |
From: Jakub Filak <jfilak@redhat.com>
|
|
|
4b6aa8 |
Date: Thu, 23 Apr 2015 13:21:41 +0200
|
|
|
4b6aa8 |
Subject: [LIBREPORT PATCH] lib: add a function checking file names
|
|
|
4b6aa8 |
|
|
|
4b6aa8 |
Move the code from ABRT and extend it a bit:
|
|
|
4b6aa8 |
* allow only 64 characters
|
|
|
4b6aa8 |
* allow '.' in names (vmcore_dmesg.txt)
|
|
|
4b6aa8 |
* forbid '/'
|
|
|
4b6aa8 |
* forbid "."
|
|
|
4b6aa8 |
* forbid ".."
|
|
|
4b6aa8 |
|
|
|
4b6aa8 |
Related: #1214451
|
|
|
4b6aa8 |
|
|
|
4b6aa8 |
Signed-off-by: Jakub Filak <jfilak@redhat.com>
|
|
|
4b6aa8 |
---
|
|
|
4b6aa8 |
src/include/internal_libreport.h | 6 +++++
|
|
|
4b6aa8 |
src/lib/concat_path_file.c | 25 ++++++++++++++++++++
|
|
|
4b6aa8 |
tests/Makefile.am | 3 ++-
|
|
|
4b6aa8 |
tests/dump_dir.at | 49 ++++++++++++++++++++++++++++++++++++++++
|
|
|
4b6aa8 |
tests/testsuite.at | 1 +
|
|
|
4b6aa8 |
5 files changed, 83 insertions(+), 1 deletion(-)
|
|
|
4b6aa8 |
create mode 100644 tests/dump_dir.at
|
|
|
4b6aa8 |
|
|
|
4b6aa8 |
diff --git a/src/include/internal_libreport.h b/src/include/internal_libreport.h
|
|
|
4b6aa8 |
index 4c5c72a..8d84fd4 100644
|
|
|
4b6aa8 |
--- a/src/include/internal_libreport.h
|
|
|
4b6aa8 |
+++ b/src/include/internal_libreport.h
|
|
|
4b6aa8 |
@@ -132,6 +132,12 @@ char *concat_path_file(const char *path, const char *filename);
|
|
|
4b6aa8 |
#define concat_path_basename libreport_concat_path_basename
|
|
|
4b6aa8 |
char *concat_path_basename(const char *path, const char *filename);
|
|
|
4b6aa8 |
|
|
|
4b6aa8 |
+/* Allows all printable characters except '/',
|
|
|
4b6aa8 |
+ * the string must not exceed 64 characters of length
|
|
|
4b6aa8 |
+ * and must not equal neither "." nor ".." (these strings may appear in the string) */
|
|
|
4b6aa8 |
+#define str_is_correct_filename libreport_str_is_correct_filename
|
|
|
4b6aa8 |
+bool str_is_correct_filename(const char *str);
|
|
|
4b6aa8 |
+
|
|
|
4b6aa8 |
/* A-la fgets, but malloced and of unlimited size */
|
|
|
4b6aa8 |
#define xmalloc_fgets libreport_xmalloc_fgets
|
|
|
4b6aa8 |
char *xmalloc_fgets(FILE *file);
|
|
|
4b6aa8 |
diff --git a/src/lib/concat_path_file.c b/src/lib/concat_path_file.c
|
|
|
4b6aa8 |
index 39ae07a..24e4cbd 100644
|
|
|
4b6aa8 |
--- a/src/lib/concat_path_file.c
|
|
|
4b6aa8 |
+++ b/src/lib/concat_path_file.c
|
|
|
4b6aa8 |
@@ -57,3 +57,28 @@ char *concat_path_basename(const char *path, const char *filename)
|
|
|
4b6aa8 |
free(abspath);
|
|
|
4b6aa8 |
return name;
|
|
|
4b6aa8 |
}
|
|
|
4b6aa8 |
+
|
|
|
4b6aa8 |
+bool str_is_correct_filename(const char *str)
|
|
|
4b6aa8 |
+{
|
|
|
4b6aa8 |
+#define NOT_PRINTABLE(c) (c < ' ' || c == 0x7f)
|
|
|
4b6aa8 |
+
|
|
|
4b6aa8 |
+ if (NOT_PRINTABLE(*str) || *str == '/' || *str == '\0')
|
|
|
4b6aa8 |
+ return false;
|
|
|
4b6aa8 |
+ ++str;
|
|
|
4b6aa8 |
+
|
|
|
4b6aa8 |
+ if (NOT_PRINTABLE(*str) || *str =='/' || (*str == '\0' && *(str-1) == '.'))
|
|
|
4b6aa8 |
+ return false;
|
|
|
4b6aa8 |
+ ++str;
|
|
|
4b6aa8 |
+
|
|
|
4b6aa8 |
+ if (NOT_PRINTABLE(*str) || *str =='/' || (*str == '\0' && *(str-1) == '.' && *(str-2) == '.'))
|
|
|
4b6aa8 |
+ return false;
|
|
|
4b6aa8 |
+ ++str;
|
|
|
4b6aa8 |
+
|
|
|
4b6aa8 |
+ for (unsigned i = 0; *str != '\0' && i < 61; ++str, ++i)
|
|
|
4b6aa8 |
+ if (NOT_PRINTABLE(*str) || *str == '/')
|
|
|
4b6aa8 |
+ return false;
|
|
|
4b6aa8 |
+
|
|
|
4b6aa8 |
+ return *str == '\0';
|
|
|
4b6aa8 |
+
|
|
|
4b6aa8 |
+#undef NOT_PRINTABLE
|
|
|
4b6aa8 |
+}
|
|
|
4b6aa8 |
diff --git a/tests/Makefile.am b/tests/Makefile.am
|
|
|
4b6aa8 |
index a680f05..eaf1ac2 100644
|
|
|
4b6aa8 |
--- a/tests/Makefile.am
|
|
|
4b6aa8 |
+++ b/tests/Makefile.am
|
|
|
4b6aa8 |
@@ -42,7 +42,8 @@ TESTSUITE_AT = \
|
|
|
4b6aa8 |
report_python.at \
|
|
|
4b6aa8 |
xfuncs.at \
|
|
|
4b6aa8 |
string_list.at \
|
|
|
4b6aa8 |
- ureport.at
|
|
|
4b6aa8 |
+ ureport.at \
|
|
|
4b6aa8 |
+ dump_dir.at
|
|
|
4b6aa8 |
|
|
|
4b6aa8 |
EXTRA_DIST += $(TESTSUITE_AT)
|
|
|
4b6aa8 |
TESTSUITE = $(srcdir)/testsuite
|
|
|
4b6aa8 |
diff --git a/tests/dump_dir.at b/tests/dump_dir.at
|
|
|
4b6aa8 |
new file mode 100644
|
|
|
4b6aa8 |
index 0000000..a579243
|
|
|
4b6aa8 |
--- /dev/null
|
|
|
4b6aa8 |
+++ b/tests/dump_dir.at
|
|
|
4b6aa8 |
@@ -0,0 +1,49 @@
|
|
|
4b6aa8 |
+# -*- Autotest -*-
|
|
|
4b6aa8 |
+
|
|
|
4b6aa8 |
+AT_BANNER([dump directories])
|
|
|
4b6aa8 |
+
|
|
|
4b6aa8 |
+## ----------------------- ##
|
|
|
4b6aa8 |
+## str_is_correct_filename ##
|
|
|
4b6aa8 |
+## ----------------------- ##
|
|
|
4b6aa8 |
+
|
|
|
4b6aa8 |
+AT_TESTFUN([str_is_correct_filename],
|
|
|
4b6aa8 |
+[[
|
|
|
4b6aa8 |
+#include "internal_libreport.h"
|
|
|
4b6aa8 |
+#include <assert.h>
|
|
|
4b6aa8 |
+#
|
|
|
4b6aa8 |
+int main(void)
|
|
|
4b6aa8 |
+{
|
|
|
4b6aa8 |
+ g_verbose = 3;
|
|
|
4b6aa8 |
+
|
|
|
4b6aa8 |
+ assert(str_is_correct_filename("") == false);
|
|
|
4b6aa8 |
+ assert(str_is_correct_filename("/") == false);
|
|
|
4b6aa8 |
+ assert(str_is_correct_filename("//") == false);
|
|
|
4b6aa8 |
+ assert(str_is_correct_filename(".") == false);
|
|
|
4b6aa8 |
+ assert(str_is_correct_filename(".") == false);
|
|
|
4b6aa8 |
+ assert(str_is_correct_filename("..") == false);
|
|
|
4b6aa8 |
+ assert(str_is_correct_filename("..") == false);
|
|
|
4b6aa8 |
+ assert(str_is_correct_filename("/.") == false);
|
|
|
4b6aa8 |
+ assert(str_is_correct_filename("//.") == false);
|
|
|
4b6aa8 |
+ assert(str_is_correct_filename("./") == false);
|
|
|
4b6aa8 |
+ assert(str_is_correct_filename(".//") == false);
|
|
|
4b6aa8 |
+ assert(str_is_correct_filename("/./") == false);
|
|
|
4b6aa8 |
+ assert(str_is_correct_filename("/..") == false);
|
|
|
4b6aa8 |
+ assert(str_is_correct_filename("//..") == false);
|
|
|
4b6aa8 |
+ assert(str_is_correct_filename("../") == false);
|
|
|
4b6aa8 |
+ assert(str_is_correct_filename("..//") == false);
|
|
|
4b6aa8 |
+ assert(str_is_correct_filename("/../") == false);
|
|
|
4b6aa8 |
+ assert(str_is_correct_filename("/.././") == false);
|
|
|
4b6aa8 |
+
|
|
|
4b6aa8 |
+ assert(str_is_correct_filename("looks-good-but-evil/") == false);
|
|
|
4b6aa8 |
+ assert(str_is_correct_filename("looks-good-but-evil/../../") == false);
|
|
|
4b6aa8 |
+
|
|
|
4b6aa8 |
+ assert(str_is_correct_filename(".meta-data") == true);
|
|
|
4b6aa8 |
+ assert(str_is_correct_filename("..meta-meta-data") == true);
|
|
|
4b6aa8 |
+ assert(str_is_correct_filename("meta-..-data") == true);
|
|
|
4b6aa8 |
+
|
|
|
4b6aa8 |
+ assert(str_is_correct_filename("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890+-") == true);
|
|
|
4b6aa8 |
+ assert(str_is_correct_filename("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890+-=") == false);
|
|
|
4b6aa8 |
+
|
|
|
4b6aa8 |
+ return 0;
|
|
|
4b6aa8 |
+}
|
|
|
4b6aa8 |
+]])
|
|
|
4b6aa8 |
diff --git a/tests/testsuite.at b/tests/testsuite.at
|
|
|
4b6aa8 |
index abad32b..41107e7 100644
|
|
|
4b6aa8 |
--- a/tests/testsuite.at
|
|
|
4b6aa8 |
+++ b/tests/testsuite.at
|
|
|
4b6aa8 |
@@ -17,3 +17,4 @@ m4_include([xml_definition.at])
|
|
|
4b6aa8 |
m4_include([report_python.at])
|
|
|
4b6aa8 |
m4_include([string_list.at])
|
|
|
4b6aa8 |
m4_include([ureport.at])
|
|
|
4b6aa8 |
+m4_include([dump_dir.at])
|
|
|
4b6aa8 |
--
|
|
|
4b6aa8 |
1.8.3.1
|
|
|
4b6aa8 |
|