Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 937025
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T21:24:29+00:00 2026-05-15T21:24:29+00:00

How do you create a unit test case in c for a buffer overflow

  • 0

How do you create a unit test case in c for a buffer overflow that does not cause a memory error such as a segfault?

I.e. Given a simple buffer overflow, such as

int function () {
    int exampleArray[10];
    exampleArray[10] = 5;
    return 0;
}

How do you create a unit test for this code? There is clearly an error, we are writing past the end of an array. However, you can run a function like this without any evidence of the error.

Note: I need to be able to create test cases for when the index to the array is supplied at run time by the user as well as the above simplified case.

In a managed language like Java the code will throw an exception (ArrayIndexOutOfBoundsException) which can be caught. So creating a test case is straightforward (a try-catch block for the exception).

How would such a test be created in c? Can any of the unit testing frameworks for C handle such a situation?

Background Information: I’m trying to do automatic test case generation. I know where the errors are and would like to be able to create a unit test to fail on these bugs.

However I wouldn’t have the faintest idea how to create a test case that fails for a buffer overflow bug that doesn’t crash the application.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T21:24:30+00:00Added an answer on May 15, 2026 at 9:24 pm

    One way to check is to allocate extra bytes before and after the buffer if you are using heap. But it will be difficult to keep track of every variable. After the function ends you can check if the data in those buffers was modified. You have to create a seperate library to hold these values for you.

    Alternatively check this link. Hope it will give you more information on testing for buffer overflow.

    EDIT : Some more information :

    1. Its difficult or rather not your job to test for APIs which dont take any input. However if the API takes input which will be manipulated during the course of the execution then you can pass values which can cause overrun.

      void foo()
      {

      char buffer [5];
      
      
       strcpy(buffer, "StackOverflow");
      
      // Clearly overflow. Has to be found out in Code reviews or static analysis
      
      
      }
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 529k
  • Answers 529k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Here is a good overview of working with XML in… May 16, 2026 at 11:13 pm
  • Editorial Team
    Editorial Team added an answer To start, you should log the moc in both app… May 16, 2026 at 11:13 pm
  • Editorial Team
    Editorial Team added an answer No, the NDK only offers limited apis. The only officially… May 16, 2026 at 11:13 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I'm trying to create a unit test to test the case for when the
I need to create a unit-test for some python class. I have a database
I would like to create a unit test using a mock web server. Is
I wrote a test case that extends AbstractTransactionalJUnit4SpringContextTests . The single test case I've
In the unit tests that I wrote, I provide a test fixture for each
when i try to create unit tests using the unit test wizzard in visual
(Title was: How to write a unit test for a DBUS service written in
I have a unit test where I run a method for every item in
I am having a issue with boost unit testing. Basically I create a fixture
I am trying to create a function with a variant record-type parameter that allows

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.