1
0
mirror of https://github.com/systemd/systemd synced 2024-07-01 07:34:28 +00:00

string-util: introduce string_is_safe_ascii helper

This commit is contained in:
Mike Yuan 2024-05-09 22:01:07 +08:00
parent 4d06bf5922
commit e2b812c804
No known key found for this signature in database
GPG Key ID: 417471C0A40F58B3
2 changed files with 5 additions and 1 deletions

View 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) {

View 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);