From 3fa615778e441b4ea6c43baa2986efac9ab85d0e Mon Sep 17 00:00:00 2001 From: ben Date: Thu, 20 Feb 2003 22:31:52 +0000 Subject: [PATCH] Be careful not to try to get information from windows we don't own, or that don't exist at all. Also a small PuTTYgen change that I can't be bothered to filter out of this commit. git-svn-id: svn://svn.tartarus.org/sgt/putty@2874 cda61777-01e9-0310-a592-d414129be87e --- mac/mac.c | 14 +++++++------- mac/mac.h | 6 ++++++ mac/macmisc.c | 21 ++++++++++++++++++++- 3 files changed, 33 insertions(+), 8 deletions(-) diff --git a/mac/mac.c b/mac/mac.c index a0bc998b..1ff3a87f 100644 --- a/mac/mac.c +++ b/mac/mac.c @@ -1,4 +1,4 @@ -/* $Id: mac.c,v 1.49 2003/02/15 16:22:15 ben Exp $ */ +/* $Id: mac.c,v 1.50 2003/02/20 22:31:52 ben Exp $ */ /* * Copyright (c) 1999, 2003 Ben Harris * All rights reserved. @@ -377,7 +377,7 @@ static int mac_windowtype(WindowPtr window) static void mac_keypress(EventRecord *event) { WindowPtr window; - window = FrontWindow(); + window = mac_frontwindow(); /* * Check for a command-key combination, but ignore it if it counts * as a meta-key combination and we're in a terminal window. @@ -388,7 +388,7 @@ static void mac_keypress(EventRecord *event) { mac_adjustmenus(); mac_menucommand(MenuKey(event->message & charCodeMask)); } else { - if (mac_wininfo(window)->key != NULL) + if (window != NULL && mac_wininfo(window)->key != NULL) (*mac_wininfo(window)->key)(window, event); } } @@ -402,7 +402,7 @@ static void mac_menucommand(long result) { menu = HiWord(result); item = LoWord(result); - window = FrontWindow(); + window = mac_frontwindow(); /* Things which do the same whatever window we're in. */ switch (menu) { case mApple: @@ -445,7 +445,7 @@ static void mac_menucommand(long result) { break; } /* If we get here, handling is up to window-specific code. */ - if (mac_wininfo(window)->menu != NULL) + if (window != NULL && mac_wininfo(window)->menu != NULL) (*mac_wininfo(window)->menu)(window, menu, item); done: @@ -483,7 +483,7 @@ static void mac_adjustmenus(void) { WindowPtr window; MenuHandle menu; - window = FrontWindow(); + window = mac_frontwindow(); menu = GetMenuHandle(mApple); EnableItem(menu, 0); EnableItem(menu, iAbout); @@ -497,7 +497,7 @@ static void mac_adjustmenus(void) { DisableItem(menu, iClose); EnableItem(menu, iQuit); - if (mac_wininfo(window)->adjustmenus != NULL) + if (window != NULL && mac_wininfo(window)->adjustmenus != NULL) (*mac_wininfo(window)->adjustmenus)(window); else { DisableItem(menu, iSave); diff --git a/mac/mac.h b/mac/mac.h index c228d1bd..e18ff742 100644 --- a/mac/mac.h +++ b/mac/mac.h @@ -112,10 +112,16 @@ extern Session *sesslist; /* PuTTYgen per-window state */ typedef struct KeyState { DialogPtr box; + int collecting_entropy; + int entropy_got, entropy_required, entropy_size; + unsigned *entropy; + ControlHandle progress; } KeyState; #define mac_windowkey(w) (((WinInfo *)GetWRefCon(w))->ks) +/* from macmisc.c */ +extern WindowPtr mac_frontwindow(void); /* from macdlg.c */ extern void mac_newsession(void); extern void mac_dupsession(void); diff --git a/mac/macmisc.c b/mac/macmisc.c index a5cb1f5f..b2479781 100644 --- a/mac/macmisc.c +++ b/mac/macmisc.c @@ -1,4 +1,4 @@ -/* $Id: macmisc.c,v 1.1 2003/02/12 23:53:15 ben Exp $ */ +/* $Id: macmisc.c,v 1.2 2003/02/20 22:31:52 ben Exp $ */ /* * Copyright (c) 1999, 2003 Ben Harris * All rights reserved. @@ -28,6 +28,8 @@ #include #include #include +#include +#include #include #include @@ -35,6 +37,7 @@ #include #include "putty.h" +#include "mac.h" #if TARGET_API_MAC_CARBON /* @@ -48,6 +51,22 @@ const CFAllocatorRef kCFAllocatorDefault = NULL; QDGlobals qd; #endif +/* + * Like FrontWindow(), but return NULL if we aren't the front process + * (i.e. the front window isn't one of ours). + */ +WindowPtr mac_frontwindow(void) +{ + ProcessSerialNumber frontpsn; + ProcessSerialNumber curpsn = { 0, kCurrentProcess }; + Boolean result; + + GetFrontProcess(&frontpsn); + if (SameProcess(&frontpsn, &curpsn, &result) == noErr && result) + return FrontWindow(); + return NULL; +} + void fatalbox(char *fmt, ...) { va_list ap; Str255 stuff; -- 2.11.0