Code:
DWORD len=lpBuffers[0].len;
char *b=lpBuffers[0].buf;
char *temp=(char*)malloc(len+3); // this buffer is for string search
char *temp2=(char*)malloc(len+4);// this is for our new buffer
strncpy(temp,b,len);
temp[len]=0;
char *c;
c=strstr(temp,"test1.ru"); // search for TEST1.RU
if (c!=NULL) { // if found, then :
DWORD pos=c-temp;
strncpy(temp2,temp,pos);
strncpy(temp2+pos,"localhost",9); // replace it with localhost
strncpy(temp2+pos+9,temp+pos+8,len-pos-8);
lpBuffers[0].len=len+1; // replace len and buf fields of WSABUF
struct
lpBuffers[0].buf=temp2;
} else { // if the TEST1.RU not found,
strncpy(temp2,temp,len); // just copying temp to temp2
buf->len=len; // we could not doing all this, anyway
buf->buf=temp2;
}
Ret = NextProcTable.lpWSPSend(SocketContext->ProviderSocket,
lpBuffers, 1, // send our buffer beneath.....
lpNumberOfBytesSent, dwFlags, lpOverlapped,
lpCompletionRoutine,
lpThreadId, lpErrno);
if (Ret != SOCKET_ERROR)
{
LogBuffer(&lpBuffers[0]); // logging
}
Let's say, I have my IE or Opera work fine. But. When I try to navigate
to test1.ru (the string I have to replace in http header), I got a
crash (
Listen, even if I try to change test1.ru to the string with the same
length, I have everithing FINE!!!! As soon as I alloc string on 1 byte
longer than it was, I have a crash ! Maybe somewhere else the http
header length saves off ? Or what ? My opera does the same - crashes.
I have been experimening a lot and two days have gone on it, but
nothing helps. I tried to alloc my WSABUF struct, tried to change the
data that higher provider sends to my provider (it is bad, but I HAD TO
TRY !), no results. Please say me, what's I forgotten ? Maybe some code
...
> Let's say, I have my IE or Opera work fine. But. When I try to navigate
> to test1.ru (the string I have to replace in http header), I got a
> crash (
> Listen, even if I try to change test1.ru to the string with the same
> length, I have everithing FINE!!!! As soon as I alloc string on 1 byte
> longer than it was, I have a crash ! Maybe somewhere else the http
> header length saves off ? Or what ? My opera does the same - crashes.
> I have been experimening a lot and two days have gone on it, but
> nothing helps. I tried to alloc my WSABUF struct, tried to change the
> data that higher provider sends to my provider (it is bad, but I HAD TO
> TRY !), no results. Please say me, what's I forgotten ? Maybe some code
The bug is probably not in the code you pasted. The bug is likely in how
you handle the completion of the send. For example:
1) If you added two bytes to the header, you need to subtract two bytes
off from the completion. Otherwise the application will be told it sent more
bytes than it tried to send, which could definitely cause it to crash.
2) When do you release the memory you allocate? You need to keep it
around until the operation completes, not just until it initiates.
DS