chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
3177a7f
)
hostname: drop invalid chars when reading hostname from disk
author
Lennart Poettering
<lennart@poettering.net>
Sun, 9 May 2010 17:12:06 +0000
(19:12 +0200)
committer
Lennart Poettering
<lennart@poettering.net>
Sun, 9 May 2010 17:12:39 +0000
(19:12 +0200)
hostname-setup.c
patch
|
blob
|
history
diff --git
a/hostname-setup.c
b/hostname-setup.c
index b8551d9802feb48715d8ebffdfa47c2d0c9b8777..9f614746250f91be141c3ceeb84ea271a45bcc9c 100644
(file)
--- a/
hostname-setup.c
+++ b/
hostname-setup.c
@@
-44,6
+44,22
@@
#define FILENAME "/etc/conf.d/hostname"
#endif
#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)
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;
}
goto finish;
}
- if (!(k = delete_chars(k, "\"\'"))) {
- r = -ENOMEM;
+ strip_bad_chars(k);
+
+ if (k[0] == 0) {
+ free(k);
+ r = -ENOENT;
goto finish;
}
goto finish;
}
@@
-107,6
+126,13
@@
finish:
if (!k)
return -ENOMEM;
if (!k)
return -ENOMEM;
+ strip_bad_chars(k);
+
+ if (k[0] == 0) {
+ free(k);
+ return -NOENT;
+ }
+
*hn = k;
#else
*hn = k;
#else