mirror of
https://github.com/systemd/systemd-stable.git
synced 2024-12-25 23:21:33 +03:00
hostname: drop invalid chars when reading hostname from disk
This commit is contained in:
parent
3177a7fa12
commit
a06b0b562b
@ -44,6 +44,22 @@
|
||||
#define FILENAME "/etc/conf.d/hostname"
|
||||
#endif
|
||||
|
||||
static char* strip_bad_chars(char *s) {
|
||||
char *p, *d;
|
||||
|
||||
for (p = s, d = s; *p; p++)
|
||||
if ((*p >= 'a' && *p <= 'z') ||
|
||||
(*p >= 'A' && *p <= 'Z') ||
|
||||
(*p >= '0' && *p <= '9') ||
|
||||
*p == '-' ||
|
||||
*p == '_')
|
||||
*(d++) = *p;
|
||||
|
||||
*d = 0;
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
static int read_hostname(char **hn) {
|
||||
|
||||
#if defined(TARGET_FEDORA) || defined(TARGET_ARCH) || defined(TARGET_GENTOO)
|
||||
@ -77,8 +93,11 @@ static int read_hostname(char **hn) {
|
||||
goto finish;
|
||||
}
|
||||
|
||||
if (!(k = delete_chars(k, "\"\'"))) {
|
||||
r = -ENOMEM;
|
||||
strip_bad_chars(k);
|
||||
|
||||
if (k[0] == 0) {
|
||||
free(k);
|
||||
r = -ENOENT;
|
||||
goto finish;
|
||||
}
|
||||
|
||||
@ -107,6 +126,13 @@ finish:
|
||||
if (!k)
|
||||
return -ENOMEM;
|
||||
|
||||
strip_bad_chars(k);
|
||||
|
||||
if (k[0] == 0) {
|
||||
free(k);
|
||||
return -NOENT;
|
||||
}
|
||||
|
||||
*hn = k;
|
||||
|
||||
#else
|
||||
|
Loading…
Reference in New Issue
Block a user