Re: [twsocket] EAccessViolations when Posting Data to a HTTPServer
Dod wrote: > You said "disabled", one thing I learned by experience about FWs and > AVs is that they are never 100% "disabled", you MUST uninstall them to > be sure they are not causing the problem because disabling keep low > level drivers loaded. That's my experience as well and the only reliable method. If they used user mode hooking one could also check the list of libraries loaded either in debugger event log or by Sysinternal's Process Explorer. In the sample below there is a suspicious SSSensor.dll which is injected into each process by an old version of Sygate Personal Firewall. Those injected DLLs may hook the API calls they are interested in. They could be injected by many different applications including a virus or other stuff. If they are buggy it looks like a bug in your application :( Btw: The error might not happen with blocking winsock API since most internet applications use blocking winsock so they are more carefully tested. -- Arno Garrels Module Load: Project1.exe. Has Debug Info. Base Address: $0040. Process Project1.exe (640) Module Load: ntdll.dll. No Debug Info. Base Address: $7C91. Process Project1.exe (640) Module Load: KERNEL32.dll. No Debug Info. Base Address: $7C80. Process Project1.exe (640) Module Load: OLEAUT32.dll. No Debug Info. Base Address: $770F. Process Project1.exe (640) Module Load: ADVAPI32.dll. No Debug Info. Base Address: $77DA. Process Project1.exe (640) Module Load: RPCRT4.dll. No Debug Info. Base Address: $77E5. Process Project1.exe (640) Module Load: Secur32.dll. No Debug Info. Base Address: $77FC. Process Project1.exe (640) Module Load: GDI32.dll. No Debug Info. Base Address: $77EF. Process Project1.exe (640) Module Load: USER32.dll. No Debug Info. Base Address: $7E36. Process Project1.exe (640) Module Load: msvcrt.dll. No Debug Info. Base Address: $77BE. Process Project1.exe (640) Module Load: ole32.dll. No Debug Info. Base Address: $774B. Process Project1.exe (640) Module Load: VERSION.dll. No Debug Info. Base Address: $77BD. Process Project1.exe (640) Module Load: COMCTL32.dll. No Debug Info. Base Address: $773A. Process Project1.exe (640) Module Load: SHLWAPI.dll. No Debug Info. Base Address: $77F4. Process Project1.exe (640) Module Load: SHELL32.dll. No Debug Info. Base Address: $7E67. Process Project1.exe (640) Module Load: ShimEng.dll. No Debug Info. Base Address: $5CF0. Process Project1.exe (640) Module Load: IMM32.dll. No Debug Info. Base Address: $7633. Process Project1.exe (640) Module Load: LPK.dll. No Debug Info. Base Address: $62E1. Process Project1.exe (640) Module Load: USP10.dll. No Debug Info. Base Address: $7579. Process Project1.exe (640) Module Unload: ShimEng.dll. Process Project1.exe (640) Module Load: UxTheme.dll. No Debug Info. Base Address: $5B0F. Process Project1.exe (640) Module Load: MSCTF.dll. No Debug Info. Base Address: $746A. Process Project1.exe (640) Module Load: appHelp.dll. No Debug Info. Base Address: $77B1. Process Project1.exe (640) Module Load: msctfime.ime. No Debug Info. Base Address: $7525. Process Project1.exe (640) Module Load: SSSensor.dll. No Debug Info. Base Address: $061F. Process Project1.exe (640) -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] EAccessViolations when Posting Data to a HTTPServer
Hello Keith, You said "disabled", one thing I learned by experience about FWs and AVs is that they are never 100% "disabled", you MUST uninstall them to be sure they are not causing the problem because disabling keep low level drivers loaded. For catching exceptions you can simply use MadExcept (free) or EurekaLog (not free but more powerfull and reliable, test version block the EXE 30 days after compilation (or first run I don't remember) so it should be enought for your tests, and as a side effect it make your app "trial period"). regards. KW> I've disabled all Firewalls and anti-virus stuff without any change in the KW> apps behaviour. I even tried re-compiling the ICS library and also directly KW> linking the relevant Pascal units into my project all without any change to KW> the problem. I will now try to catch an exception on my development PC when KW> I dynamically allocate memory. This sometimes happens and I may be able to KW> trap an exception lower down in the ICS code with the debugger if I directly KW> link in the Pascal units. I may also install Windows 2000 Pro on to the EEE KW> Box target machine. KW> ... After this I'm probably out of ideas. It might be time to try the Indy KW> component to see what it does :( KW> Keith Willis. KW> -Original Message- KW> From: twsocket-boun...@elists.org [mailto:twsocket-boun...@elists.org] On KW> Behalf Of Arno Garrels KW> Sent: Monday, 2 February 2009 3:43 AM KW> To: ICS support mailing KW> Subject: Re: [twsocket] EAccessViolations when Posting Data to a HTTPServer KW> Keith Willis wrote: >> Well I tried "malloc" and "free" without any joy. I have however been >> able to ascertain that its crashing in the call to "Receive". >> >> More significantly its only crashing on my target machine, (an ASUS >> EEE Box B202 running Windows XP Home). I can't seem to crash it on my >> development PC, (A generic Pentium desktop running Windows 2000 Pro). >> >> Is there some difference between the Winsock library in Windows XP >> Home and Windows 2000 Pro? KW> The sample I posted previously to the list runs without problem on both XP KW> Home and Pro. Is there any security software installed, like a personal KW> firewall, anti-virus software etc.? If so, first try to disable it, if that KW> doesn't help, remove it. KW> -- KW> Arno Garrels KW> -- KW> To unsubscribe or change your settings for TWSocket mailing list KW> please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket KW> Visit our website at http://www.overbyte.be KW> Internal Virus Database is out of date. KW> Checked by AVG - http://www.avg.com KW> Version: 8.0.173 / Virus Database: 270.7.6/1715 - Release Date: 10/8/2008 KW> 7:19 PM -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] EAccessViolations when Posting Data to a HTTPServer
Hi, do you know about madExcept? That helps a lot in catching the source of exceptions. -- From: "Keith Willis" Sent: Wednesday, February 04, 2009 14:37 To: "'ICS support mailing'" Subject: Re: [twsocket] EAccessViolations when Posting Data to a HTTPServer > I've disabled all Firewalls and anti-virus stuff without any change in the > apps behaviour. I even tried re-compiling the ICS library and also > directly > linking the relevant Pascal units into my project all without any change > to > the problem. I will now try to catch an exception on my development PC > when > I dynamically allocate memory. This sometimes happens and I may be able to > trap an exception lower down in the ICS code with the debugger if I > directly > link in the Pascal units. I may also install Windows 2000 Pro on to the > EEE > Box target machine. > > ... After this I'm probably out of ideas. It might be time to try the Indy > component to see what it does :( > > Keith Willis. > > > > -Original Message- > From: twsocket-boun...@elists.org [mailto:twsocket-boun...@elists.org] On > Behalf Of Arno Garrels > Sent: Monday, 2 February 2009 3:43 AM > To: ICS support mailing > Subject: Re: [twsocket] EAccessViolations when Posting Data to a > HTTPServer > > Keith Willis wrote: >> Well I tried "malloc" and "free" without any joy. I have however been >> able to ascertain that its crashing in the call to "Receive". >> >> More significantly its only crashing on my target machine, (an ASUS >> EEE Box B202 running Windows XP Home). I can't seem to crash it on my >> development PC, (A generic Pentium desktop running Windows 2000 Pro). >> >> Is there some difference between the Winsock library in Windows XP >> Home and Windows 2000 Pro? > > The sample I posted previously to the list runs without problem on both XP > Home and Pro. Is there any security software installed, like a personal > firewall, anti-virus software etc.? If so, first try to disable it, if > that > doesn't help, remove it. > > > -- > Arno Garrels > -- > To unsubscribe or change your settings for TWSocket mailing list > please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket > Visit our website at http://www.overbyte.be > Internal Virus Database is out of date. > Checked by AVG - http://www.avg.com > Version: 8.0.173 / Virus Database: 270.7.6/1715 - Release Date: 10/8/2008 > 7:19 PM > > -- > To unsubscribe or change your settings for TWSocket mailing list > please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket > Visit our website at http://www.overbyte.be -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] EAccessViolations when Posting Data to a HTTPServer
I've disabled all Firewalls and anti-virus stuff without any change in the apps behaviour. I even tried re-compiling the ICS library and also directly linking the relevant Pascal units into my project all without any change to the problem. I will now try to catch an exception on my development PC when I dynamically allocate memory. This sometimes happens and I may be able to trap an exception lower down in the ICS code with the debugger if I directly link in the Pascal units. I may also install Windows 2000 Pro on to the EEE Box target machine. ... After this I'm probably out of ideas. It might be time to try the Indy component to see what it does :( Keith Willis. -Original Message- From: twsocket-boun...@elists.org [mailto:twsocket-boun...@elists.org] On Behalf Of Arno Garrels Sent: Monday, 2 February 2009 3:43 AM To: ICS support mailing Subject: Re: [twsocket] EAccessViolations when Posting Data to a HTTPServer Keith Willis wrote: > Well I tried "malloc" and "free" without any joy. I have however been > able to ascertain that its crashing in the call to "Receive". > > More significantly its only crashing on my target machine, (an ASUS > EEE Box B202 running Windows XP Home). I can't seem to crash it on my > development PC, (A generic Pentium desktop running Windows 2000 Pro). > > Is there some difference between the Winsock library in Windows XP > Home and Windows 2000 Pro? The sample I posted previously to the list runs without problem on both XP Home and Pro. Is there any security software installed, like a personal firewall, anti-virus software etc.? If so, first try to disable it, if that doesn't help, remove it. -- Arno Garrels -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be Internal Virus Database is out of date. Checked by AVG - http://www.avg.com Version: 8.0.173 / Virus Database: 270.7.6/1715 - Release Date: 10/8/2008 7:19 PM -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] EAccessViolations when Posting Data to a HTTPServer
Keith Willis wrote: > Well I tried "malloc" and "free" without any joy. I have however been > able to ascertain that its crashing in the call to "Receive". > > More significantly its only crashing on my target machine, (an ASUS > EEE Box B202 running Windows XP Home). I can't seem to crash it on my > development PC, (A generic Pentium desktop running Windows 2000 Pro). > > Is there some difference between the Winsock library in Windows XP > Home and Windows 2000 Pro? The sample I posted previously to the list runs without problem on both XP Home and Pro. Is there any security software installed, like a personal firewall, anti-virus software etc.? If so, first try to disable it, if that doesn't help, remove it. -- Arno Garrels -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] EAccessViolations when Posting Data to a HTTPServer
Well I tried "malloc" and "free" without any joy. I have however been able to ascertain that its crashing in the call to "Receive". More significantly its only crashing on my target machine, (an ASUS EEE Box B202 running Windows XP Home). I can't seem to crash it on my development PC, (A generic Pentium desktop running Windows 2000 Pro). Is there some difference between the Winsock library in Windows XP Home and Windows 2000 Pro? I will try some other PC's as well for reference. Keith. -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] EAccessViolations when Posting Data to a HTTPServer
In C/C++ if you declare Junk statically eg: "char Junk[1024];", Junk is of type "char*" so the &Junk will be of type "char**". -Original Message- From: twsocket-boun...@elists.org [mailto:twsocket-boun...@elists.org] On Behalf Of Arno Garrels Sent: Sunday, 1 February 2009 3:55 AM To: ICS support mailing Subject: Re: [twsocket] EAccessViolations when Posting Data to a HTTPServer Keith Willis wrote: > Just confirming that you meant to write: > > ClientCnx->Receive(Junk, sizeof(Junk)); > > Instead of: > > ClientCnx->Receive(&Junk, sizeof(Junk)); I don't think so, I meant the address of Junk which is the address of the first element of the static array, isn't it? Same as ClientCnx->Receive(&Junk[0], sizeof(Junk)); In Delphi you MUST write it that way. Seems like CB has some built-in compiler magic so that ClientCnx->Receive(Junk, sizeof(Junk)); works as well (I used C++Builder 2007 and ICS v7). -- Arno Garrels -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be Internal Virus Database is out of date. Checked by AVG - http://www.avg.com Version: 8.0.173 / Virus Database: 270.7.6/1715 - Release Date: 10/8/2008 7:19 PM -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] EAccessViolations when Posting Data to a HTTPServer
Keith Willis wrote: > Just confirming that you meant to write: > > ClientCnx->Receive(Junk, sizeof(Junk)); > > Instead of: > > ClientCnx->Receive(&Junk, sizeof(Junk)); I don't think so, I meant the address of Junk which is the address of the first element of the static array, isn't it? Same as ClientCnx->Receive(&Junk[0], sizeof(Junk)); In Delphi you MUST write it that way. Seems like CB has some built-in compiler magic so that ClientCnx->Receive(Junk, sizeof(Junk)); works as well (I used C++Builder 2007 and ICS v7). -- Arno Garrels -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] EAccessViolations when Posting Data to a HTTPServer
Arno, No luck I'm afraid... I'm still getting those AV's :( Keith. Here's my current code... As per your suggested code. I also made the TMemoryManager global to the application. I will try free and malloc next. <<< CODE SNIPPETS >>> //-- - class TMyHttpConnection : public THttpConnection { public: char *PostedDataBuffer; // Will hold dynamically allocated buffer int PostedDataSize;// Databuffer size int RcvdByteCount; // Keep track of received byte count. public: __fastcall TMyHttpConnection(Classes::TComponent* AOwner); virtual __fastcall ~TMyHttpConnection(); }; //-- - //-- - __fastcall TMyHttpConnection::TMyHttpConnection(Classes::TComponent* AOwner) : THttpConnection(AOwner) { try { PostedDataBuffer = NULL; PostedDataSize = 0; } catch(...) {} } //-- - __fastcall TMyHttpConnection::~TMyHttpConnection() { try { if (PostedDataBuffer != NULL) { if (MemoryManager->FreeMem(PostedDataBuffer) == 0) { PostedDataBuffer = NULL; PostedDataSize = 0; } } } catch(...) {} } //-- - //-- - void __fastcall TAegisWebServerForm::HttpServerPostDocument(TObject *Sender, TObject *Client, THttpGetFlag &Flags) { try { TMyHttpConnection* Connection = (TMyHttpConnection*)Client; FCountRequests++; // Count request and display a message if (CompareText(Connection->Path, "/content/home.html") == 0)// This page is not cached { Flags = hgAcceptData; Connection->LineMode = false; if (Connection->PostedDataSize < Connection->RequestContentLength + 1) { if (Connection->PostedDataBuffer != NULL) {if (MemoryManager->FreeMem(Connection->PostedDataBuffer) != 0) throw Exception("Unable to free memory for Posted Data Buffer");} Connection->PostedDataSize = 0; Connection->PostedDataBuffer = (char*)(MemoryManager->GetMem(Connection->RequestContentLength + 1)); if (Connection->PostedDataBuffer == NULL) throw Exception("Unable to allocate memory for Posted Data Buffer"); Connection->PostedDataSize = Connection->RequestContentLength + 1; } Connection->RcvdByteCount = 0; } else Flags = hg404; } catch (Exception &E) {HandleError("TAegisWebServerForm::HttpServerPostDocument", E.Message);} catch (const exception &e) {HandleError("TAegisWebServerForm::HttpServerPostDocument", e.what());} catch (...) {HandleError("TAegisWebServerForm::HttpServerPostDocument", "Unknown Exception");} } //-- - void __fastcall TAegisWebServerForm::HttpServerPostedData(TObject *Sender, TObject *Client, WORD Error) { try { int Len, Remains; char Junk[1024]; TMyHttpConnection* Connection = (TMyHttpConnection*)Client; Remains = Connection->RequestContentLength - Connection->RcvdByteCount; if (Remains <= 0) { Connection->Receive(Junk, sizeof(Junk)); return; } Len = Connection->Receive(&(Connection->PostedDataBuffer[Connection->RcvdByteCount ]), Remains); if (Len <= 0) return; Connection->RcvdByteCount += Len; if (Connection->RcvdByteCount > Connection->RequestContentLength) Connection->RcvdByteCount = Connection->RequestContentLength; if (Connection->RcvdByteCount == Connection->RequestContentLength) { Connection->PostedDataReceived(); Connection->PostedDataBuffer[Connection->RcvdByteCount] = 0; ProcessPostedData(Connection); } } catch (Exception &E) {HandleError("TAegisWebServerForm::HttpServerPostedData", E.Message);} catch (const exception &e) {HandleError("TAegisWebServerForm::HttpServerPostedData", e.what());} catch (...) {HandleError("TAegisWebServerForm::HttpServerPostedData", "Unknown Exception");} } //-- - -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] EAccessViolations when Posting Data to a HTTPServer
Hi Arno, Just confirming that you meant to write: ClientCnx->Receive(Junk, sizeof(Junk)); Instead of: ClientCnx->Receive(&Junk, sizeof(Junk)); Cheers, Keith. -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] EAccessViolations when Posting Data to a HTTPServer
Keith Willis wrote: > Hi Arno, > >> You never check PostedDataSize, the size of your receive buffer. >> The pascal demo allocates this buffer dynamically depending on the > RequestContentLength plus one byte for the null terminator in the > OnPostDocument event handler. >> What is the value of RcvdByteCount when the error happens? > > > I originally did it like that, but it kept crashing with AV's so I > embarked on a process of elimination of suspect code until I ended up > with an (almost) stable version where PostedDataBuffer was > statically allocated in the class declaration. It's probably stable unless posted data size exceeds receive buffer size. Also the MemoryManager should be instantiated once (on application start), and memory allocated by the MemoryManager should be freed by the manager. In my sample below I use malloc and free (stdlib.h) which is most likely slower than proper use of MemoryManager. {code} class TMyHttpConnection : public THttpConnection { public: char *PostedDataBuffer; // Will hold dynamically allocated buffer int PostedDataSize;// Databuffer size int DataLen; // Keep track of received byte count. public: virtual __fastcall ~TMyHttpConnection(); }; //--- // We need to override parent class destructor because we have allocated // memory for our data buffer. __fastcall TMyHttpConnection::~TMyHttpConnection() { if (PostedDataBuffer != NULL) { free(PostedDataBuffer); PostedDataBuffer = NULL; } } //--- [..] void __fastcall TWebServForm::HttpServer1PostDocument( TObject *Sender, TObject *Client, THttpGetFlag &Flags) { TMyHttpConnection* ClientCnx = (TMyHttpConnection*)Client; // We only accept data for '/post.bin' if (CompareText(ClientCnx->Path, "/post.bin") == 0) { // Tell HTTP server that we will accept posted data // OnPostedData event will be triggered when data comes in Flags = hgAcceptData; // We want to receive any data type. So we turn line mode off ClientCnx->LineMode = false; // We need a buffer to store posted data. We allocate as much as the // size of posted data plus one byte for the terminating nul char // since we expect just a few bytes posted in this sample. // We should also check for ContentLength = 0 and handle this case... if (ClientCnx->PostedDataSize < ClientCnx->RequestContentLength + 1) { if (ClientCnx->PostedDataBuffer) free(ClientCnx->PostedDataBuffer); ClientCnx->PostedDataBuffer = (char*)malloc(ClientCnx->RequestContentLength + 1); if (ClientCnx->PostedDataBuffer) ClientCnx->PostedDataSize = ClientCnx->RequestContentLength + 1; else { ClientCnx->PostedDataSize = 0; // ERROR! } } // Clear received length ClientCnx->DataLen = 0; } else Flags = hg404; } //--- void __fastcall TWebServForm::HttpServer1PostedData( TObject *Sender, TObject *Client, WORD Error) { int Len, Remains; char Junk [1024]; THttpGetFlag Dummy = hgSendDoc; TMyHttpConnection* ClientCnx = (TMyHttpConnection*)Client; Remains = ClientCnx->RequestContentLength - ClientCnx->DataLen; // We MUST receive any data and throw away the garbage! if (Remains <= 0) { ClientCnx->Receive(&Junk, sizeof(Junk)); return; } Len = ClientCnx->Receive(&ClientCnx->PostedDataBuffer[ClientCnx->DataLen], Remains); if (Len <= 0) return; ClientCnx->DataLen += Len; // Everything received? If true, let's process the stuff if (ClientCnx->DataLen == ClientCnx->RequestContentLength) { // First we must tell the component that we've got all the data ClientCnx->PostedDataReceived(); // Do something with the received data, here we just display, we expect // just short text data in this demo! ClientCnx->PostedDataBuffer[ClientCnx->DataLen] = 0; Display(ClientCnx->PostedDataBuffer); // Send the response ClientCnx->AnswerString(Dummy, "", // Default Status '200 OK' "", // Default Content-Type: text/html "", // Default header "" "ICS WebServer POST Demo" "" "Your data has been recorded" "\r\n"); } } //--- {code} -- Arno Garrels -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] EAccessViolations when Posting Data to a HTTPServer
Hi Arno, > You never check PostedDataSize, the size of your receive buffer. > The pascal demo allocates this buffer dynamically depending on the RequestContentLength plus one byte for the null terminator in the OnPostDocument event handler. > What is the value of RcvdByteCount when the error happens? I originally did it like that, but it kept crashing with AV's so I embarked on a process of elimination of suspect code until I ended up with an (almost) stable version where PostedDataBuffer was statically allocated in the class declaration. The version I released in my original posting in this mailing list was the penultimate iteration where I was still dynamically allocating memory, but only once in TMyHttpConnection's constructor. This drastically simplified version still generates AV's so I thought it would be more relevant to the discussion. My original code is included below for reference: << CODE SNIPPETS >>> //-- - class TMyHttpConnection : public THttpConnection { public: char* Junk; char* PostedDataBuffer; // Will hold dynamically allocated buffer int PostedDataSize;// Databuffer size int RcvdByteCount; // Keep track of received byte count. public: __fastcall TMyHttpConnection(Classes::TComponent* AOwner); virtual __fastcall ~TMyHttpConnection(); }; //-- - //-- - __fastcall TMyHttpConnection::TMyHttpConnection(Classes::TComponent* AOwner) : THttpConnection(AOwner) { try { Junk = new char(65536); PostedDataBuffer = NULL; PostedDataSize = 0; } catch(...) {} } //-- - __fastcall TMyHttpConnection::~TMyHttpConnection() { try { delete [] Junk; if (PostedDataBuffer != NULL) { delete [] PostedDataBuffer; PostedDataBuffer = NULL; PostedDataSize = 0; } } catch(...) {} } //-- - void __fastcall TAegisWebServerForm::HttpServerPostDocument(TObject *Sender, TObject *Client, THttpGetFlag &Flags) { try { TMyHttpConnection* Connection = (TMyHttpConnection*)Client; FCountRequests++; // Count request and display a message if (CompareText(Connection->Path, "/content/home.html") == 0)// This page is not cached { Flags = hgAcceptData; Connection->LineMode = false; TMemoryManager* MemoryManager = new TMemoryManager(); try { GetMemoryManager(*MemoryManager); if (Connection->PostedDataSize == 0) { Connection->PostedDataSize = Connection->RequestContentLength + 1; Connection->PostedDataBuffer = (char*)(MemoryManager->GetMem(Connection->PostedDataSize)); } else { Connection->PostedDataSize = Connection->RequestContentLength + 1; Connection->PostedDataBuffer = (char*)(MemoryManager->ReallocMem(Connection->PostedDataBuffer, Connection->PostedDataSize)); } } __finally {delete MemoryManager;} Connection->RcvdByteCount = 0; } } catch (Exception &E) {HandleError("TAegisWebServerForm::HttpServerPostDocument", E.Message);} catch (const exception &e) {HandleError("TAegisWebServerForm::HttpServerPostDocument", e.what());} catch (...) {HandleError("TAegisWebServerForm::HttpServerPostDocument", "Unknown Exception");} } //-- - void __fastcall TAegisWebServerForm::HttpServerPostedData(TObject *Sender, TObject *Client, WORD Error) { try { int Len, Remains; TMyHttpConnection* Connection = (TMyHttpConnection*)Client; Remains = Connection->RequestContentLength - Connection->RcvdByteCount; if (Remains <= 0) { Len = Connection->Receive(Connection->Junk, sizeof(Connection->Junk)- 1); if (Len >= 0) Connection->Junk[Len] = 0; return; } // Len = Connection->Receive(Connection->PostedDataBuffer + Connection->RcvdByteCount, Remains); Len = Connection->Receive(&(Connection->PostedDataBuffer[Connection->RcvdByteCount ]), Remains); if (Len <= 0) return; Connection->RcvdByteCount += Len; if (Connection->RcvdByteCount > Connection->RequestContentLength) Connection->RcvdByteCount = Connection->RequestContentLength; if (Connection->RcvdByteCount == Connection->RequestContentLength) { Connection->PostedDataBuffer[Connection->RcvdByteCount] = 0; if (CompareText(Connection->Path, "/content/home.html") == 0) ProcessPostedData(Connection); // else Connection->Answer404(); // I need to make Answer404 accessible else { AnsiString Body = AnsiString("404 Not Found404 Not FoundThe requested URL ") + TextToHtmlText(Connection->Path) + " was not found on this server.\r\n"; Connection->SendHeader(Connection->Version + " 404 Not Found\r\nContent-Type: text/html\r\nContent-Length: " + Utili
Re: [twsocket] EAccessViolations when Posting Data to a HTTPServer
Keith Willis wrote: > I have managed to improve the code reliability by not dynamically > allocating the PostedDataBuffer at all, (but this is not an > acceptable solution). In the code snippets below I pre-allocate once > in the constructor but this still generates AV's. You never check PostedDataSize, the size of your receive buffer. The pascal demo allocates this buffer dynamically depending on the RequestContentLength plus one byte for the null terminator in the OnPostDocument event handler. What is the value of RcvdByteCount when the error happens? -- Arno Garrels -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
[twsocket] EAccessViolations when Posting Data to a HTTPServer
Dear All, I have recently written a small Web Server application using the THttpServer component in ICS 5 with C++ Builder 5. It serves GET requests perfectly, but when I added POST functionality, (following the WebServ example) it has started generating EAccessViolations. CodeGuard reports that these are due to my PostedDataBuffer having only a 1 byte heap length when I am writing the NULL string termination character in the "HttpServerPostedData" event handler. I have managed to improve the code reliability by not dynamically allocating the PostedDataBuffer at all, (but this is not an acceptable solution). In the code snippets below I pre-allocate once in the constructor but this still generates AV's. Can anyone shed some light on what might be happening here? Regards, Keith Willis. <<< CODE SNIPPETS >>> //-- - class TMyHttpConnection : public THttpConnection { public: char* Junk; char *PostedDataBuffer; // Will hold dynamically allocated buffer int PostedDataSize;// Databuffer size int RcvdByteCount; // Keep track of received byte count. public: __fastcall TMyHttpConnection(Classes::TComponent* AOwner); virtual __fastcall ~TMyHttpConnection(); }; //-- - //-- - __fastcall TMyHttpConnection::TMyHttpConnection(Classes::TComponent* AOwner) : THttpConnection(AOwner) { try { Junk = new char(65536); PostedDataBuffer = new char(65536); // Pre-allocate here in a desperate attempt to avoid EAccessViolations PostedDataSize = 65536; } catch(...) {} } //-- - __fastcall TMyHttpConnection::~TMyHttpConnection() { try { delete [] Junk; delete [] PostedDataBuffer; PostedDataBuffer = NULL; PostedDataSize = 0; } catch(...) {} } //-- - //-- - void __fastcall TAegisWebServerForm::HttpServerPostedData(TObject *Sender, TObject *Client, WORD Error) { try { int Len, Remains; TMyHttpConnection* Connection = (TMyHttpConnection*)Client; Remains = Connection->RequestContentLength - Connection->RcvdByteCount; if (Remains <= 0) { Len = Connection->Receive(Connection->Junk, sizeof(Connection->Junk)- 1); if (Len >= 0) Connection->Junk[Len] = 0; return; } // Len = Connection->Receive(Connection->PostedDataBuffer + Connection->RcvdByteCount, Remains); Len = Connection->Receive(&(Connection->PostedDataBuffer[Connection->RcvdByteCount ]), Remains); if (Len <= 0) return; Connection->RcvdByteCount += Len; if (Connection->RcvdByteCount > Connection->RequestContentLength) Connection->RcvdByteCount = Connection->RequestContentLength; if (Connection->RcvdByteCount == Connection->RequestContentLength) { Connection->PostedDataBuffer[Connection->RcvdByteCount] = 0; // <= CRASHES HERE! CodeGuard reports that the Heap length of is only 1 byte at this point??? if (CompareText(Connection->Path, "/content/home.html") == 0) ProcessPostedData(Connection); // else Connection->Answer404(); // I need to make Answer404 accessible else { AnsiString Body = AnsiString("404 Not Found404 Not FoundThe requested URL ") + TextToHtmlText(Connection->Path) + " was not found on this server.\r\n"; Connection->SendHeader(Connection->Version + " 404 Not Found\r\nContent-Type: text/html\r\nContent-Length: " + Utility->IntToStrEx(Body.Length()) + "\r\n\r\n"); Connection->SendStr(Body); } Connection->PostedDataReceived(); } } catch (Exception &E) {HandleError("TAegisWebServerForm::HttpServerPostedData", E.Message);} catch (const exception &e) {HandleError("TAegisWebServerForm::HttpServerPostedData", e.what());} catch (...) {HandleError("TAegisWebServerForm::HttpServerPostedData", "Unknown Exception");} } //-- - -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be