X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fshared%2Ffileio.c;h=f10126954b2d4d2b6a53c52cb0eb65e77f385a5c;hb=98b2f766b24c84fc49a4df954717b1f96bbce00d;hp=838d1284332793a09c20a11c58dfd3a9fef0b640;hpb=f27f0e2177ac0a4b96585aed7db3a080e27a2f00;p=elogind.git diff --git a/src/shared/fileio.c b/src/shared/fileio.c index 838d12843..f10126954 100644 --- a/src/shared/fileio.c +++ b/src/shared/fileio.c @@ -130,7 +130,7 @@ ssize_t sendfile_full(int out_fd, const char *fn) { assert(out_fd > 0); assert(fn); - f = fopen(fn, "r"); + f = fopen(fn, "re"); if (!f) return -errno; @@ -539,15 +539,18 @@ static int parse_env_file_push(const char *filename, unsigned line, va_list aq, *ap = userdata; if (!utf8_is_valid(key)) { - log_error("%s:%u: invalid UTF-8 for key '%s', ignoring.", - filename, line, key); + _cleanup_free_ char *p = utf8_escape_invalid(key); + + log_error("%s:%u: invalid UTF-8 in key '%s', ignoring.", + filename, line, p); return -EINVAL; } if (value && !utf8_is_valid(value)) { - /* FIXME: filter UTF-8 */ + _cleanup_free_ char *p = utf8_escape_invalid(value); + log_error("%s:%u: invalid UTF-8 value for key %s: '%s', ignoring.", - filename, line, key, value); + filename, line, key, p); return -EINVAL; } @@ -595,15 +598,18 @@ static int load_env_file_push(const char *filename, unsigned line, int r; if (!utf8_is_valid(key)) { + _cleanup_free_ char *t = utf8_escape_invalid(key); + log_error("%s:%u: invalid UTF-8 for key '%s', ignoring.", - filename, line, key); + filename, line, t); return -EINVAL; } if (value && !utf8_is_valid(value)) { - /* FIXME: filter UTF-8 */ + _cleanup_free_ char *t = utf8_escape_invalid(value); + log_error("%s:%u: invalid UTF-8 value for key %s: '%s', ignoring.", - filename, line, key, value); + filename, line, key, t); return -EINVAL; } @@ -611,11 +617,9 @@ static int load_env_file_push(const char *filename, unsigned line, if (!p) return -ENOMEM; - r = strv_push(m, p); - if (r < 0) { - free(p); + r = strv_consume(m, p); + if (r < 0) return r; - } free(value); return 0;