Skip to content

Commit

Permalink
Fix checking for memory allocation errors
Browse files Browse the repository at this point in the history
These should never happen, but call exit() if they do.  Also avoid
freeing an uninitialized PAM handle in such an error case.

I do not consider this a security vulnerability because there is no
reasonable way I know of for an attacker to trigger this failure, but
this commit should still be backported.
  • Loading branch information
DemiMarie committed Feb 20, 2025
1 parent 7e30563 commit b90eb2c
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions agent/qrexec-agent.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,23 +196,31 @@ _Noreturn void do_exec(const char *prog, const char *cmd, const char *user)
*/
pw_copy = *pw;
pw = &pw_copy;
pw->pw_name = strdup(pw->pw_name);
pw->pw_passwd = strdup(pw->pw_passwd);
pw->pw_dir = strdup(pw->pw_dir);
pw->pw_shell = strdup(pw->pw_shell);
if (!((pw->pw_name = strdup(pw->pw_name)) &&
(pw->pw_passwd = strdup(pw->pw_passwd)) &&
(pw->pw_dir = strdup(pw->pw_dir)) &&
(pw->pw_shell = strdup(pw->pw_shell)))) {
PERROR("strdup");
exit(QREXEC_EXIT_PROBLEM);

Check warning on line 204 in agent/qrexec-agent.c

View check run for this annotation

Codecov / codecov/patch

agent/qrexec-agent.c#L199-L204

Added lines #L199 - L204 were not covered by tests
}
endpwent();

shell_basename = basename (pw->pw_shell);
/* this process is going to die shortly, so don't care about freeing */
arg0 = malloc (strlen (shell_basename) + 2);
if (!arg0)
goto error;
if (!arg0) {
PERROR("malloc");
exit(QREXEC_EXIT_PROBLEM);

Check warning on line 213 in agent/qrexec-agent.c

View check run for this annotation

Codecov / codecov/patch

agent/qrexec-agent.c#L211-L213

Added lines #L211 - L213 were not covered by tests
}
arg0[0] = '-';
strcpy (arg0 + 1, shell_basename);

retval = pam_start("qrexec", user, &conv, &pamh);
if (retval != PAM_SUCCESS)
if (retval != PAM_SUCCESS) {
LOG(ERROR, "PAM handle could not be acquired");
pamh = NULL;

Check warning on line 221 in agent/qrexec-agent.c

View check run for this annotation

Codecov / codecov/patch

agent/qrexec-agent.c#L219-L221

Added lines #L219 - L221 were not covered by tests
goto error;
}

retval = pam_authenticate(pamh, 0);
if (retval != PAM_SUCCESS)
Expand Down

0 comments on commit b90eb2c

Please sign in to comment.