Re: security coding guidelines for C/C++

From: Malcolm (malcolm_at_55bank.freeserve.co.uk)
Date: 05/24/04


Date: Mon, 24 May 2004 21:00:08 +0100


"Aravind" <arvind_c_98@yahoo.com> wrote in message
>
> I am Aravind.Could someone provide me with a list of specific
> guidelines for secure programming in C/C++?.
> I would like to use those guidelines for developing a security
> application to deal with issues like buffer overflows,memory
> leaks,user input validation etc....
>
Security is a real problem for C programs, and it is not easy to write tools
to check for it.
The worst problem is when user input overflows an "auto" (stack) array, on
systems where this corrupts the reurn stack. An attacker can use this to
induce a jump to a location of his choosing, and thus introduce malicious
code.
It is also possible to oveflow the stack. For instance the code

double eval( char *expr)
{
  ...
  if(*expr == '9')
    temp = eval(expr+1);
  ...
}

can be caused to crash by inputting a huge number of open parentheses.

You simply have to be careful to call malloc() with the right size, not
overstep the array, check the return value, and free memory after you have
done with it. The good news is that there is little the user can do to wreck
things here. (To test, a good technique is to provide a version of malloc()
that fails periodically).

For user input, be aware that the user can type anything, and assume he is
trying to wreck your program and has a copy of the source.



Relevant Pages

  • [REVS] Writing Buffer Overflow Exploits - a Tutorial for Beginners
    ... The following security advisory is sent to the securiteam mailing list, and can be found at the SecuriTeam web site: http://www.securiteam.com ... Buffer overflows in user input dependent buffers have become one of the ... The bottom of the stack ... To keep it simple, shellcode is simply assembler commands, which we write ...
    (Securiteam)
  • Re: Ultra-Fast Stateless Forward Signing
    ... The protocol stack has security built in, ... There are no options for selecting multiple symmetric ciphers or ... problems of mobility and security for last. ...
    (sci.crypt)
  • Re: [Full-Disclosure] Re: Buffer overflow prevention
    ... his code cant run off your stack. ... It does provide some form security, but only a really tiny amount. ... You can download it from the PaX site ... I think there are several reasons why the major Linux ...
    (Full-Disclosure)
  • Re: Intermittent Net Access And Zonealarm
    ... Installing a personal firewall requires rigid ... Even one such change might open new security ... >>holes in the stack itself or in networking applications. ...
    (comp.security.firewalls)
  • Re: unspected shutdown. TCP attack?
    ... original debugging environment and see what is causing that problem. ... be your program has a bug that is bringing down the tcp/ip stack and causing ... >> I'll also hit one thing you may not have checked, in your local security ...
    (microsoft.public.win2000.general)