Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to find source of buffer overflow

How to find source of buffer overflow

Scheduled Pinned Locked Moved C / C++ / MFC
announcementc++data-structuresdebuggingperformance
8 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    WernerP
    wrote on last edited by
    #1

    VC++ Windows XP Hi, I have to maintain a large application which sometimes crashes at the end. The cause is probably a buffer overflow somewhere: From time to time a system error message showed up which said that the code segment had been affected. I would like to find the source of the overflow but couldn't figure out where it could be. It only happens in the release version. I think this is due to the different initialization of debug memory with CD DD and so on. I think it would be easier, when I could run a debug session with heap and stack being initialized in the same way as in the release version. Is there any possibility to get that? Or is there a tool which can show me e.g.

    slice of memory on the heap | origin routine | virtual addr begin | virtual addr end |
    pFoo bar 0x00002000 0x20000000

    Thank you Regards Werner

    E C A 4 Replies Last reply
    0
    • W WernerP

      VC++ Windows XP Hi, I have to maintain a large application which sometimes crashes at the end. The cause is probably a buffer overflow somewhere: From time to time a system error message showed up which said that the code segment had been affected. I would like to find the source of the overflow but couldn't figure out where it could be. It only happens in the release version. I think this is due to the different initialization of debug memory with CD DD and so on. I think it would be easier, when I could run a debug session with heap and stack being initialized in the same way as in the release version. Is there any possibility to get that? Or is there a tool which can show me e.g.

      slice of memory on the heap | origin routine | virtual addr begin | virtual addr end |
      pFoo bar 0x00002000 0x20000000

      Thank you Regards Werner

      E Offline
      E Offline
      Eugen Podsypalnikov
      wrote on last edited by
      #2

      You could compile your project without optimization (debug) and link it with the debug "pdb" information :) (These are the project settings) Secondly, you could try to restrict the RT reproducing context as possible :)

      virtual void BeHappy() = 0;

      1 Reply Last reply
      0
      • W WernerP

        VC++ Windows XP Hi, I have to maintain a large application which sometimes crashes at the end. The cause is probably a buffer overflow somewhere: From time to time a system error message showed up which said that the code segment had been affected. I would like to find the source of the overflow but couldn't figure out where it could be. It only happens in the release version. I think this is due to the different initialization of debug memory with CD DD and so on. I think it would be easier, when I could run a debug session with heap and stack being initialized in the same way as in the release version. Is there any possibility to get that? Or is there a tool which can show me e.g.

        slice of memory on the heap | origin routine | virtual addr begin | virtual addr end |
        pFoo bar 0x00002000 0x20000000

        Thank you Regards Werner

        E Offline
        E Offline
        Eugen Podsypalnikov
        wrote on last edited by
        #3

        Try also to make the following test (may be in a small separate application) :

        {
        int* pInt = new int[20];
        pInt = new int[10];
        pInt = new int[30];
        pInt = new int[10];
        }

        ...an then pass it to your diagnostic tool :)

        virtual void BeHappy() = 0;

        W 1 Reply Last reply
        0
        • W WernerP

          VC++ Windows XP Hi, I have to maintain a large application which sometimes crashes at the end. The cause is probably a buffer overflow somewhere: From time to time a system error message showed up which said that the code segment had been affected. I would like to find the source of the overflow but couldn't figure out where it could be. It only happens in the release version. I think this is due to the different initialization of debug memory with CD DD and so on. I think it would be easier, when I could run a debug session with heap and stack being initialized in the same way as in the release version. Is there any possibility to get that? Or is there a tool which can show me e.g.

          slice of memory on the heap | origin routine | virtual addr begin | virtual addr end |
          pFoo bar 0x00002000 0x20000000

          Thank you Regards Werner

          C Offline
          C Offline
          CPallini
          wrote on last edited by
          #4

          See the Newcomer's classic "Surviving the Release Version" :)

          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
          This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
          [My articles]

          1 Reply Last reply
          0
          • W WernerP

            VC++ Windows XP Hi, I have to maintain a large application which sometimes crashes at the end. The cause is probably a buffer overflow somewhere: From time to time a system error message showed up which said that the code segment had been affected. I would like to find the source of the overflow but couldn't figure out where it could be. It only happens in the release version. I think this is due to the different initialization of debug memory with CD DD and so on. I think it would be easier, when I could run a debug session with heap and stack being initialized in the same way as in the release version. Is there any possibility to get that? Or is there a tool which can show me e.g.

            slice of memory on the heap | origin routine | virtual addr begin | virtual addr end |
            pFoo bar 0x00002000 0x20000000

            Thank you Regards Werner

            A Offline
            A Offline
            Adam Roderick J
            wrote on last edited by
            #5

            I prefer WinDbg, very effective in finding the application crashes, handle leaks and all([^])

            Величие не Бога может быть недооценена.

            W 1 Reply Last reply
            0
            • E Eugen Podsypalnikov

              Try also to make the following test (may be in a small separate application) :

              {
              int* pInt = new int[20];
              pInt = new int[10];
              pInt = new int[30];
              pInt = new int[10];
              }

              ...an then pass it to your diagnostic tool :)

              virtual void BeHappy() = 0;

              W Offline
              W Offline
              WernerP
              wrote on last edited by
              #6

              Dear Eugen, the diagnostic tool which I would find very useful would be one, which can show me something like

              variable | chunk of heap start | chunk of heap end | length of heap | allocated by (method signature)
              pFoo 0x00002000 0x20000000 536862720 heapcrusher

              because I suspect, that the point in the program, where the exception happens is not the one which caused the trouble, but another, which caused a buffer overflow. Sometimes the app crashed at the end and signaled a segment fault. I also tried to debug the app as release version as you suggested but couldn't find out, why it crashed at the point, where it did. Do you know any which can do that? PS is it actually possible to see variable values in the debugger when I debug the release version? I thought there is no way. Thank you regards Werner

              E 1 Reply Last reply
              0
              • A Adam Roderick J

                I prefer WinDbg, very effective in finding the application crashes, handle leaks and all([^])

                Величие не Бога может быть недооценена.

                W Offline
                W Offline
                WernerP
                wrote on last edited by
                #7

                Dear Adam, please refer to my answer to Eugen, thank you :) Werner

                1 Reply Last reply
                0
                • W WernerP

                  Dear Eugen, the diagnostic tool which I would find very useful would be one, which can show me something like

                  variable | chunk of heap start | chunk of heap end | length of heap | allocated by (method signature)
                  pFoo 0x00002000 0x20000000 536862720 heapcrusher

                  because I suspect, that the point in the program, where the exception happens is not the one which caused the trouble, but another, which caused a buffer overflow. Sometimes the app crashed at the end and signaled a segment fault. I also tried to debug the app as release version as you suggested but couldn't find out, why it crashed at the point, where it did. Do you know any which can do that? PS is it actually possible to see variable values in the debugger when I debug the release version? I thought there is no way. Thank you regards Werner

                  E Offline
                  E Offline
                  Eugen Podsypalnikov
                  wrote on last edited by
                  #8

                  Hallo Werner, 0. Yes, you can see any value at the debugging of your release project now :) 1. The message of the tool is different now :) 2. When you say "crashes at the end" - please try the following code by your tool:

                  {
                  int* pInt = new int[30];
                  delete pInt;
                  for (int i = 0; i < 100; i++) {
                  int* pChar = new char[1024];
                  delete pChar;
                  delete pChar;
                  }
                  delete pInt;
                  }

                  3. Is there a way to reduce the application and reproduce the effect ? :)

                  virtual void BeHappy() = 0;

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups