summaryrefslogtreecommitdiffstats
path: root/patches/polkit-0.105/0001-0.106-agenthelper-pam-Fix-newline-trimming-code.patch
blob: 0dcef786fd978969eecd0d589c387f8a71ea36bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
From: Colin Walters <walters@verbum.org>
Date: Wed, 6 Jun 2012 09:05:14 -0400
Subject: [PATCH] 0.106: agenthelper-pam: Fix newline-trimming code

First, we were using == instead of =, as the author probably intended.
But after changing that, we're now assigning to const memory.  Fix
that by writing to a temporary string buffer.

Signed-off-by: David Zeuthen <zeuthen@gmail.com>
Origin: upstream, 0.106, commit:14121fda7e4fa9463c66ce419cc32be7e7f3b535

Imported from policykit-1_0.105-25.debian.tar.xz

Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
---
 src/polkitagent/polkitagenthelper-pam.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/src/polkitagent/polkitagenthelper-pam.c b/src/polkitagent/polkitagenthelper-pam.c
index 85a26718a513..7af5321ebfa3 100644
--- a/src/polkitagent/polkitagenthelper-pam.c
+++ b/src/polkitagent/polkitagenthelper-pam.c
@@ -227,6 +227,8 @@ conversation_function (int n, const struct pam_message **msg, struct pam_respons
   char buf[PAM_MAX_RESP_SIZE];
   int i;
   gchar *escaped = NULL;
+  gchar *tmp = NULL;
+  size_t len;
 
   data = data;
   if (n <= 0 || n > PAM_MAX_NUM_MSG)
@@ -258,9 +260,12 @@ conversation_function (int n, const struct pam_message **msg, struct pam_respons
 #ifdef PAH_DEBUG
           fprintf (stderr, "polkit-agent-helper-1: writing `%s' to stdout\n", msg[i]->msg);
 #endif /* PAH_DEBUG */
-          if (strlen (msg[i]->msg) > 0 && msg[i]->msg[strlen (msg[i]->msg) - 1] == '\n')
-            msg[i]->msg[strlen (msg[i]->msg) - 1] == '\0';
-          escaped = g_strescape (msg[i]->msg, NULL);
+          tmp = g_strdup (msg[i]->msg);
+          len = strlen (tmp);
+          if (len > 0 && tmp[len - 1] == '\n')
+            tmp[len - 1] = '\0';
+          escaped = g_strescape (tmp, NULL);
+          g_free (tmp);
           fputs (escaped, stdout);
           g_free (escaped);
 #ifdef PAH_DEBUG