Skip to content

Commit 107fdb6

Browse files
committed
bsdauth_verify: restore SIGCHLD signal handler on asprintf() failure
Reported by Maiquel Paiva
1 parent a7a52f2 commit 107fdb6

1 file changed

Lines changed: 22 additions & 19 deletions

File tree

plugins/sudoers/auth/bsdauth.c

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ bsdauth_verify(const struct sudoers_context *ctx, struct passwd *pw,
109109
char *pass;
110110
char *s;
111111
size_t len;
112-
int authok = 0;
112+
int ret = AUTH_ERROR;
113113
struct sigaction sa, osa;
114114
auth_session_t *as = ((struct bsdauth_state *) auth->data)->as;
115115
debug_decl(bsdauth_verify, SUDOERS_DEBUG_AUTH);
@@ -123,15 +123,15 @@ bsdauth_verify(const struct sudoers_context *ctx, struct passwd *pw,
123123
sa.sa_handler = SIG_DFL;
124124
(void) sigaction(SIGCHLD, &sa, &osa);
125125

126-
/*
127-
* If there is a challenge then print that instead of the normal
128-
* prompt. If the user just hits return we prompt again with echo
129-
* turned on, which is useful for challenge/response things like
130-
* S/Key.
131-
*/
132126
if ((s = auth_challenge(as)) == NULL) {
127+
/* No challenge, use normal password prompt. */
133128
pass = auth_getpass(prompt, SUDO_CONV_PROMPT_ECHO_OFF, callback);
134129
} else {
130+
/*
131+
* Print the challenge instead of the normal prompt. If the
132+
* user just hits return we prompt again with echo turned on,
133+
* which is useful for challenge/response things like S/Key.
134+
*/
135135
pass = auth_getpass(s, SUDO_CONV_PROMPT_ECHO_OFF, callback);
136136
if (pass != NULL && *pass == '\0') {
137137
if ((prompt = strrchr(s, '\n')))
@@ -148,31 +148,34 @@ bsdauth_verify(const struct sudoers_context *ctx, struct passwd *pw,
148148
len--;
149149
if (asprintf(&s, "%.*s [echo on]: ", (int)len, prompt) == -1) {
150150
log_warningx(ctx, 0, N_("unable to allocate memory"));
151-
debug_return_int(AUTH_ERROR);
151+
goto done;
152152
}
153153
free(pass);
154154
pass = auth_getpass(s, SUDO_CONV_PROMPT_ECHO_ON, callback);
155155
free(s);
156156
}
157157
}
158158

159-
if (pass != NULL) {
160-
authok = auth_userresponse(as, pass, 1);
159+
if (pass == NULL) {
160+
/* error or ^C from tgetpass() */
161+
ret = AUTH_INTR;
162+
} else {
163+
/* verify password */
164+
if (auth_userresponse(as, pass, 1)) {
165+
ret = AUTH_SUCCESS;
166+
} else {
167+
ret = AUTH_FAILURE;
168+
if ((s = auth_getvalue(as, (char *)"errormsg")) != NULL)
169+
log_warningx(ctx, 0, "%s", s);
170+
}
161171
freezero(pass, strlen(pass));
162172
}
163173

174+
done:
164175
/* restore old signal handler */
165176
(void) sigaction(SIGCHLD, &osa, NULL);
166177

167-
if (authok)
168-
debug_return_int(AUTH_SUCCESS);
169-
170-
if (pass == NULL)
171-
debug_return_int(AUTH_INTR);
172-
173-
if ((s = auth_getvalue(as, (char *)"errormsg")) != NULL)
174-
log_warningx(ctx, 0, "%s", s);
175-
debug_return_int(AUTH_FAILURE);
178+
debug_return_int(ret);
176179
}
177180

178181
int

0 commit comments

Comments
 (0)