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

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Minor
    • Resolution: Not a Bug
    • Affects Version/s: None
    • Fix Version/s: N/A
    • Labels:
      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

            Assignee:
            georg Georg Richter
            Reporter:
            Lawrin Lawrin Novitsky
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: