[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] OT: C Q/As, was Re: security_20040618
From: |
Charlie Gordon |
Subject: |
[Qemu-devel] OT: C Q/As, was Re: security_20040618 |
Date: |
Mon, 21 Jun 2004 12:21:46 +0200 |
> > one of my favorite Q/As : what is wrong with : enum BOOL { FALSE=0,
> > TRUE=1 }; ?
>
> can you enlighten me? The only drawback I see is that with plain C (no
> C++) typedef enum { ... } BOOL; would be more appropriate.
>
defensive programming would require that TRUE be also defined as
#define TRUE 1
as many unsuspecting programmers will expect TRUE and FALSE to be handled in
the preprocessor phase eg:
#if TRUE
...
somecode();
...
#endif
if TRUE is defined solely as en enum value, it will expand to 0 inside
preprocessing directive expressions without warning : quite a headache to
debug this type of mistake !
> PS: I used to ask: Why does this crash later (if you are lucky)
>
> const char *itoa(int i)
> { char x[20];
> snprintf(x,sizeof x,"%d",i);
> return x;
> }
This code will abviously fail, unless you are very lucky and use the
returned value right away, as the x buffer is in automatic stack space and
will be overwritten by subsequent function calls or possibly signal
handlers.
I can think of 4 ways it may crash later when the pointer is dereferenced :
- you are using an advanced C compiler/runtime that checks pointer validity
(such as valgrind, checker, tinycc...)
- after the end of the thread that called itoa.
- if pages in the stack are unmapped for another reason like the stack being
swapped out and having shrunk below the depth it had when itoa was called
(quite unlikely).
- if the stack contains no zero byte till the end of its mapped space (you
would have to be so lucky for this!)
Anything more casual ?
Charlie, the C teaser.
- Re: [Qemu-devel] [PATCH] security_20040618, (continued)
- Re: [Qemu-devel] [PATCH] security_20040618, Fabrice Bellard, 2004/06/19
- Re: [Qemu-devel] [PATCH] security_20040618, Vladimir N. Oleynik, 2004/06/19
- Re: [Qemu-devel] [PATCH] security_20040618, Tim, 2004/06/19
- [Qemu-devel] Re: [PATCH] security_20040618, Charlie Gordon, 2004/06/20
- Re: [Qemu-devel] Re: [PATCH] security_20040618, Tim, 2004/06/20
- [Qemu-devel] Re: Re: [PATCH] security_20040618, Charlie Gordon, 2004/06/20
- Re: [Qemu-devel] Re: Re: [PATCH] security_20040618, Tim, 2004/06/20
- OT: C Q/As, was Re: [Qemu-devel] security_20040618, Christof Petig, 2004/06/21
- [Qemu-devel] OT: C Q/As, was Re: security_20040618,
Charlie Gordon <=
- Re: [Qemu-devel] OT: C Q/As, was Re: security_20040618, Christof Petig, 2004/06/21
- Re: OT: C Q/As, was Re: [Qemu-devel] security_20040618, Michael Jennings, 2004/06/21
- [Qemu-devel] Re: completely OT: C Q/As, was Re: security_20040618, Charlie Gordon, 2004/06/22
- Re: [Qemu-devel] Re: completely OT: C Q/As, was Re: security_20040618, Sander Nagtegaal, 2004/06/22
- [Qemu-devel] Re: Re: completely OT: C Q/As, was Re: security_20040618, Charlie Gordon, 2004/06/22
- Re: [Qemu-devel] Re: completely OT: C Q/As, Michael Jennings, 2004/06/22
- [Qemu-devel] Re: Re: completely OT: C Q/As : let's feed the troll, Charlie Gordon, 2004/06/24