Re: [Lit.] Buffer overruns

From: Trevor L. Jackson, III (tlj3_at_comcast.net)
Date: 01/29/05


Date: Fri, 28 Jan 2005 21:29:47 -0500

Mok-Kong Shen wrote:

>
>
> Trevor L. Jackson, III wrote:
>
>> Phil Carmody wrote:
>>
>
>>> I don't know if the intent was malicious, but I've see both of these
>>> before #includes:
>>>
>>> #define const
>>> #define private public // OK, not C, but you get the idea
>>>
>>> Some things are almost impossible to defend against.
>>
>>
>>
>> Those symbols are defensible. Just #define them.
>
>
> You are largely but not entirely right, I am afraid. You
> apparently assumed that detection of such matters could
> be perfect, which often may not be the case in practice,
> particularly if the software is of significant size.
> I suppose it is barely possible to eradicate all errors
> (either due to neligence/mistakes or due to intended
> malicious acts), just like one couldn't eradicate all
> drug traffic and abuses in the world. On the other hand,
> taking sufficient measures (all practically feasible
> ones in one's given environment) in defensive (perhaps
> even proactive?) error prevention/recovery is certainly
> a worthwhile/necessary goal to be achieved for all
> safety critical applications.

No I did not make any such assumption. I made the claim that by
#defining the symbols within the source code you control you can inhibit
any preprocessor overrides of those symbols. An alternative is to
#undef them, but that fails silently. I prefer that the conflict be
made visible by an error message regarding dissimilar definitions. Note
that multiple definitions of reserved symbols will not conflict with
each other.

You can even automate it by creating a header file such as define_C.h
and including it as the first header in each source file.

Note that this technique also defends against symbol overrides from the
command line and/or environment.



Relevant Pages

  • Re: [Lit.] Buffer overruns
    ... > any preprocessor overrides of those symbols. ... I prefer that the conflict be ... > You can even automate it by creating a header file such as define_C.h ... examining these code regions. ...
    (sci.crypt)
  • Re: True Name Spaces, when?
    ... // this solves sysutils conflict ... By forceing yourself to touch each and every source code file that might use web/pwmain, each and every time you need to switch, you are increasing the possibility of error, and making it virtually impossible for multiple developers to be working on separate issues in parallel. ... Again name your new code 'sockets', put it in a directory with a properly versions name, adjust your search path, and fix it for your entire project with one fell swoop, without error. ...
    (borland.public.delphi.non-technical)
  • Compiler error creating managed c++ directx app
    ... I'm trying to create a simple program using managed C++ and DirectX. ... Here is the source code I am using: ... did you forget to include a header file? ... "Microsoft.DirectX" to References in Solution Explorer, ...
    (microsoft.public.win32.programmer.directx.managed)
  • Re: beginners questions
    ... # (I work on Linux 2.4.22/Debian) ... Some supply the source code, ... second #define converts them into old style K+R function declarations. ... use the same header file for two different styles of compilation. ...
    (comp.lang.c)
  • Re: #ifdef
    ... It may be defined by the user, or somewhere in a header file, ... out of a larger context such as the OS source code ... C code after preprocessing but before compiling. ... in tracking down issues with preprocessor symbols. ...
    (comp.lang.c)