1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2024-12-24 21:34:08 +03:00

util: don't consider tabs special in string_has_cc() anymore

Instead, take a list of exceptions to our usual CC check
This commit is contained in:
Lennart Poettering 2014-07-07 12:04:55 +02:00
parent 7568345034
commit 6294aa76d8
5 changed files with 18 additions and 15 deletions

View File

@ -550,8 +550,7 @@ static int set_machine_info(Context *c, sd_bus *bus, sd_bus_message *m, int prop
if (prop == PROP_ICON_NAME && !filename_is_safe(name))
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid icon name '%s'", name);
if (prop == PROP_PRETTY_HOSTNAME &&
(string_has_cc(name) || chars_intersect(name, "\t")))
if (prop == PROP_PRETTY_HOSTNAME && string_has_cc(name, NULL))
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid pretty host name '%s'", name);
if (prop == PROP_CHASSIS && !valid_chassis(name))
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid chassis '%s'", name);

View File

@ -78,7 +78,9 @@ bool env_value_is_valid(const char *e) {
if (!utf8_is_valid(e))
return false;
if (string_has_cc(e))
/* bash allows tabs in environment variables, and so should
* we */
if (string_has_cc(e, "\t"))
return false;
/* POSIX says the overall size of the environment block cannot

View File

@ -738,7 +738,7 @@ static void write_env_var(FILE *f, const char *v) {
p++;
fwrite(v, 1, p-v, f);
if (string_has_cc(p) || chars_intersect(p, WHITESPACE "\'\"\\`$")) {
if (string_has_cc(p, NULL) || chars_intersect(p, WHITESPACE "\'\"\\`$")) {
fputc('\"', f);
for (; *p; p++) {

View File

@ -5350,16 +5350,14 @@ bool filename_is_safe(const char *p) {
bool string_is_safe(const char *p) {
const char *t;
assert(p);
if (!p)
return false;
for (t = p; *t; t++) {
if (*t > 0 && *t < ' ')
return false;
if (*t == 127)
return false;
if (strchr("\\\"\'", *t))
if (strchr("\\\"\'\0x7f", *t))
return false;
}
@ -5367,16 +5365,19 @@ bool string_is_safe(const char *p) {
}
/**
* Check if a string contains control characters.
* Spaces and tabs are not considered control characters.
* Check if a string contains control characters. If 'ok' is non-NULL
* it may be a string containing additional CCs to be considered OK.
*/
bool string_has_cc(const char *p) {
bool string_has_cc(const char *p, const char *ok) {
const char *t;
assert(p);
for (t = p; *t; t++) {
if (*t > 0 && *t < ' ' && *t != '\t')
if (ok && strchr(ok, *t))
return false;
if (*t > 0 && *t < ' ')
return true;
if (*t == 127)

View File

@ -382,7 +382,8 @@ bool fstype_is_network(const char *fstype);
int chvt(int vt);
int read_one_char(FILE *f, char *ret, usec_t timeout, bool *need_nl);
int ask(char *ret, const char *replies, const char *text, ...) _printf_(3, 4);
int ask_char(char *ret, const char *replies, const char *text, ...) _printf_(3, 4);
int ask_string(char **ret, const char *text, ...) _printf_(2, 3);
int reset_terminal_fd(int fd, bool switch_to_text);
int reset_terminal(const char *name);
@ -692,7 +693,7 @@ _alloc_(2, 3) static inline void *memdup_multiply(const void *p, size_t a, size_
bool filename_is_safe(const char *p) _pure_;
bool path_is_safe(const char *p) _pure_;
bool string_is_safe(const char *p) _pure_;
bool string_has_cc(const char *p) _pure_;
bool string_has_cc(const char *p, const char *ok) _pure_;
/**
* Check if a string contains any glob patterns.