Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-5181

incorrect binary search in remove_status_vars()

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Critical
    • Resolution: Fixed
    • Affects Version/s: 10.0.4, 5.5.33a
    • Fix Version/s: 5.5.34, 10.0.6
    • Component/s: None
    • Labels:

      Description

      On INSTALL SONAME 'ha_tokudb.so' when TokuDB cannot be installed (for example, because transparent hugepages are enabled), MariaDB hangs.

      The reason is the remove_status_vars() function that has incorrectly implemented binary search to remove plugin variables from the all-variables list. The code

            for (; b-a > 0; c= (a+b)/2)
            {
              res= show_var_cmp(list, all+c);
              if (res < 0)
                b= c;
              else if (res > 0)
                a= c;
              else
                break;
            }
      

      in my test, a=129, b=130. So, c=129, in comparison I get res > 0, and the loop continues till infinity.

        Gliffy Diagrams

          Attachments

            Activity

            Hide
            pomyk Patryk Pomykalski added a comment - - edited

            I came up with something like this:

            — sql/sql_show.cc 2013-07-16 17:09:54 +0000
            +++ sql/sql_show.cc 2013-11-05 21:59:41 +0000
            @@ -2550,17 +2550,18 @@

            for (; list->name; list++)
            {

            • int res= 0, a= 0, b= all_status_vars.elements, c= (a+b)/2;
            • for (; b-a > 0; c= (a+b)/2)
              + int res= 0, a= 0, b= all_status_vars.elements, c;
              + do { + c= (a+b)/2; res= show_var_cmp(list, all+c); if (res < 0) - b= c; + b= c - 1; else if (res > 0) - a= c; + a= c + 1; else break; - }

              + } while (b >= a && a < all_status_vars.elements);
              if (res == 0)
              all[c].type= SHOW_UNDEF;
              }

            Show
            pomyk Patryk Pomykalski added a comment - - edited I came up with something like this: — sql/sql_show.cc 2013-07-16 17:09:54 +0000 +++ sql/sql_show.cc 2013-11-05 21:59:41 +0000 @@ -2550,17 +2550,18 @@ for (; list->name; list++) { int res= 0, a= 0, b= all_status_vars.elements, c= (a+b)/2; for (; b-a > 0; c= (a+b)/2) + int res= 0, a= 0, b= all_status_vars.elements, c; + do { + c= (a+b)/2; res= show_var_cmp(list, all+c); if (res < 0) - b= c; + b= c - 1; else if (res > 0) - a= c; + a= c + 1; else break; - } + } while (b >= a && a < all_status_vars.elements); if (res == 0) all [c] .type= SHOW_UNDEF; }
            Hide
            bar Alexander Barkov added a comment -

            Pushed into 5.1, 5.2, 5.3, 5.5, 10.0-base.

            Show
            bar Alexander Barkov added a comment - Pushed into 5.1, 5.2, 5.3, 5.5, 10.0-base.

              People

              • Assignee:
                bar Alexander Barkov
                Reporter:
                serg Sergei Golubchik
              • Votes:
                1 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: