Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can abusing RegisterWindowMessage lead to resource exhaustion?

Tags:

windows

winapi

MSDN advises that RegisterWindowMessage() function is only used for registering messages to be sent between the processes. If a message is needed for sending within one process it can be safely selected from the range WM_APP through 0xBFFF.

However in our codebase I often see that RegisterWindowMessage() is used for messages only sent within one process. I suppose that this was done because of perceived simplicity of using RegisterWindowMessage() since it doesn't require manually distributing the message identifiers in the WM_APP..0xBFFF range.

Do I understand correctly that if many applications are run on one machine and they all call RegisterWindowMessage() with different strings they could exhaust the range of message identifiers allowed to return by RegisterWindowMessage() and for some of them it will just return a value indicating a failure? What could be a valid reason for using RegisterWindowMessage() messages in cases where WM_APP..0xBFFF range messages would suffice?

like image 291
sharptooth Avatar asked Jul 28 '09 06:07

sharptooth


2 Answers

IMHO there is no valid reason to use RegisterWindowMessage if you are only sending messages to yourself

There is no (documented) way to un-register a message, so after your app quits, that registered message will stay in the atom table until reboot/logoff (I can't remember exactly where this atom table is stored, the window station or terminal server session instance probably)

like image 67
Anders Avatar answered Oct 11 '22 20:10

Anders


The reason you need to use RegisterWindowMessage even when messaging to yourself is that it protects you from the idiot who broadcasts messages in the WM_APP + N range.

Yes, this does happen.

like image 42
Bob Moore Avatar answered Oct 11 '22 20:10

Bob Moore