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

error with sizeof("commit") in function mysql_commit

Details

    • Bug
    • Status: Closed (View Workflow)
    • Minor
    • Resolution: Fixed
    • 2.3.7
    • 3.1.3
    • None
    • None
    • linux ppc64/window10 x64

    Description

      Hi team,
      I want to connect a drds database with library mariadb-connector-c-2.3.7-src. when i use mysql_commit function ,i got an error like this:

       mysql_error:You have an error in you SQL syntax:Error occurs around this fragment : {COMMIT 
       mysql_errno:1064
      

      I found that the mysql_commit function uses the sizeof("commit") , the value is 7.

      3363 my_bool STDCALL mysql_commit(MYSQL *mysql)
      3364 {
      3365   DBUG_ENTER("mysql_commit");
      3366   DBUG_RETURN((my_bool)mysql_real_query(mysql, "COMMIT", sizeof("COMMIT")));
      3367 }
      3368 
      3369 my_bool STDCALL mysql_rollback(MYSQL *mysql)
      3370 {
      3371   DBUG_ENTER("mysql_rollback");
      3372   DBUG_RETURN((my_bool)mysql_real_query(mysql, "ROLLBACK", sizeof("ROLLBACK")));
      3373 }
      

      and the libmysql.c in library mysql-5.5.37/libmysql ,the implement is

       4745 my_bool STDCALL mysql_commit(MYSQL * mysql)
      4746 {
      4747   DBUG_ENTER("mysql_commit");
      4748   DBUG_RETURN((my_bool) mysql_real_query(mysql, "commit", 6));
      4749 }
      

      when i use libmysql, the error is fixed.

      the poco c++ library use length() function ,and the error is fixed too.

        sql = "commit";
          rc = mysql_real_query(hsession, sql.c_str(), static_cast<unsigned long>(sql.length()));
          if (rc != 0)
          {
              print_mysql_error();
          }
          assert(rc == 0);
      

      I'm not sure if it's a bug, so I want to get an answer.

      Attachments

        Activity

          pali Pali added a comment -

          sizeof("COMMIT") is 7 and strlen("COMMIT") is 6 by definition of C language. 6 is length of string "COMMIT" and 7 is size of buffer needed for storing null-term string "COMMIT.

          According to both MariaDB and MySQL documentation of mysql_real_query() function, caller should pass length of string in bytes and not size of needed for storing null-term string. See:

          https://mariadb.com/kb/en/library/mysql_real_query/
          https://dev.mysql.com/doc/en/mysql-real-query.html

          So correct implementation should use either

          sizeof("COMMIT")-1
          

          or

          strlen("COMMIT")
          

          So, could you fix current implementation of mysql_commit and mysql_rollback?

          pali Pali added a comment - sizeof("COMMIT") is 7 and strlen("COMMIT") is 6 by definition of C language. 6 is length of string "COMMIT" and 7 is size of buffer needed for storing null-term string "COMMIT. According to both MariaDB and MySQL documentation of mysql_real_query() function, caller should pass length of string in bytes and not size of needed for storing null-term string. See: https://mariadb.com/kb/en/library/mysql_real_query/ https://dev.mysql.com/doc/en/mysql-real-query.html So correct implementation should use either sizeof("COMMIT")-1 or strlen("COMMIT") So, could you fix current implementation of mysql_commit and mysql_rollback ?
          anklean anklean added a comment -

          ok,i'd like to fix it

          anklean anklean added a comment - ok,i'd like to fix it
          pali Pali added a comment -

          anklean: Are you going to fix it? It should be really simple, just adds -1 after sizeof().

          pali Pali added a comment - anklean : Are you going to fix it? It should be really simple, just adds -1 after sizeof() .
          georg Georg Richter added a comment -

          This was already fixed:
          commit 86829abc874f572f11bc2e568c714e5d3f7804bb
          Merge: 7ba08bc 9cb1322
          Author: Georg Richter <9EOR9@users.noreply.github.com>
          Date: Fri Jul 5 08:24:21 2019 +0200

          Merge pull request #115 from anklean/3.1

          fix bug CONC-400 error with sizeof("commit") in function mysql_commit

          georg Georg Richter added a comment - This was already fixed: commit 86829abc874f572f11bc2e568c714e5d3f7804bb Merge: 7ba08bc 9cb1322 Author: Georg Richter <9EOR9@users.noreply.github.com> Date: Fri Jul 5 08:24:21 2019 +0200 Merge pull request #115 from anklean/3.1 fix bug CONC-400 error with sizeof("commit") in function mysql_commit
          pali Pali added a comment -

          Great! I did not know that this was already fixed as in this issue was still in open state and there was no update.

          pali Pali added a comment - Great! I did not know that this was already fixed as in this issue was still in open state and there was no update.

          People

            georg Georg Richter
            anklean anklean
            Votes:
            0 Vote for this issue
            Watchers:
            3 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.