Copilot
Your everyday AI companion
About 249,000 results
    Upvotes240edited Sep 2, 2022 at 15:10

    Why is gets() dangerous

    The first internet worm (the Morris Internet Worm) escaped about 30 years ago (1988-11-02), and it used gets() and a buffer overflow as one of its methods of propagating from system to system. The basic problem is that the func...

    char *gets(char *buffer)
    {
    assert(buffer != 0);
    abort();
    return 0;
    }

    Given that your code will crash anyway, sooner or later, it is better to head the trouble off sooner rather than later. I'd be prepared to add an error message:

    fputs("obsolete and dangerous function gets() called\n", stderr);
    Content Under CC-BY-SA license
    Was this helpful?
  1. c - Why is the gets function so dangerous that it should not be …

  2. c - warning: the `gets' function is dangerous and should not be …

  3. gets() is risky to use! - GeeksforGeeks

  4. Warning: the gets function is Dangerous and should …

    WEBSep 14, 2019 · The correct thing to do is to use the fgets function with the stdin file handle since you can limit the characters read from the user. …

    • Estimated Reading Time: 4 mins
    • Why there is no "gets" function in C standard library?

    • People also ask
      It is dangerous and should not be used. The message tells you that. The function gets is unsafe and is not supported by the C standard. The used array can be overwritten beyond its size. Instead use the function fgets. That is instead of this statement The function can append the new line character '\n' to the entered string.
      [-Wimplicit-function-declaration] ” and another “ warning: the `gets' function is dangerous and should not be used. ” In C Language to read a string generally everyone use gets () function. In order to use gets safely, you have to know exactly how many characters you will be reading so that you can make your buffer large enough.
      Note that the real danger is not in being able to crash your program, but in being able to make it run arbitrary code. (In general, exploiting undefined behavior.) The C gets function is dangerous and has been a very costly mistake. Tony Hoare singles it out for specific mention in his talk "Null References: The Billion Dollar Mistake":
      It's no more "dangerous" than any other string function when used appropriately, such as in program examples, documentation, unit test scaffolding, homework assignments, etc. What's more, gets () enhances readability in a way that fgets () never will.
    • C gets function - codingpointer.com

    • Why GCC does warn me when I using gets () function for …

    • [Solved] Why gets() function is dangerous to use in code

    • Why gets() function dangerous to use??? - C / C++

    • warning: the `gets' function is dangerous and should not be used.

    • Some results have been removed