mirror of
https://github.com/systemd/systemd
synced 2024-10-01 13:55:20 +00:00
string-util: introduce string_is_safe_ascii helper
This commit is contained in:
parent
4d06bf5922
commit
e2b812c804
|
@ -8,6 +8,7 @@
|
||||||
#include "alloc-util.h"
|
#include "alloc-util.h"
|
||||||
#include "macro.h"
|
#include "macro.h"
|
||||||
#include "string-util-fundamental.h"
|
#include "string-util-fundamental.h"
|
||||||
|
#include "utf8.h"
|
||||||
|
|
||||||
/* What is interpreted as whitespace? */
|
/* What is interpreted as whitespace? */
|
||||||
#define WHITESPACE " \t\n\r"
|
#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_;
|
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;
|
DISABLE_WARNING_STRINGOP_TRUNCATION;
|
||||||
static inline void strncpy_exact(char *buf, const char *src, size_t buf_len) {
|
static inline void strncpy_exact(char *buf, const char *src, size_t buf_len) {
|
||||||
|
|
|
@ -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) {
|
int sd_dhcp_server_set_boot_filename(sd_dhcp_server *server, const char *filename) {
|
||||||
assert_return(server, -EINVAL);
|
assert_return(server, -EINVAL);
|
||||||
|
|
||||||
if (filename && (!string_is_safe(filename) || !ascii_is_valid(filename)))
|
if (filename && !string_is_safe_ascii(filename))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
return free_and_strdup(&server->boot_filename, filename);
|
return free_and_strdup(&server->boot_filename, filename);
|
||||||
|
|
Loading…
Reference in a new issue