]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
string-util: introduce string_is_safe_ascii helper 33364/head
authorMike Yuan <me@yhndnzj.com>
Thu, 9 May 2024 14:01:07 +0000 (22:01 +0800)
committerMike Yuan <me@yhndnzj.com>
Sun, 16 Jun 2024 17:07:35 +0000 (19:07 +0200)
src/basic/string-util.h
src/libsystemd-network/sd-dhcp-server.c

index a032ee8d6a7ae4da8b3e93a901d074d512ee617c..b5da8bea0593b642d2051c234e9e9320f21d07a5 100644 (file)
@@ -8,6 +8,7 @@
 #include "alloc-util.h"
 #include "macro.h"
 #include "string-util-fundamental.h"
+#include "utf8.h"
 
 /* What is interpreted as whitespace? */
 #define WHITESPACE          " \t\n\r"
@@ -234,6 +235,9 @@ static inline int strdup_to(char **ret, const char *src) {
 }
 
 bool string_is_safe(const char *p) _pure_;
+static inline bool string_is_safe_ascii(const char *p) {
+        return ascii_is_valid(p) && string_is_safe(p);
+}
 
 DISABLE_WARNING_STRINGOP_TRUNCATION;
 static inline void strncpy_exact(char *buf, const char *src, size_t buf_len) {
index 4967f066dce5f8901df7e324c20cc414cb202fdf..25b4cafaa59cf40f448ec5d7d9202a15e4c22ba6 100644 (file)
@@ -271,7 +271,7 @@ int sd_dhcp_server_set_boot_server_name(sd_dhcp_server *server, const char *name
 int sd_dhcp_server_set_boot_filename(sd_dhcp_server *server, const char *filename) {
         assert_return(server, -EINVAL);
 
-        if (filename && (!string_is_safe(filename) || !ascii_is_valid(filename)))
+        if (filename && !string_is_safe_ascii(filename))
                 return -EINVAL;
 
         return free_and_strdup(&server->boot_filename, filename);