Giter VIP home page Giter VIP logo

safe-memory-c's Introduction

safe-memory-c

Safe allocation and deallocation of memory in C

The maximum number of locations kept track of can be modified by changing MAX_LOCin safe_mem.c

Functionalities

Hijacking

A shell script hijack.sh is provided.

Make sure to have the safe_mem.c file in the working directory.

Assuming the client file is hijack_client.c, run :

hijack.sh hijack_client

hijack.out is produced

Normal Usage

Interfaces Provided :

  • smalloc
  • sfree

Sample client ( client.c )

#include <stdio.h>
#include <stdlib.h>
#include "safe_mem.h"

int main() {
  char *ptr = smalloc(sizeof(char));
  int *arr = smalloc(5 * sizeof(int));

  // double free will not cause segmentation fault
  sfree(ptr);
  sfree(ptr);

  sfree(arr);

  int a = 5;
  int *b = &a;
  // freeing location on stack will not cause segmentation fault
  sfree(b);
}

Compilation & Running :

gcc client.c safe_mem.c

Sample output :

Invalid free()!!, not freeing memory at location 0x557d7858d2a0
Invalid free()!!, not freeing memory at location 0x7fff397ff17c

safe-memory-c's People

Contributors

sriram1999s avatar

Watchers

 avatar

safe-memory-c's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.