Bug in ISAPI DLL
| From: | Bryan Surles | Date: | Tue, 03 Aug 1999 23:22:04 +0000 |
| Subject: | Bug in ISAPI DLL | ||
| References: | 1 | Groups: | php.version4 |
| Request: | Send a blank email to php-version4+get-3083@lists.php.net to get a copy of this message | ||
This is a bug in the code. The current implementation calls
GetServerVariable once, with a static string of length 1024. However,
if the length of the server variable's value is greater then 1024, the
function returns FALSE, and writes the correct size into 'dwLen'. The
GetServerVariable then needs to be called again, with a buffer of size
dwLen. Only then will you be able to get any size server variable
value.
Hopefully this memory is being freed somewhere. I don't have time to
hunt it down.
Also, I'm not sure how to submit patches to this group. Below is a
re-write of the sapi_getenv function. I've also attached a patch file
to this email. If there is more I can do, let me know.
Cheers!
-Bryan Surles
char *sapi_getenv(void *scid, char *string){
char staticBuf[1024];
char *var;
DWORD dwLen = 1024;
DWORD code;
LPEXTENSION_CONTROL_BLOCK lpEcb=scid;
if (!string)
return NULL;
var = staticBuf;
var[0] = '\0';
if (lpEcb->GetServerVariable(lpEcb->ConnID,string,var,&dwLen)!=TRUE)
{
if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
var = (char *)malloc(dwLen);
var[0] = '\0';
lpEcb->GetServerVariable(lpEcb->ConnID,string,var,&dwLen);
}
}
if (var == '\0')
return NULL;
if (dwLen == 0 || dwLen >1024)
return NULL;
else if (var == staticBuf)
return estrdup(var);
else
return var;
}
Kevin Gillespie wrote:
> Hi Everyone,
>
> I run Sambar Http / Proxy Server and want to use the php4isapi.dll
> but get a Dr. Watson error (NT 4.0 Wks) as well as this error in the
> servers isapi log
>
> [02/Aug/1999:10:59:11 -0500] php4isapi.dll: GetServerVariable
> 'HTTP_COOKIE' failed (INSUFFICIENT_BUFFER)
>
> I have this in my mapping.ini
>
> *.php = e:\php\php4isapi.dll
>
> and the dll loads fine but locks the ntserver.exe (Sambar's NT
> Service executable)
>
> Any ideas are welcome.
>
> T.I.A.
>
> Kevin Gillespie
> Internet HomeSteaders Network
>
> Visit....
> http://sambar.homesteaders.net
> For a Fantastic Freeware
> Http / Proxy Server
>
> Visit....
> http://free4all.homesteaders.net
> For Freeware Software
>
> --
> PHP 4 Beta