]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
util: move filename_is_valid() and path_is_safe() to path-util.[ch]
authorLennart Poettering <lennart@poettering.net>
Mon, 26 Oct 2015 17:59:36 +0000 (18:59 +0100)
committerLennart Poettering <lennart@poettering.net>
Tue, 27 Oct 2015 12:25:55 +0000 (13:25 +0100)
13 files changed:
src/basic/locale-util.c
src/basic/lockfile-util.c
src/basic/path-util.c
src/basic/path-util.h
src/basic/util.c
src/basic/util.h
src/hostname/hostnamed.c
src/import/pull-common.c
src/libsystemd/sd-login/sd-login.c
src/locale/localed.c
src/shared/dropin.c
src/shared/import-util.c
src/test/test-util.c

index 44e16286646178aebf92217fa4e1266efda2cc10..ccbc1479316e833372baf9a3f60f5c1d6f831ca6 100644 (file)
@@ -23,6 +23,7 @@
 
 #include "fd-util.h"
 #include "locale-util.h"
+#include "path-util.h"
 #include "set.h"
 #include "string-util.h"
 #include "strv.h"
index e573dcb56f416ad9f4ee349cfdc4e5ec7ba298b0..6eee3009d8784dd5716a4e7890050781eb8ed102 100644 (file)
@@ -30,6 +30,7 @@
 #include "fd-util.h"
 #include "fileio.h"
 #include "lockfile-util.h"
