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:
ed85d9a
)
util: make sure result of hostname_cleanup() passes hostname_is_valid()
author
Lennart Poettering
<lennart@poettering.net>
Tue, 16 Apr 2013 01:57:50 +0000
(
03:57
+0200)
committer
Lennart Poettering
<lennart@poettering.net>
Tue, 16 Apr 2013 02:41:21 +0000
(
04:41
+0200)
src/shared/util.c
patch
|
blob
|
history
diff --git
a/src/shared/util.c
b/src/shared/util.c
index 5d6995d23f878eb8d081d1318e2c0bbed5f8d982..4eb64934ee4cf1437956f3629e3c6271e2b98077 100644
(file)
--- a/
src/shared/util.c
+++ b/
src/shared/util.c
@@
-3837,19
+3837,24
@@
bool hostname_is_valid(const char *s) {
char* hostname_cleanup(char *s) {
char *p, *d;
char* hostname_cleanup(char *s) {
char *p, *d;
+ bool dot;
+
+ for (p = s, d = s, dot = true; *p; p++) {
+ if (*p == '.') {
+ if (dot || p[1] == 0)
+ continue;
- for (p = s, d = s; *p; p++)
- if ((*p >= 'a' && *p <= 'z') ||
- (*p >= 'A' && *p <= 'Z') ||
- (*p >= '0' && *p <= '9') ||
- *p == '-' ||
- *p == '_' ||
- *p == '.')
+ dot = true;
+ } else
+ dot = false;
+
+ if (hostname_valid_char(*p))
*(d++) = *p;
*(d++) = *p;
+ }
*d = 0;
*d = 0;
-
strshorten(s, HOST_NAME_MAX);
strshorten(s, HOST_NAME_MAX);
+
return s;
}
return s;
}