Don't try to dereference replies[] if it is a NULL pointer.
This commit is contained in:
@@ -53,7 +53,6 @@ sudo_conversation(int num_msgs, const struct sudo_conv_message msgs[],
|
|||||||
|
|
||||||
for (n = 0; n < num_msgs; n++) {
|
for (n = 0; n < num_msgs; n++) {
|
||||||
const struct sudo_conv_message *msg = &msgs[n];
|
const struct sudo_conv_message *msg = &msgs[n];
|
||||||
struct sudo_conv_reply *repl = &replies[n];
|
|
||||||
int flags = tgetpass_flags;
|
int flags = tgetpass_flags;
|
||||||
|
|
||||||
switch (msg->msg_type & 0xff) {
|
switch (msg->msg_type & 0xff) {
|
||||||
@@ -71,7 +70,8 @@ sudo_conversation(int num_msgs, const struct sudo_conv_message msgs[],
|
|||||||
pass = tgetpass(msg->msg, msg->timeout, flags, callback);
|
pass = tgetpass(msg->msg, msg->timeout, flags, callback);
|
||||||
if (pass == NULL)
|
if (pass == NULL)
|
||||||
goto err;
|
goto err;
|
||||||
if ((repl->reply = strdup(pass)) == NULL) {
|
replies[n].reply = strdup(pass);
|
||||||
|
if (replies[n].reply == NULL) {
|
||||||
sudo_fatalx_nodebug(U_("%s: %s"), "sudo_conversation",
|
sudo_fatalx_nodebug(U_("%s: %s"), "sudo_conversation",
|
||||||
U_("unable to allocate memory"));
|
U_("unable to allocate memory"));
|
||||||
}
|
}
|
||||||
@@ -95,14 +95,16 @@ sudo_conversation(int num_msgs, const struct sudo_conv_message msgs[],
|
|||||||
|
|
||||||
err:
|
err:
|
||||||
/* Zero and free allocated memory and return an error. */
|
/* Zero and free allocated memory and return an error. */
|
||||||
do {
|
if (replies != 0) {
|
||||||
struct sudo_conv_reply *repl = &replies[n];
|
do {
|
||||||
if (repl->reply != NULL) {
|
struct sudo_conv_reply *repl = &replies[n];
|
||||||
|
if (repl->reply == NULL)
|
||||||
|
continue;
|
||||||
memset_s(repl->reply, SUDO_CONV_REPL_MAX, 0, strlen(repl->reply));
|
memset_s(repl->reply, SUDO_CONV_REPL_MAX, 0, strlen(repl->reply));
|
||||||
free(repl->reply);
|
free(repl->reply);
|
||||||
repl->reply = NULL;
|
repl->reply = NULL;
|
||||||
}
|
} while (n--);
|
||||||
} while (n--);
|
}
|
||||||
|
|
||||||
sudo_debug_set_active_instance(conv_debug_instance);
|
sudo_debug_set_active_instance(conv_debug_instance);
|
||||||
return -1;
|
return -1;
|
||||||
|
Reference in New Issue
Block a user