www.digitalmars.com         C & C++   DMDScript  

c++.command-line - problems with sscanf : small example

reply C <dont respond.com> writes:
#include <stdio.h>

int main () {

         char* url =3D "http://www.google.com";
         char proto[4096];
         char path[4096];
         printf("%d\n",sscanf(url, "%64[^:]:%[^\n]",
                            proto,
                            path));

         puts(proto);
         puts(path);
}


Expected output is

2
http
//www.google.com

Actual output is one new line.

Thanks!
Charles





-- =

D Newsgroup.
Mar 20 2004
parent reply "Walter" <walter digitalmars.com> writes:
Thanks, I'll check it out. BTW, if that code appears in libcurl, it looks to
me like an exploitable buffer overflow problem.

"C" <dont respond.com> wrote in message news:opr46nwb0xehmtou localhost...
#include <stdio.h>

int main () {

         char* url = "http://www.google.com";
         char proto[4096];
         char path[4096];
         printf("%d\n",sscanf(url, "%64[^:]:%[^\n]",
                            proto,
                            path));

         puts(proto);
         puts(path);
}


Expected output is

2
http
//www.google.com

Actual output is one new line.

Thanks!
Charles





-- 
D Newsgroup.
Mar 21 2004
parent reply "Walter" <walter digitalmars.com> writes:
"Walter" <walter digitalmars.com> wrote in message
news:c3jkml$kti$1 digitaldaemon.com...
 Thanks, I'll check it out.
It is a bug in sscanf, fixed now.
Mar 21 2004
parent reply C <dont respond.com> writes:
 Thanks, I'll check it out. BTW, if that code appears in libcurl, it =
 looks to
 me like an exploitable buffer overflow problem.
Nah that was just a small example, they dynamically allocate space for = path.
 It is a bug in sscanf, fixed now.
Awesome! When can we download an update ? Thanks, C On Sun, 21 Mar 2004 01:20:07 -0800, Walter <walter digitalmars.com> wrot= e:
 "Walter" <walter digitalmars.com> wrote in message
 news:c3jkml$kti$1 digitaldaemon.com...
 Thanks, I'll check it out.
It is a bug in sscanf, fixed now.
-- = D Newsgroup.
Mar 21 2004
parent reply "Walter" <walter digitalmars.com> writes:
"C" <dont respond.com> wrote in message news:opr473cp0dehmtou localhost...
Awesome! When can we download an update ?
I don't want to do an update just for that, but I can email it to you.
Mar 21 2004
parent reply C <dont respond.com> writes:
Ok im at qbert atari-soldiers.com.  Preciate you ;).

C

On Sun, 21 Mar 2004 10:19:08 -0800, Walter <walter digitalmars.com> wrot=
e:

 "C" <dont respond.com> wrote in message =
 news:opr473cp0dehmtou localhost...
 Awesome! When can we download an update ?
I don't want to do an update just for that, but I can email it to you.=



-- =

D Newsgroup.
Mar 21 2004
parent reply C <dont respond.com> writes:
That got it :).  Libcurl for D now works on windows also.  I'd like to =

post the makefile to libcurl but currently the preprocessor is choking o=
n =

the CFINIT and CINIT macros with the errors

   CINIT(FILE, OBJECTPOINT, 1),
                            ^
../include\curl/curl.h(366) : Error: '}' expected
   CFINIT(NOTHING),        /********* the first one is unused **********=
**/
                ^
../include\curl/curl.h(899) : Error: '}' expected
   CFINIT(COPYNAME),
                 ^
../include\curl/curl.h(902) : Error: missing ',' between declaration of =

'CURLFO
M_' and 'COPYNAME'
         CURLformoption          option;
                                      ^
../include\curl/curl.h(930) : Error: ';' expected following declaration =
of =

stru
t member
CURLcode curl_easy_setopt(CURL *curl, CURLoption option, ...);
                                                ^
../include\curl/easy.h(30) : Error: ')' expected
Fatal error: too many errors
--- errorlevel 1


those are defined as

#ifdef CURL_ISOCPP
#define
#else

#define CFINIT(name) CURLFORM_/**/name
#endif

and


#ifdef CURL_ISOCPP
#define
e =

+ number
#else
#define CINIT(name,type,number) CURLOPT_/**/name =3D type + number
#endif


The same error message is generated wether CURL_ISOCPP is defined or not=
.  =

Its used like


