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

mariadb_stmt_execute_direct of queries with parameters

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Fixed
    • None
    • 3.0.1
    • None
    • None
    • C/C built from current master branch, and server built from current 10.2 branch

    Description

      Using mariadb_stmt_execute_direct of queries with parameters simply crashes the application.
      The crash occurs in mariadb_stmt_execute_direct call, in line:752 of mariadb_stmt.c
      if (indicator == STMT_INDICATOR_NTS ||
      (!stmt->row_size && stmt->params[i].length[j] == (unsigned long)-1))

      #include <stdio.h>

      #include <mysql.h>

      #define NUMBER_OF_TEST_LOOPS 10

      #ifndef OK

      1. define OK 0
        #endif
        #ifndef FAIL
      2. define FAIL 1
        #endif
        #ifndef SKIP
      3. define SKIP -1
        #endif
        #ifndef FALSE
      4. define FALSE 0
        #endif
        #ifndef TRUE
      5. define TRUE 1
        #endif

      #define check_stmt_rc(rc, stmt) \
      if (rc)\
      {\
      diag("Error: %s (%s: %d)", mysql_stmt_error(stmt), _FILE, __LINE_);\
      return(FAIL);\
      }

      #define check_mysql_rc(rc, mysql) \
      if (rc)\
      {\
      diag("Error (%d): %s (%d) in %s line %d", rc, mysql_error(mysql), \
      mysql_errno(mysql), _FILE, __LINE_);\
      return(FAIL);\
      }

      void diag(char const *fmt, ...);
      int main(int argc, char *argv)
      {
      MYSQL *ma;
      MYSQL_STMT *stmt;
      MYSQL_BIND bind[2];
      unsigned long length[2];
      my_bool is_null[2], error[2];
      int i, id, param_count= 1;

      ma = mysql_init(NULL);
      if (!mysql_real_connect(ma, "localhost", "root", "root", "test", 3308, NULL, 0))

      { printf("Could not connect: %s\n", mysql_error(ma)); exit(1); }

      else

      { printf("Server info %s\nClient info: %s\n", mysql_get_server_info(ma), mysql_get_client_info()); }

      stmt = mysql_stmt_init(ma);

      memset(bind, '\0', sizeof(bind));
      memset(is_null, '\0', sizeof(is_null));
      memset(length, '\0', sizeof(length));
      memset(error, '\0', sizeof(error));

      bind[0].buffer_type = MYSQL_TYPE_LONG;
      bind[0].buffer = (void *)&id;
      bind[0].buffer_length = 4;
      bind[0].is_null = &is_null[0];
      bind[0].length = &length[0];
      bind[0].error = &error[0];

      mysql_stmt_attr_set(stmt, STMT_ATTR_PREBIND_PARAMS, &param_count);
      check_stmt_rc(mysql_stmt_bind_param(stmt, bind), stmt);
      check_stmt_rc(mariadb_stmt_execute_direct(stmt, "SELECT ?", strlen("SELECT ?")), stmt);
      check_stmt_rc(mysql_stmt_store_result(stmt), stmt);
      check_stmt_rc(mysql_stmt_free_result(stmt), stmt);

      mysql_stmt_close(stmt);
      mysql_close(ma);

      exit(0);
      }

      Attachments

        Activity

          People

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