[systemd-commits] 2 commits - src/hostname src/login src/network src/shared src/test
Lennart Poettering
lennart at kemper.freedesktop.org
Wed Jul 2 04:46:21 PDT 2014
src/hostname/hostnamed.c | 2 +-
src/login/pam_systemd.c | 4 +---
src/network/networkd-link.c | 12 ------------
src/shared/util.c | 27 +++++++++++++++++++++------
src/shared/util.h | 2 ++
src/test/test-util.c | 8 +++++---
6 files changed, 30 insertions(+), 25 deletions(-)
New commits:
commit e0a33e7ba619eb44f732aaf23cb249fa43d0ce8d
Author: Lennart Poettering <lennart at poettering.net>
Date: Wed Jul 2 13:42:25 2014 +0200
util: when unescaping strings, don't allow smuggling in of additional NUL bytes
Better safe than sorry.
diff --git a/src/shared/util.c b/src/shared/util.c
index ceafa01..4ad3f20 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -1256,7 +1256,7 @@ char *cunescape_length_with_prefix(const char *s, size_t length, const char *pre
a = unhexchar(f[1]);
b = unhexchar(f[2]);
- if (a < 0 || b < 0) {
+ if (a < 0 || b < 0 || (a == 0 && b == 0)) {
/* Invalid escape code, let's take it literal then */
*(t++) = '\\';
*(t++) = 'x';
@@ -1283,7 +1283,7 @@ char *cunescape_length_with_prefix(const char *s, size_t length, const char *pre
b = unoctchar(f[1]);
c = unoctchar(f[2]);
- if (a < 0 || b < 0 || c < 0) {
+ if (a < 0 || b < 0 || c < 0 || (a == 0 && b == 0 && c == 0)) {
/* Invalid escape code, let's take it literal then */
*(t++) = '\\';
*(t++) = f[0];
@@ -1566,8 +1566,7 @@ int chvt(int vt) {
int read_one_char(FILE *f, char *ret, usec_t t, bool *need_nl) {
struct termios old_termios, new_termios;
- char c;
- char line[LINE_MAX];
+ char c, line[LINE_MAX];
assert(f);
assert(ret);
@@ -1604,9 +1603,10 @@ int read_one_char(FILE *f, char *ret, usec_t t, bool *need_nl) {
}
}
- if (t != (usec_t) -1)
+ if (t != (usec_t) -1) {
if (fd_wait_for_event(fileno(f), POLLIN, t) <= 0)
return -ETIMEDOUT;
+ }
if (!fgets(line, sizeof(line), f))
return -EIO;
@@ -1624,6 +1624,7 @@ int read_one_char(FILE *f, char *ret, usec_t t, bool *need_nl) {
}
int ask(char *ret, const char *replies, const char *text, ...) {
+ int r;
assert(ret);
assert(replies);
@@ -1632,7 +1633,6 @@ int ask(char *ret, const char *replies, const char *text, ...) {
for (;;) {
va_list ap;
char c;
- int r;
bool need_nl = true;
if (on_tty())
diff --git a/src/test/test-util.c b/src/test/test-util.c
index dbc7cfe..44921bd 100644
--- a/src/test/test-util.c
+++ b/src/test/test-util.c
@@ -297,14 +297,16 @@ static void test_undecchar(void) {
static void test_cescape(void) {
_cleanup_free_ char *escaped;
- escaped = cescape("abc\\\"\b\f\n\r\t\v\a\003\177\234\313");
+
+ assert_se(escaped = cescape("abc\\\"\b\f\n\r\t\v\a\003\177\234\313"));
assert_se(streq(escaped, "abc\\\\\\\"\\b\\f\\n\\r\\t\\v\\a\\003\\177\\234\\313"));
}
static void test_cunescape(void) {
_cleanup_free_ char *unescaped;
- unescaped = cunescape("abc\\\\\\\"\\b\\f\\a\\n\\r\\t\\v\\003\\177\\234\\313");
- assert_se(streq(unescaped, "abc\\\"\b\f\a\n\r\t\v\003\177\234\313"));
+
+ assert_se(unescaped = cunescape("abc\\\\\\\"\\b\\f\\a\\n\\r\\t\\v\\003\\177\\234\\313\\000\\x00"));
+ assert_se(streq(unescaped, "abc\\\"\b\f\a\n\r\t\v\003\177\234\313\\000\\x00"));
}
static void test_foreach_word(void) {
commit fecc80c1ba2eed9dadb9a10c15508c356bcc5fc1
Author: Lennart Poettering <lennart at poettering.net>
Date: Wed Jul 2 13:41:31 2014 +0200
util: generalize is_localhost() and use it everywhere where applicable
diff --git a/src/hostname/hostnamed.c b/src/hostname/hostnamed.c
index 241d296..c2b6d3d 100644
--- a/src/hostname/hostnamed.c
+++ b/src/hostname/hostnamed.c
@@ -258,7 +258,7 @@ static char* context_fallback_icon_name(Context *c) {
}
static bool hostname_is_useful(const char *hn) {
- return !isempty(hn) && !streq(hn, "localhost");
+ return !isempty(hn) && !is_localhost(hn);
}
static int context_update_kernel_hostname(Context *c) {
diff --git a/src/login/pam_systemd.c b/src/login/pam_systemd.c
index 262621d..f522d6e 100644
--- a/src/login/pam_systemd.c
+++ b/src/login/pam_systemd.c
@@ -357,9 +357,7 @@ _public_ PAM_EXTERN int pam_sm_open_session(
if (isempty(class))
class = streq(type, "unspecified") ? "background" : "user";
- remote = !isempty(remote_host) &&
- !streq_ptr(remote_host, "localhost") &&
- !streq_ptr(remote_host, "localhost.localdomain");
+ remote = !isempty(remote_host) && !is_localhost(remote_host);
/* Talk to logind over the message bus */
diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c
index 3324276..660efed 100644
--- a/src/network/networkd-link.c
+++ b/src/network/networkd-link.c
@@ -1928,18 +1928,6 @@ static int link_enter_enslave(Link *link) {
return 0;
}
-/* make sure the hostname is not "localhost" */
-static bool is_localhost(const char *hostname) {
- assert(hostname);
-
- return streq(hostname, "localhost") ||
- streq(hostname, "localhost.") ||
- endswith(hostname, ".localhost") ||
- endswith(hostname, ".localhost.") ||
- endswith(hostname, ".localdomain") ||
- endswith(hostname, ".localdomain.");
-}
-
static int link_configure(Link *link) {
int r;
diff --git a/src/shared/util.c b/src/shared/util.c
index a1c8baf..ceafa01 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -6732,3 +6732,18 @@ char *tempfn_random(const char *p) {
return t;
}
+
+/* make sure the hostname is not "localhost" */
+bool is_localhost(const char *hostname) {
+ assert(hostname);
+
+ /* This tries to identify local hostnames described in RFC6761
+ * plus the redhatism of .localdomain */
+
+ return streq(hostname, "localhost") ||
+ streq(hostname, "localhost.") ||
+ endswith(hostname, ".localhost") ||
+ endswith(hostname, ".localhost.") ||
+ endswith(hostname, ".localdomain") ||
+ endswith(hostname, ".localdomain.");
+}
diff --git a/src/shared/util.h b/src/shared/util.h
index 6ad43cd..6d3791b 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -959,3 +959,5 @@ int fflush_and_check(FILE *f);
char *tempfn_xxxxxx(const char *p);
char *tempfn_random(const char *p);
+
+bool is_localhost(const char *hostname);
More information about the systemd-commits
mailing list