typedef enum {
   /* This is the FILE * or void * the regular output should be written =
to. =

*/
   CINIT(FILE, OBJECTPOINT, 1),

   /* The full URL to get/put */
   CINIT(URL,  OBJECTPOINT, 2),

   /* Port number to connect to, if other than default. */
   CINIT(PORT, LONG, 3),

   /* Name of proxy to use. */
   CINIT(PROXY, OBJECTPOINT, 4),

   /* "name:password" to use when fetching. */
   CINIT(USERPWD, OBJECTPOINT, 5),

   /* "name:password" to use with proxy. */
   CINIT(PROXYUSERPWD, OBJECTPOINT, 6),

...

and


typedef enum {
   CFINIT(COPYNAME),
   CFINIT(PTRNAME),
   CFINIT(NAMELENGTH),
   CFINIT(COPYCONTENTS),
   CFINIT(PTRCONTENTS),
   CFINIT(CONTENTSLENGTH),
...



Thanks!
Charles


On Sun, 21 Mar 2004 12:44:18 -0800, C <dont respond.com> wrote:

 Ok im at qbert atari-soldiers.com.  Preciate you ;).

 C

 On Sun, 21 Mar 2004 10:19:08 -0800, Walter <walter digitalmars.com> =
 wrote:

 "C" <dont respond.com> wrote in message =
 news:opr473cp0dehmtou localhost...
 Awesome! When can we download an update ?
I don't want to do an update just for that, but I can email it to you=
.

-- = D Newsgroup.
Mar 23 2004
parent reply "Walter" <walter digitalmars.com> writes:
I attempted to reconstruct your code, filling in missing stuff, into the
following file which compiles successfully. (This is why I am so adamant
about, when posting bug reports, please leave nothing to my imagination!
There's always something critical left out.)
---------------------------------------------------------------

#define CURLOPTTYPE_OBJECTPOINT 1
#define CURLOPTTYPE_LONG 2

#define CURL_ISOCPP 1

#ifdef CURL_ISOCPP
#define
#else

#define CFINIT(name) CURLFORM_/**/name
#endif

#ifdef CURL_ISOCPP
#define
number
#else
#define CINIT(name,type,number) CURLOPT_/**/name = type + number
#endif


typedef enum {
   /* This is the FILE * or void * the regular output should be written to.
*/
   CINIT(FILE, OBJECTPOINT, 1),

   /* The full URL to get/put */
   CINIT(URL,  OBJECTPOINT, 2),

   /* Port number to connect to, if other than default. */
   CINIT(PORT, LONG, 3),

   /* Name of proxy to use. */
   CINIT(PROXY, OBJECTPOINT, 4),

   /* "name:password" to use when fetching. */
   CINIT(USERPWD, OBJECTPOINT, 5),

   /* "name:password" to use with proxy. */
   CINIT(PROXYUSERPWD, OBJECTPOINT, 6),

} y;


typedef enum {
   CFINIT(COPYNAME),
   CFINIT(PTRNAME),
   CFINIT(NAMELENGTH),
   CFINIT(COPYCONTENTS),
   CFINIT(PTRCONTENTS),
   CFINIT(CONTENTSLENGTH),
} x;
Mar 23 2004
parent C <dont respond.com> writes:
Ugh, your right CURL_ISOCPP was getting undefined somewhere else :(.  =

Sorry!  Thanks for the time , libcurl is invaluable to me, so I =

appreciated your attention on all of this.

Thanks as usual,
Charlie

On Tue, 23 Mar 2004 23:56:38 -0800, Walter <walter digitalmars.com> wrot=
e:

 I attempted to reconstruct your code, filling in missing stuff, into t=
he
 following file which compiles successfully. (This is why I am so adama=
nt
 about, when posting bug reports, please leave nothing to my imaginatio=
n!
 There's always something critical left out.)
 ---------------------------------------------------------------

 #define CURLOPTTYPE_OBJECTPOINT 1
 #define CURLOPTTYPE_LONG 2

 #define CURL_ISOCPP 1

 #ifdef CURL_ISOCPP
 #define
 #else

 #define CFINIT(name) CURLFORM_/**/name
 #endif

 #ifdef CURL_ISOCPP
 #define
ype +
 number
 #else
 #define CINIT(name,type,number) CURLOPT_/**/name =3D type + number
 #endif


 typedef enum {
    /* This is the FILE * or void * the regular output should be writte=
n =
 to.
 */
    CINIT(FILE, OBJECTPOINT, 1),

    /* The full URL to get/put */
    CINIT(URL,  OBJECTPOINT, 2),

    /* Port number to connect to, if other than default. */
    CINIT(PORT, LONG, 3),

    /* Name of proxy to use. */
    CINIT(PROXY, OBJECTPOINT, 4),

    /* "name:password" to use when fetching. */
    CINIT(USERPWD, OBJECTPOINT, 5),

    /* "name:password" to use with proxy. */
    CINIT(PROXYUSERPWD, OBJECTPOINT, 6),

 } y;


 typedef enum {
    CFINIT(COPYNAME),
    CFINIT(PTRNAME),
    CFINIT(NAMELENGTH),
    CFINIT(COPYCONTENTS),
    CFINIT(PTRCONTENTS),
    CFINIT(CONTENTSLENGTH),
 } x;
-- = D Newsgroup.
Mar 24 2004