From c194931d2eac3d81cf5d0fd388ea1ae58cae0ebd Mon Sep 17 00:00:00 2001
From: Lennart Poettering <lennart@poettering.net>
Date: Thu, 22 May 2014 10:35:28 +0900
Subject: [PATCH] logind: also escape external data when saving to /run
Better be safe than sorry...
(cherry picked from commit 558c6490b1df7f82a63d0a747fda7412c4d28b0c)
(cherry picked from commit 1be1ff309f703b077bf87020d520469d33546e03)
Conflicts:
src/login/logind-session.c
---
src/login/logind-session.c | 40 +++++++++++++++++++++++++++++++++-------
1 file changed, 33 insertions(+), 7 deletions(-)
diff --git a/src/login/logind-session.c b/src/login/logind-session.c
index 13de549ddf..9c87e4326f 100644
--- a/src/login/logind-session.c
+++ b/src/login/logind-session.c
@@ -202,7 +202,6 @@ int session_save(Session *s) {
if (s->scope)
fprintf(f, "SCOPE=%s\n", s->scope);
-
if (s->scope_job)
fprintf(f, "SCOPE_JOB=%s\n", s->scope_job);
@@ -218,14 +217,41 @@ int session_save(Session *s) {
if (s->display)
fprintf(f, "DISPLAY=%s\n", s->display);
- if (s->remote_host)
- fprintf(f, "REMOTE_HOST=%s\n", s->remote_host);
+ if (s->remote_host) {
+ _cleanup_free_ char *escaped;
+
+ escaped = cescape(s->remote_host);
+ if (!escaped) {
+ r = -ENOMEM;
+ goto finish;
+ }
- if (s->remote_user)
- fprintf(f, "REMOTE_USER=%s\n", s->remote_user);
+ fprintf(f, "REMOTE_HOST=%s\n", escaped);
+ }
+
+ if (s->remote_user) {
+ _cleanup_free_ char *escaped;
+
+ escaped = cescape(s->remote_user);
+ if (!escaped) {
+ r = -ENOMEM;
+ goto finish;
+ }
- if (s->service)
- fprintf(f, "SERVICE=%s\n", s->service);
+ fprintf(f, "REMOTE_USER=%s\n", escaped);
+ }
+
+ if (s->service) {
+ _cleanup_free_ char *escaped;
+
+ escaped = cescape(s->service);
+ if (!escaped) {
+ r = -ENOMEM;
+ goto finish;
+ }
+
+ fprintf(f, "SERVICE=%s\n", escaped);
+ }
if (s->seat && seat_has_vts(s->seat))
fprintf(f, "VTNR=%i\n", s->vtnr);