Uploaded image for project: 'MariaDB Connector/C'
  1. MariaDB Connector/C
  2. CONC-590

c-connector bind / execute mess up memory allocation

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Won't Fix
    • 3.0.2
    • N/A
    • archlinux kernel 5.2.13
      gcc (GCC) 9.1.0
      mariadb 10.7.3 downloaded and compiled on host
      same behavior on upgraded version 10.4.8

    Description

      i'm using mariadb c-connector with prepare, bind and execute. it works usualy. but one case end up in "corrupted unsorted chunks" and core dumping when freeing bind buffer. i suggest the whole malloc organisation is messed up after calling mysql_stmt_execute(). my test's MysqlDynamic.c show:

      • the problem only is connected to x509cert variable bound by bnd[9]
      • freeing memory only fails if bnd[9].is_null = 0, if is_null execute end normally
      • freeing memory (using FreeStmt()) after bind and before execute end normally
      • print of bnd[9].buffer before execute show (void*) is connected to the correct string buffer
      • same behavior for setting bnd[9].buffer_length to STMT_INDICATOR_NTS or strlen()
      • other similar bindings (picture, bnd[10]) do not lead to corrupted memory and core dump.

      for more detailed explanation please see link stackoverflow.
      i'm opening this issue after i did not get any useful answers.

      please verify code MysqlDynamic.c and compile it. i especialy wrote for debugging purposes after running randomly into troubles. please let me know if <MysqlDynamic -i> run without problems.

      thank you

      Attachments

        1. cert.pem
          2 kB
        2. ch.png
          ch.png
          0.2 kB
        3. MysqlDynamic.c
          20 kB

        Activity

          georg Georg Richter added a comment -

          Please provide a short reproducible test case, but not 645 lines of code (where most of the code is unrelated to your problem).
          For an example check the tests in unittest/libmariadb, e.g. test_conc67

          georg Georg Richter added a comment - Please provide a short reproducible test case, but not 645 lines of code (where most of the code is unrelated to your problem). For an example check the tests in unittest/libmariadb, e.g. test_conc67
          ralf.gebhardt Ralf Gebhardt added a comment -

          Hi SwissGeorge, I am changing the priority until we got a reproducible test case.

          ralf.gebhardt Ralf Gebhardt added a comment - Hi SwissGeorge , I am changing the priority until we got a reproducible test case.

          why are you doing

          		bnd[2].buffer_length = STMT_INDICATOR_NTS;
          

          ? Can you point to the documentation where you took it from?

          serg Sergei Golubchik added a comment - why are you doing bnd[2].buffer_length = STMT_INDICATOR_NTS; ? Can you point to the documentation where you took it from?
          SwissGeorge Juerg Oehler added a comment -

          hi sergei goulubchik

          thank you for the hint. i changed my code to strlen(). now the program runs stable.

          20 years ago i was using oracles, sybase and informix functionalities what they called Dynamic SQL. hence i tried to understand the way i have to use your functionalties. intention is to bind my buffer to database structure and use it by just move the pointer through the array of buffers. i went through any of your documents including Connector/C Types where i found <STMT_INDICATOR_NTS>.

          after reading all of the documention around bind/execute i really do not feel to have understood all the features good enough in order to write stable applications. i tried to ask for more documentations alike c-type db-type relation. this because of i do not understand why i have to declare my c buffer as <MYSQL_TYPE_VARCHAR>. c only knows char and arrays of it. the database datatype is available after mysql_stmt_prepare, i do bind them together thereafter.

          i was understanding there are two functions for mysql_stmt_bind; parameter for writing to the db and result for reading. to me it is obvious to use different bindings for input and output. but MYSQL_BIND in confused me as not all attributes are clear in effect to me. furthermore i discoverd implicit conversion c-string to DATE/TIME db structure.

          i so changed to <try and error> i try to avoid.

          why did i use <<STMT_INDICATOR_NTS> and wrote this issue as <need feedback>?

          • mysql_stmt_bind did not fail
          • most cases using <STMT_INDICATOR_NTS> works well, as ingle call of bind/exec works always without messing up memory.
          • work always was done .. db touples were correct
          • in a few cases the memory was messed up

          BTW: <STMT_INDICATOR_NTS> would reduce mysql_stmt_bind calls substantialy.

          please let me know for which cases <STMT_INDICATOR_NTS> is supported. if also supported for row-wise binding, i continue to provide a short testversion asked by Georg Richter. It looks like all single calls work well - recurring calls to bind/execute cause the problem.

          it would be great if somebody could verify and some information to the description MYSQL_BIND in . please verify <is_null Pointer which indicates if column is NULL (not used for parameters)>. my test's show a <string with length and is_null = 1> will be stored as NULL - which is great. in what cases is <length_value Used if length pointer is NULL> used (input / output / both)?

          SwissGeorge Juerg Oehler added a comment - hi sergei goulubchik thank you for the hint. i changed my code to strlen(). now the program runs stable. 20 years ago i was using oracles, sybase and informix functionalities what they called Dynamic SQL. hence i tried to understand the way i have to use your functionalties. intention is to bind my buffer to database structure and use it by just move the pointer through the array of buffers. i went through any of your documents including Connector/C Types where i found <STMT_INDICATOR_NTS>. after reading all of the documention around bind/execute i really do not feel to have understood all the features good enough in order to write stable applications. i tried to ask for more documentations alike c-type db-type relation . this because of i do not understand why i have to declare my c buffer as <MYSQL_TYPE_VARCHAR>. c only knows char and arrays of it. the database datatype is available after mysql_stmt_prepare, i do bind them together thereafter. i was understanding there are two functions for mysql_stmt_bind; parameter for writing to the db and result for reading. to me it is obvious to use different bindings for input and output. but MYSQL_BIND in confused me as not all attributes are clear in effect to me. furthermore i discoverd implicit conversion c-string to DATE/TIME db structure. i so changed to <try and error> i try to avoid. why did i use <<STMT_INDICATOR_NTS> and wrote this issue as <need feedback>? mysql_stmt_bind did not fail most cases using <STMT_INDICATOR_NTS> works well, as ingle call of bind/exec works always without messing up memory. work always was done .. db touples were correct in a few cases the memory was messed up BTW: <STMT_INDICATOR_NTS> would reduce mysql_stmt_bind calls substantialy. please let me know for which cases <STMT_INDICATOR_NTS> is supported. if also supported for row-wise binding, i continue to provide a short testversion asked by Georg Richter. It looks like all single calls work well - recurring calls to bind/execute cause the problem. it would be great if somebody could verify and some information to the description MYSQL_BIND in . please verify <is_null Pointer which indicates if column is NULL (not used for parameters)>. my test's show a <string with length and is_null = 1> will be stored as NULL - which is great. in what cases is <length_value Used if length pointer is NULL> used (input / output / both)?
          SwissGeorge Juerg Oehler added a comment -

          hi Georg Richter

          i was working on your request to extract a test case reproducing the issue.
          then i got the question from sergei goulubchik why i'm using <bnd[2].buffer_length = STMT_INDICATOR_NTS;>.

          now i'm hanging in the ropes not knowing if i was missunderstanding Connector/C Types and Definitions. if so, there is no motivation to continue debugging. otherwise i'll be glad to give something back to the community.

          thank you for short answer.

          SwissGeorge Juerg Oehler added a comment - hi Georg Richter i was working on your request to extract a test case reproducing the issue. then i got the question from sergei goulubchik why i'm using <bnd [2] .buffer_length = STMT_INDICATOR_NTS;>. now i'm hanging in the ropes not knowing if i was missunderstanding Connector/C Types and Definitions . if so, there is no motivation to continue debugging. otherwise i'll be glad to give something back to the community. thank you for short answer.
          georg Georg Richter added a comment -

          Can't reproduce issue.

          georg Georg Richter added a comment - Can't reproduce issue.

          People

            georg Georg Richter
            SwissGeorge Juerg Oehler
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.