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 793 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 8 Apr 2024, 00:09 last edited by jdent 4 Aug 2024, 00:10
    #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?

    C 1 Reply Last reply 8 Apr 2024, 04:18
    0
    • J jdent
      8 Apr 2024, 00:09

      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?

      C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 8 Apr 2024, 04:18 last edited by Christian Ehrlicher 4 Aug 2024, 04:37
      #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 8 Apr 2024, 11:25
      3
      • C Christian Ehrlicher
        8 Apr 2024, 04:18

        @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 8 Apr 2024, 11:25 last edited by
        #3

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

        C 1 Reply Last reply 8 Apr 2024, 11:36
        0
        • J jdent
          8 Apr 2024, 11:25

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

          C Offline
          C Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on 8 Apr 2024, 11:36 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 8 Apr 2024, 11:41
          3
          • C Christian Ehrlicher
            8 Apr 2024, 11:36

            @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 8 Apr 2024, 11:41 last edited by jdent 4 Aug 2024, 11:44
            #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!!!
            
            
            J 1 Reply Last reply 8 Apr 2024, 11:45
            0
            • J jdent
              8 Apr 2024, 11:41

              @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!!!
              
              
              J Offline
              J Offline
              JonB
              wrote on 8 Apr 2024, 11:45 last edited by JonB 4 Aug 2024, 11:47
              #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 8 Apr 2024, 11:49
              0
              • J JonB
                8 Apr 2024, 11:45

                @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 8 Apr 2024, 11:49 last edited by jdent 4 Aug 2024, 11:57
                #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?

                C 1 Reply Last reply 8 Apr 2024, 11:58
                0
                • J jdent
                  8 Apr 2024, 11:49

                  @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?

                  C Offline
                  C Offline
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on 8 Apr 2024, 11:58 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 8 Apr 2024, 12:04
                  0
                  • C Christian Ehrlicher
                    8 Apr 2024, 11:58

                    @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 8 Apr 2024, 12:04 last edited by jdent 4 Aug 2024, 12:10
                    #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

                    J 1 Reply Last reply 8 Apr 2024, 12:11
                    0
                    • J jdent
                      8 Apr 2024, 12:04

                      @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

                      J Offline
                      J Offline
                      JonB
                      wrote on 8 Apr 2024, 12:11 last edited by JonB 4 Aug 2024, 12:13
                      #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

                      1/10

                      8 Apr 2024, 00:09

                      • Login

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