Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect Array out of bounds #198

Closed
Wherekonshade opened this issue Apr 22, 2021 · 0 comments · Fixed by #257
Closed

Detect Array out of bounds #198

Wherekonshade opened this issue Apr 22, 2021 · 0 comments · Fixed by #257
Assignees
Labels
feature practical-course Practical Course at TUM

Comments

@Wherekonshade
Copy link
Contributor

Wherekonshade commented Apr 22, 2021

Current situation
Goblint currently cannot find/analyze undefined behavior like:

-Array-Bounds (Index out of bounds access; Source: https://www.geeksforgeeks.org/accessing-array-bounds-ccpp/ )

There are 2 general ways this can happen:

  1. Access non allocated location of memory: The program can access some piece of memory which is owned by it:
// Program to demonstrate 
// accessing array out of bounds
#include <stdio.h>
int main()
{
    int arr[] = {1,2,3,4,5};
    printf("arr [0] is %d\n", arr[0]);
      
    // arr[10] is out of bound
    printf("arr[10] is %d\n", arr[10]);
    return 0;
}

Output :

arr [0] is 1
arr[10] is -1786647872
  1. Segmentation fault: The program can access some piece of memory which is not owned by it, which can cause crashing of program such as segmentation fault
// Program to demonstrate 
// accessing array out of bounds
#include <stdio.h>
int main()
{
    int arr[] = {1,2,3,4,5};
    printf("arr [0] is %d\n",arr[0]);
    printf("arr[10] is %d\n",arr[10]);
      
    // allocation memory to out of bound 
    // element
    arr[10] = 11;
    printf("arr[10] is %d\n",arr[10]);
    return 0;
}

Output :
Runtime Error : Segmentation Fault (SIGSEGV)

Situation after Resolving this Issue
Goblint can detect this undefined Behavior. This will be optional.

@vandah
@EdinCitaku

@michael-schwarz michael-schwarz added feature practical-course Practical Course at TUM labels Apr 22, 2021
@Wherekonshade Wherekonshade changed the title Undefined Behavior(Array out of bonds) Detect Array out of bounds Apr 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature practical-course Practical Course at TUM
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants