Use gets Safely

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Billy Bong

    Use gets Safely

    I wrote this program which guarantees to use gets safely.

    #include <stdio.h>
    int main(void)
    {
    char name[588+1];
    printf("Enter your last name: ");
    fflush(stdout);
    printf("Hi %s\n",gets(name ));
    return 0;
    }

    You see, the longest last name in the world is 588 characters, as
    explained here:

    Because I was afraid to speak When I was just a lad My father gave me nose a tweak And told me I was bad But then one day I learned a word That saved me...


    So, my program works for everyone in the world. Guaranteed.

    --
    Billy
  • user923005

    #2
    Re: Use gets Safely

    On Jan 14, 9:27 pm, Billy Bong <billyb655...@a ol.comwrote:
    I wrote this program which guarantees to use gets safely.
    >
    #include <stdio.h>
    int main(void)
    {
       char name[588+1];
       printf("Enter your last name: ");
       fflush(stdout);
       printf("Hi %s\n",gets(name ));
       return 0;
    >
    }
    >
    You see, the longest last name in the world is 588 characters, as
    explained here:
    >
    Because I was afraid to speak When I was just a lad My father gave me nose a tweak And told me I was bad But then one day I learned a word That saved me...

    >
    So, my program works for everyone in the world. Guaranteed.
    What if they type in an extra ten letters, just for fun?

    What if they feed it a 100 MB binary file?

    Comment

    • Walter Roberson

      #3
      Re: Use gets Safely

      In article <9c4f736c-12dc-43b0-9eb2-825ee17fad9d@v2 9g2000hsf.googl egroups.com>,
      user923005 <dcorbit@connx. comwrote:
      >On Jan 14, 9:27=A0pm, Billy Bong <billyb655...@a ol.comwrote:
      >I wrote this program which guarantees to use gets safely.
      >=A0 =A0char name[588+1];
      >=A0 =A0printf("Hi %s\n",gets(name ));
      >You see, the longest last name in the world is 588 characters, as
      >explained here:
      >So, my program works for everyone in the world. Guaranteed.
      >What if they type in an extra ten letters, just for fun?
      Or if they have a typo in their own name (not unlikely in 588
      characters).
      --
      "Is there any thing whereof it may be said, See, this is new? It hath
      been already of old time, which was before us." -- Ecclesiastes

      Comment

      • Chris Dollin

        #4
        Re: Use gets Safely

        Billy Bong wrote:
        I wrote this program which guarantees to use gets safely.
        >
        #include <stdio.h>
        int main(void)
        {
        char name[588+1];
        printf("Enter your last name: ");
        fflush(stdout);
        printf("Hi %s\n",gets(name ));
        return 0;
        }
        >
        You see, the longest last name in the world is 588 characters, as
        explained here:
        >
        Because I was afraid to speak When I was just a lad My father gave me nose a tweak And told me I was bad But then one day I learned a word That saved me...

        >
        So, my program works for everyone in the world. Guaranteed.
        Exactly how does it ensure that the user is constrained to enter
        a genuine last name, and how does it ensure that the constraints
        for a longest last name /still hold/ when it runs?

        Nice try.

        --
        Far-Fetched Hedgehog
        "It took a very long time, much longer than the most generous estimates."
        - James White, /Sector General/

        Comment

        • Richard Heathfield

          #5
          Re: Use gets Safely

          user923005 said:
          On Jan 14, 9:27 pm, Billy Bong <billyb655...@a ol.comwrote:
          <snip>
          >printf("Hi %s\n",gets(name ));
          >return 0;
          >>
          >}
          >>
          >You see, the longest last name in the world is 588 characters, as
          >explained here:
          >>
          >http://www.everything2.com/index.pl?node_id=1534419
          >>
          >So, my program works for everyone in the world. Guaranteed.
          >
          What if they type in an extra ten letters, just for fun?
          >
          What if they feed it a 100 MB binary file?

          YHBT.


          --
          Richard Heathfield <http://www.cpax.org.uk >
          Email: -http://www. +rjh@
          Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
          "Usenet is a strange place" - dmr 29 July 1999

          Comment

          • Kenny McCormack

            #6
            Re: Use gets Safely

            In article <g-qdnW-Ny7HX_RHanZ2dnU VZ8t7inZ2d@bt.c om>,
            Richard Heathfield <rjh@see.sig.in validwrote:
            >user923005 said:
            >
            >On Jan 14, 9:27 pm, Billy Bong <billyb655...@a ol.comwrote:
            ><snip>
            >
            >>printf("Hi %s\n",gets(name ));
            >>return 0;
            >>>
            >>}
            >>>
            >>You see, the longest last name in the world is 588 characters, as
            >>explained here:
            >>>
            >>http://www.everything2.com/index.pl?node_id=1534419
            >>>
            >>So, my program works for everyone in the world. Guaranteed.
            >>
            >What if they type in an extra ten letters, just for fun?
            >>
            >What if they feed it a 100 MB binary file?
            >
            >
            >YHBT.
            Wow. Call the news media. A CLC regular who gets the joke.
            This is a truly newsworthy event.

            Comment

            • Malcolm McLean

              #7
              Re: Use gets Safely


              "user923005 " <dcorbit@connx. comwrote in message
              On Jan 14, 9:27 pm, Billy Bong <billyb655...@a ol.comwrote:
              >I wrote this program which guarantees to use gets safely.
              >>
              >#include <stdio.h>
              >>int main(void)
              >{
              >char name[588+1];
              >printf("Ente r your last name: ");
              >fflush(stdout) ;
              >printf("Hi %s\n",gets(name ));
              >return 0;
              >
              }
              >
              >You see, the longest last name in the world is 588 characters, as
              >explained here:
              >>
              >So, my program works for everyone in the world. Guaranteed.
              >What if they type in an extra ten letters, just for fun?
              >What if they feed it a 100 MB binary file?
              >
              If you disobey instructions the program might not work. But that's true of
              almost every product.

              --
              Free games and programming goodies.



              Comment

              • Bart C

                #8
                Re: Use gets Safely


                "Billy Bong" <billyb655321@a ol.comwrote in message
                news:ZpXij.2120 $aC6.1044@newsf e07.lga...
                >I wrote this program which guarantees to use gets safely.
                The program can't guarantee anything. It's up to the user in this case, and
                you can't guarantee what the user will do. But I think you knew that.

                I tried your code (using name[5+1] instead to save some typing) with my full
                name, and it crashed.

                Bart
                >
                #include <stdio.h>
                int main(void)
                {
                char name[588+1];
                printf("Enter your last name: ");
                fflush(stdout);
                printf("Hi %s\n",gets(name ));
                return 0;
                }


                Comment

                • Chris Dollin

                  #9
                  Re: Use gets Safely

                  Kenny McCormack wrote:
                  Wow. Call the news media. A CLC regular who gets the joke.
                  This is a truly newsworthy event.
                  Hardly.

                  --
                  Nice Try Hedgehog
                  "Life is full of mysteries. Consider this one of them." Sinclair, /Babylon 5/

                  Comment

                  • Kenny McCormack

                    #10
                    Re: Use gets Safely

                    In article <uL6jj.201667$S 37.66784@fe3.ne ws.blueyonder.c o.uk>,
                    Chris Dollin <eh@electriched gehog.netwrote:
                    >Kenny McCormack wrote:
                    >
                    >Wow. Call the news media. A CLC regular who gets the joke.
                    >This is a truly newsworthy event.
                    >
                    >Hardly.
                    Such style. Such grace. Such quality of argumentation.
                    The only thing missing is the obligatory "Neener, neener!".

                    Comment

                    • Antoninus Twink

                      #11
                      Re: Use gets Safely

                      On 15 Jan 2008 at 19:16, Kenny McCormack wrote:
                      In article <uL6jj.201667$S 37.66784@fe3.ne ws.blueyonder.c o.uk>,
                      Chris Dollin <eh@electriched gehog.netwrote:
                      >>Kenny McCormack wrote:
                      >>
                      >>Wow. Call the news media. A CLC regular who gets the joke.
                      >>This is a truly newsworthy event.
                      >>
                      >>Hardly.
                      >
                      Such style. Such grace. Such quality of argumentation.
                      The only thing missing is the obligatory "Neener, neener!".
                      Interesting to see Chris "holier-than-thou" Dollin getting his hands
                      dirty insulting the "trolls" though...

                      Comment

                      • Antoninus Twink

                        #12
                        Re: Use gets Safely

                        On 15 Jan 2008 at 21:33, Chris Dollin wrote:
                        Antoninus Twink wrote:
                        >Interesting to see Chris "holier-than-thou" Dollin
                        >
                        I'm honoured, Antoninus, but I didn't realise you were qualified
                        to award holiness.
                        Yes, that did end up sounding much too pejorative! I don't think you're
                        positively sanctimonius at all - it's just that unlike most of The
                        Clique you seem quite good-natured and good-humored, and don't usually
                        go in for the nastiness and acrimony that's the bread and butter of most
                        of the regulars here.
                        >getting his hands dirty insulting the "trolls" though...
                        >
                        /That/ was mere snark.
                        Fair enough. You'd have to agree that CLC is actually one of the most
                        humorless places on Usenet though...

                        Comment

                        • Chris Dollin

                          #13
                          Re: Use gets Safely

                          Antoninus Twink wrote:
                          On 15 Jan 2008 at 19:16, Kenny McCormack wrote:
                          >In article <uL6jj.201667$S 37.66784@fe3.ne ws.blueyonder.c o.uk>,
                          >Chris Dollin <eh@electriched gehog.netwrote:
                          >>>Kenny McCormack wrote:
                          >>>
                          >>>Wow. Call the news media. A CLC regular who gets the joke.
                          >>>This is a truly newsworthy event.
                          >>>
                          >>>Hardly.
                          >>
                          >Such style. Such grace. Such quality of argumentation.
                          >The only thing missing is the obligatory "Neener, neener!".
                          >
                          Interesting to see Chris "holier-than-thou" Dollin
                          I'm honoured, Antoninus, but I didn't realise you were qualified
                          to award holiness.
                          getting his hands dirty insulting the "trolls" though...
                          /That/ was mere snark.

                          --
                          Boojum Too Hedgehog
                          The "good old days" used to be much better.

                          Comment

                          • Kelsey Bjarnason

                            #14
                            Re: Use gets Safely

                            [snips]

                            On Tue, 15 Jan 2008 10:26:49 +0000, Malcolm McLean wrote:
                            >>What if they feed it a 100 MB binary file?
                            >>
                            If you disobey instructions the program might not work. But that's true of
                            almost every product.
                            Unlike most products, software can cope with such things. A toaster can't
                            prevent you sticking a fork in it while it's plugged in, even though this
                            is an undesirable state of affairs, but a program _can_ prevent you
                            entering incorrect inputs, by avoiding input routines such as gets, and by
                            validating the data returned by such routines.

                            Besides, much input to a typical program comes from humans, who are *not*
                            perfect in their typing, let alone anything else they do. A program which
                            fails to deal with this reality is doomed to endless errors. A programmer
                            who fails to deal with this reality is - one would hope - doomed to a
                            career path not involving software development.

                            Comment

                            • Richard Bos

                              #15
                              Re: Use gets Safely

                              "Malcolm McLean" <regniztar@btin ternet.comwrote :
                              "user923005 " <dcorbit@connx. comwrote in message
                              On Jan 14, 9:27 pm, Billy Bong <billyb655...@a ol.comwrote:
                              I wrote this program which guarantees to use gets safely.
                              char name[588+1];
                              printf("Hi %s\n",gets(name ));
                              You see, the longest last name in the world is 588 characters, as
                              What if they type in an extra ten letters, just for fun?
                              >
                              What if they feed it a 100 MB binary file?
                              >
                              If you disobey instructions the program might not work. But that's true of
                              almost every product.
                              You clearly do not own a pet larger than a budgie, and do not have
                              little children. Nor do you read reference books while coding.

                              Richard

                              Comment

                              Working...