Modify

Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#3054 closed Bug (Fixed)

_Crypt_GenRandom always returns False and sets @error

Reported by: wraithdu Owned by: BrewManNH
Milestone: 3.3.13.21 Component: Standard UDFs
Version: 3.3.13.20 Severity: None
Keywords: _crypt_genrandom Cc:

Description

The function sets $iError = @error + 10 without checking @error. Further, I see no documentation or reason for @error + 10 at all.

Func _Crypt_GenRandom($pBuffer, $iSize)
	_Crypt_Startup()
	Local $aRet = DllCall(__Crypt_DllHandle(), "bool", "CryptGenRandom", "handle", __Crypt_Context(), "dword", $iSize, "struct*", $pBuffer)
	Local $iError = @error + 10, $iExtended = @extended
	_Crypt_Shutdown()
	If $iError Or (Not $aRet[0]) Then
		Return SetError($iError, $iExtended, False)
	Else
		Return True
	EndIf
EndFunc   ;==>_Crypt_GenRandom

Attachments (0)

Change History (11)

comment:1 by BrewManNH, 11 years ago

According to the header in the function, you wrote it, did someone change it after it was committed?

comment:2 by wraithdu, 11 years ago

Yep. My original version is in ticket #2263.

comment:3 by BrewManNH, 11 years ago

I found where it was changed in the repository. Not sure why it got changed the way it did, but easy enough to correct.

comment:4 by BrewManNH, 11 years ago

Milestone: 3.3.13.21
Owner: set to BrewManNH
Resolution: Fixed
Status: newclosed

Fixed by revision [11324] in version: 3.3.13.21

comment:5 by J-Paul Mesnage, 11 years ago

In fact the + 10 if the $aRet[0] is non zero to insure the setting of a non zeror @error

comment:6 by jchd18, 11 years ago

In every function in Crypt.au3 error return values are offset by distinct constant values; I guess it's to help locate where the error popped from.

comment:7 by BrewManNH, 11 years ago

That doesn't explain why it is set that way, or when it was changed, or where it was documented. If you make a change like this, it needs to be documented.

Where 10 is being added to the @error value is definitely a bug. If you wanted to return a non-zero value for the $aRet[0] being 0 then you should be adding 10 to the $iError variable AFTER the If statement, not before it. The way it was rewritten guarantees that it will always return an error condition unless @error is -10.

Last edited 11 years ago by BrewManNH (previous) (diff)

comment:8 by BrewManNH, 11 years ago

Resolution: Fixed
Status: closedreopened

comment:9 by BrewManNH, 11 years ago

Resolution: Fixed
Status: reopenedclosed

Fixed by revision [11327] in version: 3.3.13.21

comment:10 by J-Paul Mesnage, 11 years ago

Thanks ,
You right checking only @error instead of $iError was the smallest correction

comment:11 by jchd18, 11 years ago

I never pretended it was the right way to handle errors and never said it wasn't a bug! And I never touched this code.

Modify Ticket

Action
as closed The owner will remain BrewManNH.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.