Re: [PHP4BETA] Bug in ISAPI DLL
| From: | Zeev Suraski | Date: | Wed, 04 Aug 1999 23:27:36 +0000 |
| Subject: | Re: [PHP4BETA] Bug in ISAPI DLL | ||
| References: | 1 | Groups: | php.version4 |
| Request: | Send a blank email to php-version4+get-3128@lists.php.net to get a copy of this message | ||
sapi_getenv() is actually an obsolete function (along with the rest of the code in the sapi directory) - the PHP 4.0 ISAPI module is in php4isapi.
I updated the module with that logic. Thanks!
Zeev
At 01:22 04/08/99 , Bryan Surles wrote:
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){-- Zeev Suraski <zeev@zend.com> http://www.zend.com/ For a PGP public key, finger bourbon@netvision.net.ilchar 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>http://sambar.homesteaders.net For a Fantastic Freeware Http / Proxy Server Visit.... <http://free4all.homesteaders.net>http://free4all.homesteaders.net For Freeware Software -- PHP 4 Beta35,60c35,47< 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; < } else if (var == staticBuf) { < return estrdup(var); < } else { < return var; < }---char var[1024]; DWORD dwLen; LPEXTENSION_CONTROL_BLOCK lpEcb=scid;if (!string) return NULL;dwLen=lpEcb->GetServerVariable(lpEcb->ConnID,string,var,&dwLen);if (dwLen == 0 || dwLen >1024) return NULL; else return estrdup(var);-- PHP 4 Beta