X-Git-Url: https://git.distorted.org.uk/u/mdw/putty/blobdiff_plain/2d466ffd08675d26db45e524c2fe6a8cf4628e2b..2ed9fb8a1161813bd21e396475d4810f27fac7eb:/pageant.c diff --git a/pageant.c b/pageant.c index 853341ac..6ab373e1 100644 --- a/pageant.c +++ b/pageant.c @@ -74,6 +74,8 @@ int random_byte(void) { MessageBox(hwnd, "Internal Error", APPNAME, MB_OK | MB_ICONERROR); exit(0); + /* this line can't be reached but it placates MSVC's warnings :-) */ + return 0; } /* @@ -168,6 +170,8 @@ static int CALLBACK AboutProc(HWND hwnd, UINT msg, return 0; } +static HWND passphrase_box; + /* * Dialog-box function for the passphrase box. */ @@ -179,6 +183,7 @@ static int CALLBACK PassphraseProc(HWND hwnd, UINT msg, switch (msg) { case WM_INITDIALOG: + passphrase_box = hwnd; /* * Centre the window. */ @@ -324,6 +329,7 @@ static void add_keyfile(char *filename) int dlgret; dlgret = DialogBoxParam(instance, MAKEINTRESOURCE(210), NULL, PassphraseProc, (LPARAM) & pps); + passphrase_box = NULL; if (!dlgret) { if (comment) sfree(comment); @@ -644,16 +650,19 @@ static void answer_msg(void *msg) { struct RSAKey *key; char *comment; + int commentlen; key = smalloc(sizeof(struct RSAKey)); - memset(key, 0, sizeof(key)); + memset(key, 0, sizeof(struct RSAKey)); p += makekey(p, key, NULL, 1); p += makeprivate(p, key); - p += ssh1_read_bignum(p, key->iqmp); /* p^-1 mod q */ - p += ssh1_read_bignum(p, key->p); /* p */ - p += ssh1_read_bignum(p, key->q); /* q */ - comment = smalloc(GET_32BIT(p)); + p += ssh1_read_bignum(p, &key->iqmp); /* p^-1 mod q */ + p += ssh1_read_bignum(p, &key->p); /* p */ + p += ssh1_read_bignum(p, &key->q); /* q */ + commentlen = GET_32BIT(p); + comment = smalloc(commentlen+1); if (comment) { - memcpy(comment, p + 4, GET_32BIT(p)); + memcpy(comment, p + 4, commentlen); + comment[commentlen] = '\0'; key->comment = comment; } PUT_32BIT(ret, 1); @@ -1017,6 +1026,11 @@ static int CALLBACK KeyListProc(HWND hwnd, UINT msg, case 101: /* add key */ if (HIWORD(wParam) == BN_CLICKED || HIWORD(wParam) == BN_DOUBLECLICKED) { + if (passphrase_box) { + MessageBeep(MB_ICONERROR); + SetForegroundWindow(passphrase_box); + break; + } prompt_add_keyfile(); } return 0; @@ -1091,6 +1105,8 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, case WM_SYSCOMMAND: switch (wParam & ~0xF) { /* low 4 bits reserved to Windows */ case IDM_CLOSE: + if (passphrase_box) + SendMessage(passphrase_box, WM_CLOSE, 0, 0); SendMessage(hwnd, WM_CLOSE, 0, 0); break; case IDM_VIEWKEYS: @@ -1108,6 +1124,11 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, } break; case IDM_ADDKEY: + if (passphrase_box) { + MessageBeep(MB_ICONERROR); + SetForegroundWindow(passphrase_box); + break; + } prompt_add_keyfile(); break; case IDM_ABOUT: