Skip to content
Snippets Groups Projects
Commit 407eca73 authored by Deucе's avatar Deucе :ok_hand_tone4:
Browse files

If call to GetAttributeString() fails, we have a lot worse problems

than err_len containing garbage.

Handle the error and mention we didn't get the message.
While we're here, check the return value of malloc().
parent ec8eb4ff
No related branches found
No related tags found
No related merge requests found
Pipeline #5774 failed
......@@ -49,20 +49,32 @@ cryptlib_error_message(int status, const char *msg)
char str[64];
char str2[64];
char *errmsg;
int err_len = 0;
int err_len;
bool err_written = false;
sprintf(str, "Error %d %s\r\n\r\n", status, msg);
pthread_mutex_lock(&ssh_mutex);
cl.GetAttributeString(ssh_session, CRYPT_ATTRIBUTE_ERRORMESSAGE, NULL, &err_len);
errmsg = (char *)malloc(err_len + strlen(str) + 5);
strcpy(errmsg, str);
cl.GetAttributeString(ssh_session, CRYPT_ATTRIBUTE_ERRORMESSAGE, errmsg + strlen(str), &err_len);
pthread_mutex_unlock(&ssh_mutex);
errmsg[strlen(str) + err_len] = 0;
strcat(errmsg, "\r\n\r\n");
sprintf(str2, "Error %d %s", status, msg);
uifcmsg(str2, errmsg);
free(errmsg);
if (cryptStatusOK(cl.GetAttributeString(ssh_session, CRYPT_ATTRIBUTE_ERRORMESSAGE, NULL, &err_len))) {
errmsg = malloc(err_len + strlen(str) + 5);
if (errmsg) {
strcpy(errmsg, str);
if (cryptStatusOK(cl.GetAttributeString(ssh_session, CRYPT_ATTRIBUTE_ERRORMESSAGE, errmsg + strlen(str), &err_len))) {
pthread_mutex_unlock(&ssh_mutex);
errmsg[strlen(str) + err_len] = 0;
strcat(errmsg, "\r\n\r\n");
sprintf(str2, "Error %d %s", status, msg);
uifcmsg(str2, errmsg);
err_written = true;
}
free(errmsg);
}
}
if (!err_written) {
pthread_mutex_unlock(&ssh_mutex);
sprintf(str2, "Error %d %s", status, msg);
uifcmsg(str2, "Additionally, a failure occured getting the error message");
free(errmsg);
}
}
static void
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment