Thread: Urgent help on buffer overflow

  1. #1
    Registered User
    Join Date
    Dec 2018
    Posts
    1

    Urgent help on buffer overflow

    Hi all,

    I got to write a program, which allow user to enter the name, and it will generate two numbers from 0-100, and calculate the average of it.

    And i will to hack the program so the average can always be the highest which is 100.
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    int main ()
    {
    
    srand(time(NULL));
    char input[8];
    
    printf("Please enter the student name: ");
    gets(input);
    int score1=rand()%100+1;
    int score2=rand()%100+1;
    float average = (score1+score2) / (float)2;
    
    printf("Your name is: %s", input);
    printf("\nYour first mark is: %d ", score1);
    printf("\nYour secord mark is: %d", score2);
    printf("\nAnd the averge mark is: %f\n", average);
    return 0;
    }
    

    Any experts know how to hack the average?

    Thanks,
    Eddie

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    We normally shut down posts requesting help on exploiting buffer overflows, but I grant that this is a clearly contrived program that looks intended to show the pitfalls of gets and buffer overflow, so I'll tentatively let it stand.

    Anyway, haven't you experimented with causing a buffer overflow and seeing what you get?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Buffer Overflow
    By AlexTank853 in forum C Programming
    Replies: 3
    Last Post: 09-25-2013, 04:14 PM
  2. Buffer overflow error. please help
    By Matt Hintzke in forum C Programming
    Replies: 12
    Last Post: 02-02-2012, 11:22 PM
  3. Buffer overflow gone wrong
    By Wolf` in forum C Programming
    Replies: 13
    Last Post: 08-09-2009, 10:00 AM
  4. buffer overflow
    By cpp_is_fun in forum C Programming
    Replies: 2
    Last Post: 10-24-2006, 11:04 PM

Tags for this Thread