Examine Code

This is a discussion on Examine Code within the C Programming forums, part of the General Programming Boards category; i am good at coding and stuff so please can anyone please help me in finding 1)some vulnerability of class/type ...

  1. #1
    AG1
    AG1 is offline
    Registered User
    Join Date
    May 2012
    Posts
    12

    Question Examine Code

    i am good at coding and stuff so please can anyone please help me in finding 1)some vulnerability of class/type 2) the exact cause of the problem 3) How to fix the code to mitigate the vulnerability.??
    Code:
    int get_stuff()
    { int ran1, ran2;
    char stuff[64];
    ran2 = ran1 = rand(); /* get a random number */
    gets(stuff);
    if (ran1 != ran2)
    exit(); /* something wrong */
    else
    /* proceed */
    }

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,761
    If you're "good at coding", then you should really know about the gets() flaws already, and how to fix them.

    Or at least be able to read about it in pretty much any C programming FAQ around the net.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    AG1
    AG1 is offline
    Registered User
    Join Date
    May 2012
    Posts
    12
    @salem - sorry that's my typo mistake, I meant to say I'm not good at programming. Can u help me with this code??

  4. #4
    Registered User
    Join Date
    May 2009
    Posts
    2,747
    "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the Universe is winning." Rick Cook

  5. #5
    Technical Lead QuantumPete's Avatar
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    894
    1) "get_stuff" is a terrible function name
    2) variables should be declared on their own lines
    3) variables should be initialised
    4) Nothing should go on the same line after a curly brace
    5) As mentioned gets is a big no-no
    6) You're using C++ style comments
    7) Always use braces with if statements
    8) Don't exit from functions, especially when they have a return variable
    9) Always return something unconditionally from a function that has a return value
    10) Indent your code properly
    "No-one else has reported this problem, you're either crazy or a liar" - Dogbert Technical Support
    "Have you tried turning it off and on again?" - The IT Crowd

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Examine size of code/data in the exe
    By idelovski in forum Windows Programming
    Replies: 4
    Last Post: 01-03-2012, 02:44 PM
  2. Examine Core Dump
    By wenxinleong in forum C Programming
    Replies: 1
    Last Post: 07-04-2011, 11:52 AM
  3. Examine hex number?
    By Sly in forum C Programming
    Replies: 16
    Last Post: 03-01-2009, 01:04 PM
  4. Examine a variable with GDB
    By ^xor in forum Linux Programming
    Replies: 8
    Last Post: 08-16-2005, 02:40 PM
  5. Examine my code please
    By TWIXMIX in forum C++ Programming
    Replies: 13
    Last Post: 03-21-2004, 12:28 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21