+#include "path-util.h"
 #include "util.h"
 
 int make_lock_file(const char *p, int operation, LockFile *ret) {
index b1cab7356c2c0284640657ec04f3e0f2170b9636..d581f85707dde2639d1a69b941306484f3683064 100644 (file)
@@ -723,3 +723,46 @@ char* dirname_malloc(const char *path) {
 
         return dir2;
 }
+
+bool filename_is_valid(const char *p) {
+        const char *e;
+
+        if (isempty(p))
+                return false;
+
+        if (streq(p, "."))
+                return false;
+
+        if (streq(p, ".."))
+                return false;
+
+        e = strchrnul(p, '/');
+        if (*e != 0)
+                return false;
+
+        if (e - p > FILENAME_MAX)
+                return false;
+
+        return true;
+}
+
+bool path_is_safe(const char *p) {
+
+        if (isempty(p))
+                return false;
+
+        if (streq(p, "..") || startswith(p, "../") || endswith(p, "/..") || strstr(p, "/../"))
+                return false;
+
+        if (strlen(p)+1 > PATH_MAX)
+                return false;
+
+        /* The following two checks are not really dangerous, but hey, they still are confusing */
+        if (streq(p, ".") || startswith(p, "./") || endswith(p, "/.") || strstr(p, "/./"))
+                return false;
+
+        if (strstr(p, "//"))
+                return false;
+
+        return true;
+}
index 1ff47ab19304c18cd2be93c2830d4d55e09ed8bb..b2acca05fef291e062f3506488e3b7f6d41c62af 100644 (file)
@@ -102,3 +102,6 @@ char *prefix_root(const char *root, const char *path);
 int parse_path_argument_and_warn(const char *path, bool suppress_root, char **arg);
 
 char* dirname_malloc(const char *path);
+
+bool filename_is_valid(const char *p) _pure_;
+bool path_is_safe(const char *p) _pure_;
index 06fe307ba02b533349a3b40d2d729eb070c60397..576c6238d6321720f93bfd59c291d98fa3d4825e 100644 (file)
@@ -1439,26 +1439,6 @@ bool in_initrd(void) {
         return saved;
 }
 
-bool filename_is_valid(const char *p) {
-
-        if (isempty(p))
-                return false;
-
-        if (strchr(p, '/'))
-                return false;
-
-        if (streq(p, "."))
-                return false;
-
-        if (streq(p, ".."))
-                return false;
-
-        if (strlen(p) > FILENAME_MAX)
-                return false;
-
-        return true;
-}
-
 bool string_is_safe(const char *p) {
         const char *t;
 
@@ -1476,27 +1456,6 @@ bool string_is_safe(const char *p) {
         return true;
 }
 
-bool path_is_safe(const char *p) {
-
-        if (isempty(p))
-                return false;
-
-        if (streq(p, "..") || startswith(p, "../") || endswith(p, "/..") || strstr(p, "/../"))
-                return false;
-
-        if (strlen(p)+1 > PATH_MAX)
-                return false;
-
-        /* The following two checks are not really dangerous, but hey, they still are confusing */
-        if (streq(p, ".") || startswith(p, "./") || endswith(p, "/.") || strstr(p, "/./"))
-                return false;
-
-        if (strstr(p, "//"))
-                return false;
-
-        return true;
-}
-
 /* hey glibc, APIs with callbacks without a user pointer are so useless */
 void *xbsearch_r(const void *key, const void *base, size_t nmemb, size_t size,
                  int (*compar) (const void *, const void *, void *), void *arg) {
index 9388ba7d749c91d56059409f2bedc0aceb2b2814..f96b493d9d00211ae1d86bdbeb75e710c3e85c50 100644 (file)
@@ -303,8 +303,6 @@ _alloc_(2, 3) static inline void *memdup_multiply(const void *p, size_t a, size_
         return memdup(p, a * b);
 }
 
-bool filename_is_valid(const char *p) _pure_;
-bool path_is_safe(const char *p) _pure_;
 bool string_is_safe(const char *p) _pure_;
 
 /**
index 8bff7d4b39f797317ed06f71fb77837321845a63..a42124288da4c1e037153e0e2ff9a8899d3c7113 100644 (file)
@@ -31,6 +31,7 @@
 #include "fileio-label.h"
 #include "hostname-util.h"
 #include "parse-util.h"
+#include "path-util.h"
 #include "selinux-util.h"
 #include "strv.h"
 #include "util.h"
index f465154b1d400f1d6c39d99011cfefd4a285f81c..0e918d6416273ea225b80190b0829c6c326270db 100644 (file)
@@ -27,6 +27,7 @@
 #include "escape.h"
 #include "fd-util.h"
 #include "io-util.h"
+#include "path-util.h"
 #include "process-util.h"
 #include "pull-common.h"
 #include "pull-job.h"
index 05cba9651a5a027bf29341cce07e9bcb0efacf68..879838601c2716f3ba04995d16abd14cfd1470e2 100644 (file)
@@ -37,6 +37,7 @@
 #include "login-util.h"
 #include "macro.h"
 #include "parse-util.h"
+#include "path-util.h"
 #include "socket-util.h"
 #include "string-util.h"
 #include "strv.h"
index 73e25f06428ecef0c95046b7ea653b300b8295dd..343399a62d31f695955e0e1d4c48bf958cf9b8d3 100644 (file)
 
 #include "sd-bus.h"
 
-#include "util.h"
-#include "mkdir.h"
-#include "strv.h"
-#include "def.h"
-#include "env-util.h"
-#include "fileio.h"
-#include "fileio-label.h"
-#include "bus-util.h"
 #include "bus-error.h"
 #include "bus-message.h"
+#include "bus-util.h"
+#include "def.h"
+#include "env-util.h"
 #include "event-util.h"
+#include "fd-util.h"
+#include "fileio-label.h"
+#include "fileio.h"
 #include "locale-util.h"
+#include "mkdir.h"
+#include "path-util.h"
 #include "selinux-util.h"
-#include "fd-util.h"
+#include "strv.h"
+#include "util.h"
 
 enum {
         /* We don't list LC_ALL here on purpose. People should be
index 1836e91acdae70ed526bc8eed5e794d20090c64b..25400277ff98580dcd268861b84c5fc1a9ed973b 100644 (file)
@@ -25,6 +25,7 @@
 #include "fd-util.h"
 #include "fileio-label.h"
 #include "mkdir.h"
+#include "path-util.h"
 #include "string-util.h"
 #include "strv.h"
 #include "util.h"
index c4c66c847d503ac0de4fbd253d1636e53edd75d2..b50e86b944ba4f497bd61a44af171944c7084e86 100644 (file)
 ***/
 
 #include "btrfs-util.h"
+#include "import-util.h"
+#include "path-util.h"
 #include "string-util.h"
 #include "util.h"
-#include "import-util.h"
 
 int import_url_last_component(const char *url, char **ret) {
         const char *e, *p;
index 8e5860f0e44db647fbe772093204b76310dff1b0..109791163f7f95956247b92434e6a7db2d0acc85 100644 (file)
@@ -50,6 +50,7 @@
 #include "user-util.h"
 #include "util.h"
 #include "virt.h"
+#include "path-util.h"
 
 static void test_streq_ptr(void) {
         assert_se(streq_ptr(NULL, NULL));