News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

I think I found a bug in windows

Started by ecube, November 23, 2006, 07:33:29 AM

Previous topic - Next topic

ecube

Well the bug I think I found applys to createmutex. According to  http://tinyurl.com/bkwe  "If the function fails, the return value is NULL. To get extended error information, call GetLastError". Calling GetLastError right after the function call works fine but if you just check the return value againts NULL it'll fail every single time. Regardless if the mutex is created or not, I tested on xp and xp sp2.

to test this run it once which should create the mutex in memory(you can check with process exporer if you want) then run it again which it should tell you the mutex is already created and exits, but doesn't. Afterwards manually terminate this process since it loops in mem to keep mutex alive.

.686
.model flat, stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\kernel32.lib
include \masm32\include\user32.inc
includelib \masm32\lib\user32.lib

.data
TheStr db "themutext",0
Exists db "Mutex already exists",0
Creating db "Creating mutex",0
.code
start:
invoke CreateMutex,NULL,TRUE,addr TheStr
.if eax==NULL
invoke MessageBox,0,addr Exists,addr Exists,MB_ICONINFORMATION ;if fails assume it already exists
.else
invoke MessageBox,0,addr Creating,addr Creating,MB_ICONINFORMATION
@@:
invoke Sleep,2000
jmp @B
.endif
invoke ExitProcess,0
end start

evlncrn8

i usually use openmutex to check if the mutex is already created..
never encountered this issue though..
will check later on when i have some free time.. could be an interesting find :)

MichaelW

CreateMutex is supposed to return a handle if it succeeds, or null if it fails.

MSDN: CreateMutex
eschew obfuscation

hutch--

 :bg

>      I think I found a bug in windows

Our name is LEGION for we are many. (Bugs in Windows)  :bdg
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

ecube

Quote from: MichaelW on November 23, 2006, 07:48:45 AM
CreateMutex is supposed to return a handle if it succeeds, or null if it fails.

MSDN: CreateMutex


I know that, and it doesn't ever return NULL even during failure, that's the whole point of the test :)

MichaelW

I had forgotten about this detail. You would think that a function named CreateMutex would return failure if it failed to create the mutex object. But it actually returns the handle to the existing object, and sets LastError to ERROR_ALREADY_EXISTS.

.686
.model flat, stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\kernel32.lib
include \masm32\include\user32.inc
includelib \masm32\lib\user32.lib

.data
TheStr db "themutext",0
Error db "Error creating mutex",0
Exists db "Mutex already exists",0
Creating db "Creating mutex",0
.code
start:
invoke CreateMutex,NULL,TRUE,addr TheStr
.if eax==NULL
invoke MessageBox,0,addr Exists,addr Error,MB_ICONINFORMATION ;if fails assume it already exists
.else
      invoke GetLastError
      .if eax==ERROR_ALREADY_EXISTS
        invoke MessageBox,0,addr Exists,addr Exists,MB_ICONINFORMATION
      .else     
  invoke MessageBox,0,addr Creating,addr Creating,MB_ICONINFORMATION
      .endif 
@@:
invoke Sleep,2000
jmp @B
.endif
invoke ExitProcess,0
end start


eschew obfuscation