Discussion:
Access violation in InternetReadFileEx
(too old to reply)
Theo Carr-Brion
2006-04-13 08:19:08 UTC
Permalink
I am the following error:
Access violation at address 7C80979D in module 'kernel32.dll'. Write of
address 00000014.

It occurs in InterlockedDecrement called from InternetReadFileEx. I am doing
an asynchronous http post of a text file. The data is sucessfully sent but
it crashes reading the response. The error only occurs on a few computers
(all XP SP2) and I am unable to reproduce the problem here and it works
every time.

This is how I am calling the functions. I have left out all the error
checking and use of the call back function which all appears to be working.

lNetHandle:=InternetOpen('Application name', INTERNET_OPEN_TYPE_PRECONFIG,
nil, nil, INTERNET_FLAG_ASYNC);
if lNetHandle<>nil then
begin
InternetSetStatusCallback(lNetHandle, @InternetCallbackFunction);
gUrlHandle:=InternetConnect(lNetHandle, fUrlComponents.lpszHostName,
INTERNET_DEFAULT_HTTPS_PORT,
nil, nil, INTERNET_SERVICE_HTTP, 0,
HttpConnectContext);
gRequestHandle:=HttpOpenRequest(gUrlHandle, 'POST',
fUrlComponents.lpszUrlPath,
'HTTP/1.1', '', nil, INTERNET_FLAG_NO_CACHE_WRITE
or
INTERNET_FLAG_SECURE or INTERNET_FLAG_NO_UI or
INTERNET_FLAG_PRAGMA_NOCACHE, HttpRequestContext);
lHeader:='Content-Type: text/xml'+#13+#10;
HttpAddRequestHeaders(gRequestHandle, PChar(lHeader), Length(lHeader),
HTTP_ADDREQ_FLAG_ADD
or HTTP_ADDREQ_FLAG_REPLACE);
FillChar(fBufferIn, SizeOf(INTERNET_BUFFERS), 0);
fBufferIn.dwStructSize:=sizeof(INTERNET_BUFFERS);
fBufferIn.dwBufferTotal:=Length(aMessage);
HttpSendRequestEx(aRequestHandle, @fBufferIn, nil, 0,
HttpRequestContext)
repeat
InternetWriteFile(aRequestHandle, @fBuffer[1], K, lBytesWritten);
until AllGone;
repeat
FillChar(fBufferIn, SizeOf(INTERNET_BUFFERS), 0);
fBufferIn.dwStructSize:=SizeOf(INTERNET_BUFFERS);
fBufferIn.lpvBuffer:=@fBuffer[1];
fBufferIn.dwBufferLength:=1024;
if not InternetReadFileEx(gRequestHandle, @fBufferIn, IRF_ASYNC,
HttpRequestContext) then
lBytesRead:=fBufferIn.dwBufferLength;
if lBytesRead>0 then
//Save it
until lBytesRead=0;
InternetCloseHandle(gRequestHandle);
InternetCloseHandle(gUrlHandle);
InternetCloseHandle(lNetHandle);


Is anyone able to help?

Thank you

Theo Carr-Brion
Scherbina Vladimir
2006-04-13 13:20:41 UTC
Permalink
Hello Theo!

Did you tried to to check software installed on those machines where access
violation appears? Do those machines have LSP installed?FireWalls? It is
possible that LSP may produce access violations. If all seems to be ok with
software can you publish here code of your callback -
InternetCallbackFunction ?
--
Vladimir
manage content: http://www.infostoria.com/
blog: http://spaces.msn.com/vladimir-scherbina/
Theo Carr-Brion
2006-04-13 15:02:57 UTC
Permalink
Post by Scherbina Vladimir
Hello Theo!
Did you tried to to check software installed on those machines where
access violation appears? Do those machines have LSP installed?FireWalls?
It is possible that LSP may produce access violations. If all seems to be
ok with software can you publish here code of your callback -
InternetCallbackFunction ?
--
Vladimir
manage content: http://www.infostoria.com/
blog: http://spaces.msn.com/vladimir-scherbina/
Thank you for replying. I have asked one of the users if they have a
firewall but it may be a while before I get a reply. The callback function
is:

procedure InternetCallbackFunction(hInternet: HINTERNET;
dwContext: DWORD;
dwInternetStatus: DWORD;
lpvStatusInformation: PInternetAsyncResult;
dwStatusInformationLength: DWORD); stdcall;
begin
case dwContext of
HttpConnectContext:
case dwInternetStatus of
INTERNET_STATUS_HANDLE_CREATED:
begin
gUrlHandle:=Pointer(lpvStatusInformation^.dwResult);
end;
INTERNET_STATUS_REQUEST_COMPLETE:
begin
if lpvStatusInformation^.dwResult=0 then
gErrorNo:=lpvStatusInformation^.dwError;
gHttpDone:=True;
end;
end;
HttpRequestContext:
case dwInternetStatus of
INTERNET_STATUS_HANDLE_CREATED:
begin
gRequestHandle:=Pointer(lpvStatusInformation^.dwResult);
end;
INTERNET_STATUS_REQUEST_COMPLETE:
begin
if lpvStatusInformation^.dwResult=0 then
gErrorNo:=lpvStatusInformation^.dwError;
gHttpDone:=True;
end;
end;
end;
end;

All it does is set these global variables. The program waits until gHttpDone
is set.

Theo Carr-Brion
Scherbina Vladimir
2006-04-13 15:20:48 UTC
Permalink
Why are you writing to variable without syncronizing access to it? Any
critical section, InterlockedXxx function or other sync. item should be used
if you're dealing with multithreading. But this does not explains why the
access violation appears ...

As my knowledge of pascal shows all is ok in this callback, can the problem
be in stack or heap corruption in your application? Have you checked your
code "by hands" or using profiler?

As for LSP's - google for a tool that allows to get the list of LSPs - there
should be written such kind of software and ask your client to run it and
send you report. Or you can do that manually by writing some kind of
"support" tool that is able to gather neccessary system information (active
processes, registered extensions, lsps, etc) and send it to your research
center.
--
Vladimir
manage content: http://www.infostoria.com/
blog: http://spaces.msn.com/vladimir-scherbina/
Theo Carr-Brion
2006-04-13 15:10:28 UTC
Permalink
Post by Scherbina Vladimir
Hello Theo!
Did you tried to to check software installed on those machines where
access violation appears? Do those machines have LSP installed?FireWalls?
It is possible that LSP may produce access violations. If all seems to be
ok with software can you publish here code of your callback -
InternetCallbackFunction ?
--
Vladimir
manage content: http://www.infostoria.com/
blog: http://spaces.msn.com/vladimir-scherbina/
One user with the problem says they use a Proxy called Wavecrest cyblock sa.

Theo
Loading...