Home > Ask the Security Experts > Application Security Questions & Answers > What causes buffer overflows and memory leaks in a Web application?
Ask The Security Expert: Questions & Answers
EMAIL THIS

What causes buffer overflows and memory leaks in a Web application?

Michael Cobb EXPERT RESPONSE FROM: Michael Cobb

Pose a Question
Other Security Categories
Meet all Security Experts
Become an Expert for this site


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


>
QUESTION POSED ON: 27 December 2006
What do we mean by memory leaks and buffer overflows in a Web application? Can you use an example that shows how to test for them?

>
EXPERT RESPONSE
These two problems have always plagued Web applications. Buffer overflow exploits, such as the Code Red worm, have led to major data security breaches and system compromises. First, though, let's look at memory leakage, as this will help with your understanding of buffer overflows. A memory leak occurs when a programmer dynamically allocates memory space for a variable of some type, but then fails to free up that space before the program completes. This leaves less free memory for the system to use. Repeated running of the program or function that causes such memory loss can eventually crash the system or result in a denial of service. Here's a simple code example that results in a loss of memory:

int main(int argc, char **argv)
{ 
  char * memoryA = new char[10];
  memoryA [0] = 'A'; 
  printf("%cn", memoryA [0]);
}

This program allocates memory to the variable memoryA to store an array of 10 characters, but the program never explicitly frees it.

In order to prevent memory leakage, programmers should always free any dynamically allocated space when it is no longer required. For simple applications, you can scan your code to ensure that every new operator has a corresponding delete operator, or language-equivalent pairing. For more complex projects, you will need to run an application diagnostic tool, such as Purify or LeakTracer, that detects memory errors. Also, stress-test your application and monitor its memory consumption.

Buffer overflows can result in application or system crashes; they can even allow attackers to compromise the system and initiate unauthorized processes. A buffer overflow occurs when a program or process tries to store more data into a memory buffer than it was intended to hold. A hacker, for example, can submit data to a Web application via a form, and that data is intentionally larger than the memory buffer allocated to hold it. This extra data can overflow into adjacent memory, overwriting any valid data held in it, and often overwriting the return address that is used when the function ends. By writing a new return address, the hacker can trick the system into executing his or her own code.

You should be aware that some languages are more susceptible to buffer overflow errors and memory leaks than others. The C and C++ languages provide no built-in checks to ensure that data written to a buffer is within the boundaries of that buffer. Windows programmers should use Microsoft's strsafe.lib and strsafe.h, provided as part of Visual C++ .NET 2003, which use a library of safe string-handling functions. Applications written in Java, however, don't really suffer from buffer overflows and memory leaks, as Java is a strongly typed language. Be aware, though, that applications written in Java and other "safe" languages can still be susceptible to buffer overflows when they interact with services and libraries that are written in other languages.

The best way to prevent buffer overflow problems is to validate all input data that an application receives. You can even write your own string copy function that incorporates additional data filtering checks at the same time.

More information:

  • See how file format vulnerabilities can trigger buffer overflow attacks.
  • Learn about other threats to your Web applications.

  • Sound Off! -   Be the first to post a message to Sound Off!


    Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


    RELATED CONTENT
    Application Security
    Protecting exposed servers from Google hacks (and Google 'dorks')
    Which automated quality assurance tools can be used to test software?
    Has proof-of-concept mobile device malware translated into any meaningful attacks?
    How to test the security of personal details submitted to a website
    Is security improved when the number of Internet gateways is reduced?
    Are Internet cafe users' email credentials at risk?
    Which operating system can best secure an FTP site?
    Will firewall technology have to adapt to applications that use port 80?
    How secure is a mobile phone platform that has an open source framework?
    What ports should be opened and closed when IPsec filters are implemented?

    Application Attacks (Buffer Overflows, Cross-Site Scripting)
    Tips for SQL injection protection
    Microsoft addresses XSS in Internet Explorer
    Internet Explorer open to spoofing, scripting attacks
    Software still plagued with security holes, researcher says
    Microsoft tools won't be quick fix for SQL injection attacks
    Microsoft identifies tools to address SQL injection attacks
    New defenses for automated SQL injection attacks
    Alarming SQL injection attacks
    Adobe Flash Player flaw previously patched, Symantec says
    Adobe zero day flaw being actively exploited in wild
    Application Attacks (Buffer Overflows, Cross-Site Scripting) Research

    Web Application Security (Also see Web Access Control)
    Microsoft tools won't be quick fix for SQL injection attacks
    New defenses for automated SQL injection attacks
    HP aims at IBM with application vulnerability scanning as service
    Information security book excerpts and reviews
    Kaminsky on DNS rebinding attacks, hacking techniques
    Webmail security: Best practices for data protection
    Tracing malware's steps with RE:Trace
    SQL injection attack infects hundreds of thousands of websites
    PCI Council issues clarification on Web application security
    Web security gateways keep Web-based malware at bay

    RELATED GLOSSARY TERMS
    Terms from Whatis.com − the technology online dictionary
    cache poisoning  (SearchSecurity.com)
    cyberterrorism  (SearchSecurity.com)
    dictionary attack  (SearchSecurity.com)
    directory harvest attack  (SearchSecurity.com)
    distributed denial-of-service attack  (SearchSecurity.com)
    JavaScript hijacking  (SearchSecurity.com)
    ping of death  (SearchSecurity.com)
    script kiddy  (SearchSecurity.com)
    stack smashing  (SearchSecurity.com)
    SYN flooding  (SearchSecurity.com)

    RELATED RESOURCES
    2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
    Search Bitpipe.com for the latest white papers and business webcasts
    Whatis.com, the online computer dictionary



    Search and Browse the Expert Answer Center
    Search and browse more than 25,000 question and answer pairs from more than 250 TechTarget industry experts.
    Browse our Expert Advice

    TechTarget Security Media
    Information Security View this month\\'s issue and subscribe today.
    Information Security Decisions Apply online for free conference admission.
    SearchSecurity.com
    HomeNewsMagazineWebcastsWhite PapersLearningAdviceTopicsEventsAbout Us

    About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
    TechTarget provides enterprise IT professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective IT purchase decisions and managing their organizations' IT projects - with its network of technology-specific Web sites, events and magazines.

    TechTarget Corporate Web Site  |  Media Kits  |  Reprints  |  Site Map




    All Rights Reserved, Copyright 2003 - 2008, TechTarget | Read our Privacy Policy
      TechTarget - The IT Media ROI Experts