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, featured expert EXPERT RESPONSE FROM: Michael Cobb, featured expert

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?

>
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.

  • BUFFER OVERFLOW TUTORIAL
      Buffer overflow protection introduction
      How to prevent buffer overflows
      What causes buffer overflows
      Testing for buffer overflows
      Web application vulnerability scanners


    BROWSE BY TAG
    Application Security,   Application and Platform Security,   Application Attacks (Buffer Overflows, Cross-Site Scripting),   Web Security Tools and Best Practices,   Web Application Security,   VIEW ALL TAGS

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



    RELATED CONTENT
    Application Security
    Do Facebook URL security concerns justify blocking social networks?
    Is there a way to block iPhone widgets that bypass Web filters?
    Should enterprises be concerned with Twitter in the workplace?
    Are there still Google Desktop security problems?
    Can an IP spoofing tool be used to spam SPF servers?
    Will an application usage policy best control network bandwidth?
    How can URL-shortening services be manipulated?
    Is my security program ready for Web application firewall deployment?
    How to ensure the security of a shopping cart application
    When to use the service features of the Metasploit hacking tool

    Application Attacks (Buffer Overflows, Cross-Site Scripting)
    Quiz: How to build secure applications
    Black box and white box testing: Which is best?
    Adobe warns of critical update for Reader, Acrobat 9.1.3
    9 Ways to Improve Application Security After an Incident
    Developers Need Help with Security Errors
    Buffer overflow tutorial: How to find vulnerabilities, prevent attacks
    SQL injection protection: A guide on how to prevent and stop attacks
    Experts rebuke programmers who use SQL injection as feature
    SANS: Application threats, website flaws pose biggest security threats
    Mozilla helps Adobe push out faster patches
    Application Attacks (Buffer Overflows, Cross-Site Scripting) Research

    Web Application Security
    Black box and white box testing: Which is best?
    InZero Systems launches hardware-based security gateway
    Web application vulnerability assessment shows patching progress
    Preventing SQL injection attacks: A network admin's perspective
    Cisco acquires SaaS security vendor ScanSafe
    Web application firewall use goes beyond compliance, company finds
    Gumblar Trojan drive-by exploits spike following Adobe update
    Some Facebook applications lead to Russian attack sites
    Barracuda acquires Purewire expanding Web security reach
    An enterprise strategy for Web application security threats

    RELATED GLOSSARY TERMS
    Terms from Whatis.com − the technology online dictionary
    buffer overflow  (SearchSecurity.com)
    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)
    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



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

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

    TechTarget Corporate Web Site  |  Media Kits  |  Site Map




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