Modify

#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, on Jun 19, 2015 at 6:15:38 PM

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

comment:2 by wraithdu, on Jun 20, 2015 at 12:19:19 AM

Yep. My original version is in ticket #2263.

comment:3 by BrewManNH, on Jun 20, 2015 at 3:34:10 AM

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, on Jun 20, 2015 at 3:55:25 AM

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 Jpm, on Jun 20, 2015 at 12:34:17 PM

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

comment:6 by jchd18, on Jun 20, 2015 at 2:17:50 PM

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, on Jun 22, 2015 at 1:02:32 AM

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.

By the way, if @error is zero, then setting it to 10 means that the next If statement will fire, and it will incorrectly return from the function with an error message. If you wanted to correct for any possible non-zero error, then you should be checking for zero first, and then change its value.

Version 0, edited on Jun 22, 2015 at 1:02:32 AM by BrewManNH (next)

comment:8 by BrewManNH, on Jun 22, 2015 at 2:16:04 AM

Resolution: Fixed
Status: closedreopened

comment:9 by BrewManNH, on Jun 22, 2015 at 2:18:02 AM

Resolution: Fixed
Status: reopenedclosed

Fixed by revision [11327] in version: 3.3.13.21

comment:10 by Jpm, on Jun 22, 2015 at 7:15:41 AM

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

comment:11 by jchd18, on Jun 22, 2015 at 7:32:13 AM

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.