Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

LSP - changing outgoing data

34 views
Skip to first unread message

prog...@yandex.ru

unread,
Oct 15, 2005, 6:20:48 AM10/15/05
to
Hi !
I have to change the address test1.ru to localhost on all OUTGOING http
requests. That's the code (in WSPSend func):

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
...

David Schwartz

unread,
Oct 15, 2005, 1:22:15 PM10/15/05
to

<prog...@yandex.ru> wrote in message
news:1129371648.7...@g43g2000cwa.googlegroups.com...

> 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


prog...@yandex.ru

unread,
Oct 15, 2005, 8:25:57 PM10/15/05
to
Wow!
Man, I have never used USENET forums to find the answer, i had rather
preferred usual web forum on sites, but now I see I will never get in
web forums. I have been fooling around over that stupid LSP for a week,
and the same bug goes out and nobody have given me such a valueable
advice like you, David ! Thanx a lot !
Yes, the problem was in lpNumberOfBytesSent param - I did not correct
it and had a crash. Thanx again, very big respect!

0 new messages