Thread: gets() not so bad

  1. #61
    Registered User
    Join Date
    Aug 2009
    Posts
    198
    Quote Originally Posted by Elysia View Post
    That just shows how naive you are about security.
    Do you want your program to crash on users?
    Furthermore, how about those bugs that doesn't cause a crash? The invisible ones that leaves your computer wide open to hacker attacks?
    I didn't say that I thought segmentation faults are fine. I just said that I can find and fix them without harming my system.

  2. #62
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Like I said, what happens if you share your code and it crashes on someone else's system?
    What happens if you're running your program in the background and some hacker comes and causes a buffer overrun? What if the hacker takes over your system?

    A buffer overrun may or may not result in a segmentation fault. Furthermore, it can completely screw up your program. It could even delete files you wouldn't want off your hard drive. Would you like that?
    By the time the overrun occurs, it's too late to fix it. The damage is done.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #63
    Registered User
    Join Date
    Jan 2010
    Location
    Ca, US
    Posts
    29
    What can go wrong

    Code:
    #include <stdio.h>
    int
    main(int argc, char *argv[])
    {
            char name[6];
            char folder[] = "/home/dylan/old_folder";
            printf("Enter your name : ");
            gets(name);
            printf("Your Name Is %s\n",name);
            printf("Im going to delete folder %s\n",folder);
            return 0;
    }
    Look my code runs just fine
    Code:
    ./bad_code 
    Enter your name : Dylan
    Your Name Is Dylan
    Im going to delete folder /home/dylan/old_folder
    Yeah must be good
    Code:
    ./bad_code 
    Enter your name : Dylan /home/dylan/keep_me
    Your Name Is Dylan /home/dylan/keep_me
    Im going to delete folder /home/dylan/keep_me
    Where is my folder??

  4. #64
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    I regret not having a code injection sample to show you. But just google buffer overrun to see some. It shouldn't be hard.

    Your code is a ticking time bomb, but your usage didn't cause a buffer overrun.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #65
    Registered User
    Join Date
    Jan 2010
    Location
    Ca, US
    Posts
    29
    Your code is a ticking time bomb, but your usage didn't cause a buffer overrun.
    It's not?

    So when I put "Dylan /home/dylan/keep_me" into name[6] and the "/home/dylan/keep_me" ends up outside of name[0]-name[5].

    Is there another name for this then??

    Dylan

  6. #66
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    dylan's example does look like an example of a buffer overrun to me, though of course whether it demonstrates it in precisely the way shown is implementation dependent.
    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

  7. #67
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by dylan View Post
    It's not?

    So when I put "Dylan /home/dylan/keep_me" into name[6] and the "/home/dylan/keep_me" ends up outside of name[0]-name[5].

    Is there another name for this then??

    Dylan
    And where do you copy that into name?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  8. #68
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by Elysia
    And where do you copy that into name?
    Here:
    Code:
    gets(name);
    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

  9. #69
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Ah, right, confusing Linux syntax + the hard coded string literal.
    Of course, the second example is a buffer overrun. I don't know if I only considered the first which isn't.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  10. #70
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    Ah, right, confusing Linux syntax + the hard coded string literal.
    WHAT??? "Confusing Linux syntax"??? Yeah....OK...

  11. #71
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Yes, Linux all about confuzzling.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  12. #72
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by Elysia
    Ah, right, confusing Linux syntax + the hard coded string literal.
    Actually, the only thing Linux about the examples is the directory separator, and even that is not Linux specific.

    Quote Originally Posted by Elysia
    I don't know if I only considered the first which isn't.
    I think dylan's first example was just to demonstrate the expected result, kind of like what nonoob was talking about things working for a newbie.
    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

  13. #73
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by laserlight View Post
    I think dylan's first example was just to demonstrate the expected result, kind of like what nonoob was talking about things working for a newbie.
    Yeah, I got that much. I was too lazy to properly slam dylan, so feel free.
    I'm just too tired to rant about security and how that example is so broken in so many ways.
    And how these silly newbies just pop up and think they're right.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  14. #74
    Registered User
    Join Date
    Jan 2010
    Location
    Ca, US
    Posts
    29
    Quote Originally Posted by Elysia View Post
    Yeah, I got that much. I was too lazy to properly slam dylan, so feel free.
    I'm just too tired to rant about security and how that example is so broken in so many ways.
    And how these silly newbies just pop up and think they're right.
    Hmmm???

    The code I posted was a joke, the first time I ran it it ran fine (Only because I used < 5 chars).
    But my point was just because people's code runs it might not be correct, the second time I ran it, I used more text in the question to demonstrate what can happen.

    My post was the show that code can work but is BAD!!!

    I'm not trying to say I'm right. When you told me my code was not a buffer overflow, I believed you but could not figure out why.

    Dylan

  15. #75
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Yeah, I missed it at the first time. Still, this applies to nonoob, then.
    You should have made it clearer what you meant to say...
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. bad and fail of steam
    By George2 in forum C++ Programming
    Replies: 8
    Last Post: 02-19-2008, 03:07 AM
  2. Can you still view the bios screen with a bad CPU?
    By HyperCreep in forum Tech Board
    Replies: 4
    Last Post: 12-31-2006, 06:57 PM
  3. Replies: 6
    Last Post: 11-12-2005, 11:57 AM
  4. Bad coding habits
    By Magos in forum A Brief History of Cprogramming.com
    Replies: 14
    Last Post: 09-12-2005, 05:44 PM
  5. Shocking(kind of)
    By Shadow in forum A Brief History of Cprogramming.com
    Replies: 25
    Last Post: 12-10-2002, 08:52 PM