Re: vulnerabilities

From: Dan Pop (Dan.Pop_at_cern.ch)
Date: 10/22/04


Date: 22 Oct 2004 19:33:37 GMT

In <41794e86$0$1007$8fcfb975@news.wanadoo.fr> jacob navia <jacob@jacob.remcomp.fr> writes:

>I do not pretend that my first example compiles. The second does
>however: here it is again:

Even if it compiles, this doesn't make it legal.

>#include <stdio.h>
>void memset(char * p,int s,int b)
>{
> while (b--)
> *p++ = s;
>}

Being in a different namespace, I guess C++ allows using the memset
function name like this, but I could be wrong.

>void main(void)

>From the C++ standard:

2 An implementation shall not predefine the main function. This func-
  tion shall not be overloaded. It shall have a return type of type
                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  int, but otherwise its type is implementation-defined.
  ^^^
>{
> char p[2];
>
> memset(p,0,123546);
> printf("not reached :-)\n");
>}
>
>Will you pretend that this is not legal C++?

g++ certainly does:

    fangorn:~/tmp 88> cat test.c
    void main(void) { }
    fangorn:~/tmp 89> g++ test.c
    test.c:1: error: `main' must return `int'

>It compiles perfectly and crashes as it should.
 
If your C++ compiler doesn't even warn about it, ask for a refund.
Note that a "shall" requires a diagnostic when violated, in the C++
standard (unless the standard explicitly says otherwise).

Dan

-- 
Dan Pop
DESY Zeuthen, RZ group
Email: Dan.Pop@ifh.de
           Currently looking for a job in the European Union


Relevant Pages

  • Re: Calling a managed function from native code
    ... running on top of the CLR but which is isn't garbage collected. ... compiles to IL which is JIT compiled and runs on top of the CLR. ... void test() { ... You can't do that, String is not disposable, it doesn't have a destructor, it doesn't have a Dispose method. ...
    (microsoft.public.dotnet.languages.vc)
  • (no subject)
    ... your module compiles fine on my box using this method ... > I have tried to compile the hello.c module under kernel 2.6.3. ... > int initial_module (void) ... send the line "unsubscribe linux-kernel" in ...
    (Linux-Kernel)
  • Re: Linux compiling
    ... For a start, void main has *never* been correct and as Jack has said, it ... but what they hey, it compiles doens't it!" ... a warning - so from slightly broken to completely broken happened. ... It is a biggy and to ...
    (alt.comp.lang.learn.c-cpp)
  • Re: why does it crash?
    ... Could you be more specific at which line it crashes, ... vectorCities; ... > this program compiles, but crashes when run. ... > void output(); ...
    (comp.lang.cpp)
  • Re: volatile
    ... > void handler(int signo) ... I'm pretty sure there are implementations not providing for an ... Dan Pop ...
    (comp.lang.c)