Tool for detecting Array overflow

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • vashwath@rediffmail.com

    #1

    Tool for detecting Array overflow

    Hi all,
    Is there any free tool available for detecting array overflow? I found
    one which detects overflow of dynamic arrays. But I need a tool(or a
    special compiler) which detects static array overflows too.

    Thanks

  • Chris McDonald

    #2
    Re: Tool for detecting Array overflow

    vashwath@rediff mail.com writes:
    [color=blue]
    >Hi all,
    >Is there any free tool available for detecting array overflow? I found
    >one which detects overflow of dynamic arrays. But I need a tool(or a
    >special compiler) which detects static array overflows too.[/color]

    <OT>
    Any helpful answer you receive will probably be very compiler-specific.
    If using gcc, your instance of it may support the -fbounds-check
    command line option.
    </OT>

    --
    Chris.

    Comment

    • slebetman@yahoo.com

      #3
      Re: Tool for detecting Array overflow

      vashwath@rediff mail.com wrote:[color=blue]
      > Hi all,
      > Is there any free tool available for detecting array overflow? I found
      > one which detects overflow of dynamic arrays. But I need a tool(or a
      > special compiler) which detects static array overflows too.
      >[/color]

      Just do what your teachers always tell you to do. Check your bounds
      before using the array.

      Comment

      • Bjørn Augestad

        #4
        Re: Tool for detecting Array overflow

        vashwath@rediff mail.com wrote:[color=blue]
        > Hi all,
        > Is there any free tool available for detecting array overflow? I found
        > one which detects overflow of dynamic arrays. But I need a tool(or a
        > special compiler) which detects static array overflows too.
        >
        > Thanks
        >[/color]

        On linux you can use valgrind, http://valgrind.kde.org.
        Bjørn

        Comment

        • vashwath@rediffmail.com

          #5
          Re: Tool for detecting Array overflow

          > <OT>[color=blue]
          > Any helpful answer you receive will probably be very compiler-specific.
          > If using gcc, your instance of it may support the -fbounds-check
          > command line option.
          > </OT>
          >[/color]
          Thanks for replying Chris.

          Yes, I am using gcc for compilation.
          I used the options you suggested for the following program

          #include <stdio.h>

          int main()
          {
          int a[10];

          int i;

          for(i=0;i<10;i+ +)
          a[i] = i;


          for(i=0;i<10;i+ +)
          printf("a[%d]= %d ",i,a[i]);

          printf("\n");
          printf("i=%d\n" ,i);

          a[i] = 10;/*Array overflow???*/

          }

          I gave the following command
          gcc -w -Wall -fbounds-check arrBound.c

          But it did not detect the overflow.
          Am i using the options correctly.

          Comment

          • Bjørn Augestad

            #6
            [OT] Re: Tool for detecting Array overflow

            vashwath@rediff mail.com wrote:[color=blue][color=green]
            >> <OT>
            >> Any helpful answer you receive will probably be very compiler-specific.
            >> If using gcc, your instance of it may support the -fbounds-check
            >> command line option.
            >> </OT>
            >>[/color]
            > Thanks for replying Chris.
            >
            > Yes, I am using gcc for compilation.
            > I used the options you suggested for the following program
            >
            > #include <stdio.h>
            >
            > int main()
            > {
            > int a[10];
            >
            > int i;
            >
            > for(i=0;i<10;i+ +)
            > a[i] = i;
            >
            >
            > for(i=0;i<10;i+ +)
            > printf("a[%d]= %d ",i,a[i]);
            >
            > printf("\n");
            > printf("i=%d\n" ,i);
            >
            > a[i] = 10;/*Array overflow???*/
            >
            > }
            >
            > I gave the following command
            > gcc -w -Wall -fbounds-check arrBound.c
            >
            > But it did not detect the overflow.
            > Am i using the options correctly.
            >[/color]


            Check the gcc man page for details regarding -fbounds-check. I have gcc
            4.0.2 prerelease 20050901 (SUSE 10), and my man page states that
            -fbounds-check works for fortran and java only.

            Bjørn

            Comment

            • slebetman@yahoo.com

              #7
              Re: Tool for detecting Array overflow

              vashwath@rediff mail.com wrote:[color=blue][color=green]
              > > <OT>
              > > Any helpful answer you receive will probably be very compiler-specific.
              > > If using gcc, your instance of it may support the -fbounds-check
              > > command line option.
              > > </OT>
              > >[/color]
              > Thanks for replying Chris.
              >
              > Yes, I am using gcc for compilation.
              > I used the options you suggested for the following program
              >
              > #include <stdio.h>
              >
              > int main()
              > {
              > int a[10];
              >
              > int i;
              >
              > for(i=0;i<10;i+ +)
              > a[i] = i;
              >
              >
              > for(i=0;i<10;i+ +)
              > printf("a[%d]= %d ",i,a[i]);
              >
              > printf("\n");
              > printf("i=%d\n" ,i);
              >
              > a[i] = 10;/*Array overflow???*/
              >
              > }
              >
              > I gave the following command
              > gcc -w -Wall -fbounds-check arrBound.c
              >
              > But it did not detect the overflow.
              > Am i using the options correctly.[/color]

              In your code, I never exceed 9. So it did not detect overflow because
              there is no overflow. Just modify it with the following to cause
              overflow:

              int main()
              {
              int a[10];

              int i;

              for(i=0;i<10;i+ +)
              a[i] = i;


              for(i=0;i<10;i+ +)
              printf("a[%d]= %d ",i,a[i]);

              printf("\n");
              printf("i=%d\n" ,i);

              i++; /*Cause overflow!*/
              a[i] = 10;/*Array overflow???*/

              }

              Comment

              • Niklas Norrthon

                #8
                Re: Tool for detecting Array overflow

                "slebetman@yaho o.com" <slebetman@gmai l.com> writes:
                [color=blue]
                > vashwath@rediff mail.com wrote:[color=green]
                > >
                > > Yes, I am using gcc for compilation.
                > > I used the options you suggested for the following program
                > >
                > > #include <stdio.h>
                > >
                > > int main()
                > > {
                > > int a[10];
                > >
                > > int i;
                > >
                > > for(i=0;i<10;i+ +)
                > > a[i] = i;
                > >
                > >
                > > for(i=0;i<10;i+ +)
                > > printf("a[%d]= %d ",i,a[i]);
                > >
                > > printf("\n");
                > > printf("i=%d\n" ,i);
                > >
                > > a[i] = 10;/*Array overflow???*/
                > >
                > > }
                > >
                > > I gave the following command
                > > gcc -w -Wall -fbounds-check arrBound.c
                > >
                > > But it did not detect the overflow.
                > > Am i using the options correctly.[/color]
                >
                > In your code, I never exceed 9. So it did not detect overflow because
                > there is no overflow. Just modify it with the following to cause
                > overflow:[/color]

                If that is the case, could you explain why the last printf
                statement outputs "i=10"?

                /Niklas Norrthon

                Comment

                • Igmar Palsenberg

                  #9
                  Re: Tool for detecting Array overflow

                  Bjørn Augestad wrote:[color=blue]
                  > On linux you can use valgrind, http://valgrind.kde.org.[/color]

                  Which doesn't detect overflows of arrays located on the stack.



                  Igmar

                  Comment

                  • saurabh

                    #10
                    Re: Tool for detecting Array overflow

                    Hi,

                    Try with this code: file name overflow.c

                    #include <stdlib.h>
                    #include <stdio.h>

                    int main ()
                    {
                    int arr[2] = {2,3,4};
                    }

                    On compiling with gcc version 3.4.2, I can see following compilation
                    error message,
                    gcc -fbounds-check overflow.c
                    overflow.c: In function `main':
                    overflow.c:6: warning: excess elements in array initializer
                    overflow.c6: warning: (near initialization for `arr')

                    Thanks & Regards,
                    Saurabh.


                    Igmar Palsenberg wrote:[color=blue]
                    > Bjørn Augestad wrote:[color=green]
                    > > On linux you can use valgrind, http://valgrind.kde.org.[/color]
                    >
                    > Which doesn't detect overflows of arrays located on the stack.
                    >
                    >
                    >
                    > Igmar[/color]

                    Comment

                    • slebetman@yahoo.com

                      #11
                      Re: Tool for detecting Array overflow

                      Niklas Norrthon wrote:[color=blue]
                      > "slebetman@yaho o.com" <slebetman@gmai l.com> writes:
                      >[color=green]
                      > > vashwath@rediff mail.com wrote:[color=darkred]
                      > > >
                      > > > Yes, I am using gcc for compilation.
                      > > > I used the options you suggested for the following program
                      > > >
                      > > > #include <stdio.h>
                      > > >
                      > > > int main()
                      > > > {
                      > > > int a[10];
                      > > >
                      > > > int i;
                      > > >
                      > > > for(i=0;i<10;i+ +)
                      > > > a[i] = i;
                      > > >
                      > > >
                      > > > for(i=0;i<10;i+ +)
                      > > > printf("a[%d]= %d ",i,a[i]);
                      > > >
                      > > > printf("\n");
                      > > > printf("i=%d\n" ,i);
                      > > >
                      > > > a[i] = 10;/*Array overflow???*/
                      > > >
                      > > > }
                      > > >
                      > > > I gave the following command
                      > > > gcc -w -Wall -fbounds-check arrBound.c
                      > > >
                      > > > But it did not detect the overflow.
                      > > > Am i using the options correctly.[/color]
                      > >
                      > > In your code, I never exceed 9. So it did not detect overflow because
                      > > there is no overflow. Just modify it with the following to cause
                      > > overflow:[/color]
                      >
                      > If that is the case, could you explain why the last printf
                      > statement outputs "i=10"?
                      >[/color]

                      Ah, sorry, I missed the fact that the i++ in the for loop does indeed
                      increment i to 10.

                      Comment

                      Working...