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

Wrong result if bound numeric buffer is bigger than field size

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Minor
    • Resolution: Not a Bug
    • None
    • N/A
    • None
    • None

    Description

      If to bind , for example, bit(16) field as MYSQL_TYPE_LONG, Connector/C will copy only 2 bytes to the buffer when fetches the row. Thus application can get basically wrong value.

      mysql_query(ma, "DROP TABLE IF EXISTS `copying_bug`");
      mysql_query(ma, "CREATE TABLE `copying_bug` (`a` bit(16) NOT NULL)");
      mysql_query(ma, "INSERT INTO `copying_bug` (`a`) VALUES(0)");

      st= mysql_stmt_init(ma);

      val= 0xffffffff;

      bind.buffer_length= 4;
      bind.buffer= &val;
      bind.buffer_type= MYSQL_TYPE_LONG;
      bind.length= &bind.length_value;
      bind.is_null= NULL;
      bind.error= NULL;

      mysql_stmt_prepare(st, "SELECT a FROM copying_bug", strlen("SELECT a FROM copying_bug");
      mysql_stmt_execute(st);

      mysql_stmt_bind_result(st, &bind);

      mysql_stmt_fetch(st);

      printf("Value is: %d, (copied)size is %d\n", val, bind.length_value);

      mysql_stmt_close(st);

      mysql_query(ma, "DROP TABLE IF EXISTS `copying_bug`");

      Attachments

        Activity

          People

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