chiark / gitweb /
util: consider 0x7F a control chracter (which it is: DEL)
[elogind.git] / src / shared / util.c
index 4ad3f203d7d3f1b268b1044732cea6dac745e638..d25ee6652f93a81006f354b48dedc404e4fd92bc 100644 (file)
@@ -1608,8 +1608,9 @@ int read_one_char(FILE *f, char *ret, usec_t t, bool *need_nl) {
                         return -ETIMEDOUT;
         }
 
+        errno = 0;
         if (!fgets(line, sizeof(line), f))
-                return -EIO;
+                return errno ? -errno : -EIO;
 
         truncate_nl(line);
 
@@ -3975,6 +3976,21 @@ char* hostname_cleanup(char *s, bool lowercase) {
         return s;
 }
 
+bool machine_name_is_valid(const char *s) {
+
+        if (!hostname_is_valid(s))
+                return false;
+
+        /* Machine names should be useful hostnames, but also be
+         * useful in unit names, hence we enforce a stricter length
+         * limitation. */
+
+        if (strlen(s) > 64)
+                return false;
+
+        return true;
+}
+
 int pipe_eof(int fd) {
         struct pollfd pollfd = {
                 .fd = fd,
@@ -5340,6 +5356,9 @@ bool string_is_safe(const char *p) {
                 if (*t > 0 && *t < ' ')
                         return false;
 
+                if (*t == 127)
+                        return false;
+
                 if (strchr("\\\"\'", *t))
                         return false;
         }
@@ -5356,10 +5375,14 @@ bool string_has_cc(const char *p) {
 
         assert(p);
 
-        for (t = p; *t; t++)
+        for (t = p; *t; t++) {
                 if (*t > 0 && *t < ' ' && *t != '\t')
                         return true;
 
+                if (*t == 127)
+                        return true;
+        }
+
         return false;
 }