Skip to content

Commit

Permalink
pkttyagent: EOF in password causes coredump
Browse files Browse the repository at this point in the history
  • Loading branch information
jrybar-rh committed Mar 11, 2024
1 parent b3a3a25 commit b1a0227
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/polkitagent/polkitagenttextlistener.c
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ on_request (PolkitAgentSession *session,
PolkitAgentTextListener *listener = POLKIT_AGENT_TEXT_LISTENER (user_data);
struct termios ts, ots;
GString *str;
gint c;

fprintf (listener->tty, "%s", request);
fflush (listener->tty);
Expand Down Expand Up @@ -374,7 +375,6 @@ on_request (PolkitAgentSession *session,
str = g_string_new (NULL);
while (TRUE)
{
gint c;
c = getc (listener->tty);
if (c == '\n')
{
Expand All @@ -384,8 +384,7 @@ on_request (PolkitAgentSession *session,
else if (c == EOF)
{
tcsetattr (fileno (listener->tty), TCSAFLUSH, &ots);
g_error ("Got unexpected EOF while reading from controlling terminal.");
abort ();
g_warning ("Got unexpected EOF while reading from controlling terminal.");
break;
}
else
Expand All @@ -397,7 +396,15 @@ on_request (PolkitAgentSession *session,
g_signal_emit_by_name(listener, "tty_attrs_changed", FALSE);
putc ('\n', listener->tty);

polkit_agent_session_response (session, str->str);
if (c == EOF)
{
polkit_agent_session_cancel (listener->active_session);
}
else
{
polkit_agent_session_response (session, str->str);
}

memset (str->str, '\0', str->len);
g_string_free (str, TRUE);
}
Expand Down Expand Up @@ -512,9 +519,9 @@ choose_identity (PolkitAgentTextListener *listener,
}
else if (c == EOF)
{
g_error ("Got unexpected EOF while reading from controlling terminal.");
abort ();
break;
g_warning ("Got unexpected EOF while reading from controlling terminal.");
ret = NULL; /* let' be defensive */
goto out;
}
else
{
Expand Down

0 comments on commit b1a0227

Please sign in to comment.