Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. Buffer overflow not caught after executing a QDialog!
QtWS25 Last Chance

Buffer overflow not caught after executing a QDialog!

Scheduled Pinned Locked Moved Unsolved C++ Gurus
debug error
10 Posts 3 Posters 792 Views
  • 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.
  • J Offline
    J Offline
    jdent
    wrote on last edited by jdent
    #1

    Hi,
    Using Visual Studio 2022 version 17.9.5, with the following compiler/linker settings:

    /Zi /fsanitize=address /RTCs /INCREMENTAL:NO

    the compiler will at runtime catch code like this:

    char x[10];
    x[30] = 50;
    

    But not if this code follows a call to a QDialog::exec()!!! For some reason the stack is not checked after the control returns from an exec() call!! could it be a thread related problem?

    Christian EhrlicherC 1 Reply Last reply
    0
    • J jdent

      Hi,
      Using Visual Studio 2022 version 17.9.5, with the following compiler/linker settings:

      /Zi /fsanitize=address /RTCs /INCREMENTAL:NO

      the compiler will at runtime catch code like this:

      char x[10];
      x[30] = 50;
      

      But not if this code follows a call to a QDialog::exec()!!! For some reason the stack is not checked after the control returns from an exec() call!! could it be a thread related problem?

      Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by Christian Ehrlicher
      #2

      @jdent said in Buffer overflow not caught after executing a QDialog!:

      could it be a thread related problem?

      How should we know?
      Since you must not access a Qt gui element outside the main thread I don't see what threads might have to do with.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      J 1 Reply Last reply
      3
      • Christian EhrlicherC Christian Ehrlicher

        @jdent said in Buffer overflow not caught after executing a QDialog!:

        could it be a thread related problem?

        How should we know?
        Since you must not access a Qt gui element outside the main thread I don't see what threads might have to do with.

        J Offline
        J Offline
        jdent
        wrote on last edited by
        #3

        @Christian-Ehrlicher Well it was just a thought... What could be happening?

        Christian EhrlicherC 1 Reply Last reply
        0
        • J jdent

          @Christian-Ehrlicher Well it was just a thought... What could be happening?

          Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @jdent said in Buffer overflow not caught after executing a QDialog!:

          What could be happening?

          It is a race condition. So it may eat kittens.
          You **must not ** access the gui from outside the main thread.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          J 1 Reply Last reply
          3
          • Christian EhrlicherC Christian Ehrlicher

            @jdent said in Buffer overflow not caught after executing a QDialog!:

            What could be happening?

            It is a race condition. So it may eat kittens.
            You **must not ** access the gui from outside the main thread.

            J Offline
            J Offline
            jdent
            wrote on last edited by jdent
            #5

            @Christian-Ehrlicher I am not accessing the GUI from outside the main thread, I am just calling exec() on QDialog!

            Here is the offending code:

                int locationIndex = locationView->currentIndex();
                std::unique_ptr<PasswordDetailsDlg> dlg{ new PasswordDetailsDlg{ model, locationIndex, this } };
                int accepted = dlg->exec();
                
                if (accepted == 1) {
                    model->select();
                    int lastRow = model->rowCount() - 1;
                    passwordsView->setFocus();
                    passwordsView->selectRow(0);
                    passwordsView->scrollToTop();
                }
            
                char x[10];
                x[0x10] = 5;  // this overflow is not caught!! -- if I remove the dlg->exec() it will be caught!!!
            
            
            JonBJ 1 Reply Last reply
            0
            • J jdent

              @Christian-Ehrlicher I am not accessing the GUI from outside the main thread, I am just calling exec() on QDialog!

              Here is the offending code:

                  int locationIndex = locationView->currentIndex();
                  std::unique_ptr<PasswordDetailsDlg> dlg{ new PasswordDetailsDlg{ model, locationIndex, this } };
                  int accepted = dlg->exec();
                  
                  if (accepted == 1) {
                      model->select();
                      int lastRow = model->rowCount() - 1;
                      passwordsView->setFocus();
                      passwordsView->selectRow(0);
                      passwordsView->scrollToTop();
                  }
              
                  char x[10];
                  x[0x10] = 5;  // this overflow is not caught!! -- if I remove the dlg->exec() it will be caught!!!
              
              
              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by JonB
              #6

              @jdent
              You have said you are calling QDialog::exec() (or for that matter anything QDialog::... from a secondary thread. You must not do that in Qt, only from the main/UI thread. If it works at all you are "lucky". Or have you not said you are doing that, but you asked about "could it be a thread related problem?"? If you are not using your own threads it is not a thread issue, so I am not clear.

              J 1 Reply Last reply
              0
              • JonBJ JonB

                @jdent
                You have said you are calling QDialog::exec() (or for that matter anything QDialog::... from a secondary thread. You must not do that in Qt, only from the main/UI thread. If it works at all you are "lucky". Or have you not said you are doing that, but you asked about "could it be a thread related problem?"? If you are not using your own threads it is not a thread issue, so I am not clear.

                J Offline
                J Offline
                jdent
                wrote on last edited by jdent
                #7

                @JonB I am not using threads .... I just thought that threads might be involved in the exec() called!!

                I did not say:

                "You have said you are calling QDialog::exec() (or for that matter anything QDialog::... from a secondary thread."

                I am trying to figure out what is causing the compiler to miss the overflow access

                Again, to turn this conversation to the real issue:

                int locationIndex = locationView->currentIndex();
                    std::unique_ptr<PasswordDetailsDlg> dlg{ new PasswordDetailsDlg{ model, locationIndex, this } };
                    int accepted = dlg->exec();
                    
                    if (accepted == 1) {
                        model->select();
                        int lastRow = model->rowCount() - 1;
                        passwordsView->setFocus();
                        passwordsView->selectRow(0);
                        passwordsView->scrollToTop();
                    }
                char x[10];
                 x[0x10] = 5;  // this overflow is not caught!! -- if I remove the dlg->exec() it will be caught!!!
                

                IF I remove the call to dlg->exec() then the overflow is caught by the compiler!!!
                Why?
                what does calling exec() do to this stack overflow?

                Christian EhrlicherC 1 Reply Last reply
                0
                • J jdent

                  @JonB I am not using threads .... I just thought that threads might be involved in the exec() called!!

                  I did not say:

                  "You have said you are calling QDialog::exec() (or for that matter anything QDialog::... from a secondary thread."

                  I am trying to figure out what is causing the compiler to miss the overflow access

                  Again, to turn this conversation to the real issue:

                  int locationIndex = locationView->currentIndex();
                      std::unique_ptr<PasswordDetailsDlg> dlg{ new PasswordDetailsDlg{ model, locationIndex, this } };
                      int accepted = dlg->exec();
                      
                      if (accepted == 1) {
                          model->select();
                          int lastRow = model->rowCount() - 1;
                          passwordsView->setFocus();
                          passwordsView->selectRow(0);
                          passwordsView->scrollToTop();
                      }
                  char x[10];
                   x[0x10] = 5;  // this overflow is not caught!! -- if I remove the dlg->exec() it will be caught!!!
                  

                  IF I remove the call to dlg->exec() then the overflow is caught by the compiler!!!
                  Why?
                  what does calling exec() do to this stack overflow?

                  Christian EhrlicherC Offline
                  Christian EhrlicherC Offline
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @jdent said in Buffer overflow not caught after executing a QDialog!:

                  aught by the compiler!!!

                  Maybe adding some more '!' will help?

                  You should ask the compiler devs, Qt is just a c++ library, not a compiler.

                  Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                  Visit the Qt Academy at https://academy.qt.io/catalog

                  J 1 Reply Last reply
                  0
                  • Christian EhrlicherC Christian Ehrlicher

                    @jdent said in Buffer overflow not caught after executing a QDialog!:

                    aught by the compiler!!!

                    Maybe adding some more '!' will help?

                    You should ask the compiler devs, Qt is just a c++ library, not a compiler.

                    J Offline
                    J Offline
                    jdent
                    wrote on last edited by jdent
                    #9

                    @Christian-Ehrlicher I have reported this to Microsoft... excuse me for so many !! No need to get sarcastic about it. ! means frustration, that's all

                    JonBJ 1 Reply Last reply
                    0
                    • J jdent

                      @Christian-Ehrlicher I have reported this to Microsoft... excuse me for so many !! No need to get sarcastic about it. ! means frustration, that's all

                      JonBJ Offline
                      JonBJ Offline
                      JonB
                      wrote on last edited by JonB
                      #10

                      @jdent
                      As @Christian-Ehrlicher says, who knows, behaviour may be compiler-specific and it does not claim to check everything, I think. My own guess is that the call to showing the dialog avoiding the detection may well be "coincidence", nothing to do with the specific call, many other things might cause it to skip.

                      Under Ubuntu, Qt 5, gcc and .pro file having

                      CONFIG+=sanitizer
                      CONFIG+=sanitize_address
                      

                      it does report a SIGABRT on code like yours, whether I put in a QDialog and/or exec() or not. I do not know whether you can use those CONFIG lines from Qt with MSVC or not.

                      One tiny thing: just in case MSVC is "optimizing out" your x code completely because it has no effect (e.g. gcc warns "unused variable"), add something which uses x after your code.

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved