PATCH: GlobalAddAtomA check for invalid ptr
Marcus Meissner
meissner at suse.de
Sun Aug 14 06:00:03 CDT 2005
On Thu, Aug 11, 2005 at 02:52:52PM +0200, Alexandre Julliard wrote:
> Marcus Meissner <marcus at jet.franken.de> writes:
>
> > So ... now we can:
> >
> > - fix this program by contacting the developers etc... which is difficult.
> > - fix WINE by adding a check.
> >
> > I can only fix WINE.
>
> Yes, but please don't use the IsBad* functions, use a proper exception
> handler.
Next try, is this what you imagined.
I now do a strlen() in GlobalAddAtomA(), however the compiler might optimize it
away in the future (gcc 4.1 doesn't).
Ciao, Marcus
Changelog:
Catch invalid strings in GlobalAddAtomA() using an
exception handler.
Index: dlls/kernel/atom.c
===================================================================
RCS file: /home/wine/wine/dlls/kernel/atom.c,v
retrieving revision 1.8
diff -u -r1.8 atom.c
--- dlls/kernel/atom.c 10 May 2005 15:15:50 -0000 1.8
+++ dlls/kernel/atom.c 14 Aug 2005 10:24:46 -0000
@@ -38,6 +38,8 @@
#include "winbase.h"
#include "winerror.h"
+#include "wine/exception.h"
+#include "excpt.h"
#include "wine/server.h"
#include "wine/unicode.h"
#include "kernel_private.h"
@@ -48,6 +50,14 @@
#define MAX_ATOM_LEN 255
+/* filter for page-fault exceptions */
+static WINE_EXCEPTION_FILTER(page_fault)
+{
+ if (GetExceptionCode() == EXCEPTION_ACCESS_VIOLATION)
+ return EXCEPTION_EXECUTE_HANDLER;
+ return EXCEPTION_CONTINUE_SEARCH;
+}
+
static struct atom_table* get_local_table(DWORD entries)
{
static struct atom_table* local_table;
@@ -183,6 +193,20 @@
*/
ATOM WINAPI GlobalAddAtomA( LPCSTR str /* [in] String to add */ )
{
+ if (HIWORD(str)) {
+ __TRY {
+ char *s = (char*)str;
+ while (*s) s++;
+ /* FIXME: Should make sure the compiler does
+ * not throw away the above.
+ */
+ }
+ __EXCEPT(page_fault) {
+ SetLastError( ERROR_INVALID_PARAMETER );
+ return 0;
+ }
+ __ENDTRY
+ }
return ATOM_AddAtomA( str, NULL );
}
More information about the wine-devel
mailing list