Blob Blame History Raw
From a71b7b7e52f312c7a9fc19154ac0d444e057e1d4 Mon Sep 17 00:00:00 2001
From: Lennart Poettering <lennart@poettering.net>
Date: Mon, 7 Jul 2014 11:47:10 +0200
Subject: [PATCH] util: consider 0x7F a control chracter (which it is: DEL)

Let's better be safe than sorry.

(cherry picked from commit 3a8a916338d8446b938f3cf40f6aae0c611892e3)
---
 src/shared/util.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/src/shared/util.c b/src/shared/util.c
index 3d875c72b3..d25ee6652f 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -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);
 
@@ -5355,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;
         }
@@ -5371,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;
 }