diff options
author | Colin Walters <walters@verbum.org> | 2012-06-06 09:05:14 -0400 |
---|---|---|
committer | David Zeuthen <zeuthen@gmail.com> | 2012-06-06 13:27:31 -0400 |
commit | 14121fda7e4fa9463c66ce419cc32be7e7f3b535 (patch) | |
tree | 47bd7c7e8189f6e95204fd321fd1f5c86a0aa240 /src/polkitagent | |
parent | 4f7830c4d3200eac14b49f04f2c200e3cfd824c1 (diff) | |
download | polkit-14121fda7e4fa9463c66ce419cc32be7e7f3b535.tar.gz |
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>
Diffstat (limited to 'src/polkitagent')
-rw-r--r-- | src/polkitagent/polkitagenthelper-pam.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/src/polkitagent/polkitagenthelper-pam.c b/src/polkitagent/polkitagenthelper-pam.c index 85a2671..7af5321 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 |