cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: curl send wrong data ?

From: Dan Fandrich <dan_at_coneharvesters.com>
Date: Fri, 4 Jun 2004 09:37:07 -0700

On Fri, Jun 04, 2004 at 03:04:33PM +0200, Daniel Stenberg wrote:
> On Fri, 4 Jun 2004, Blaz Smolnikar wrote:
>
> ...
>
> > char *str;
>
> ...
>
> > char* url = malloc((strlen(url) + strlen(str), sizeof(char)));
>
> What is this line supposed to do? url isn't assigned, str isn't assigned,
> sizeof(char) is 1. What are you allocating _really_ ?

This uses the comma as the sequential-evaluation operator, so the result is
effectively malloc(sizeof(char)). The buffer is then immediately overflowed
by the contents of the url. The next malloc then overwrites the url.

>
> > sprintf(url,
> > "planet-si.net/addsong.php?action=add&art=%s&tit=test&time=2:21&kbps=320",str);
>
> ... and if you make sure you output the URL after this, and then compare it
> with what URL libcurl used, I bet you'll see that they are the same.
>
> I'd recommend you to think through your program again, and check return codes
> for errors etc.

>>> Dan

-- 
http://www.MoveAnnouncer.com              The web change of address service
          Let webmasters know that your web site has moved
Received on 2004-06-04