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

New API function: mariadb_net_field_length

    XMLWordPrintable

Details

    • New Feature
    • Status: Open (View Workflow)
    • Major
    • Resolution: Unresolved
    • 3.3, 3.4
    • None
    • API
    • None

    Description

      mysql_net_field_length() is a public function that decodes length-encoded integers from raw protocol data. It has no way to know where the buffer ends, so it cannot reject truncated or invalid input. It also treats 0xFF as a 254 prefix, returns the NULL_LENGTH sentinel for 0xFB (a value that differs between platforms because ulong is 32-bit on Windows), and returns ulong. Connectors that parse raw row data, for example in a STMT_ATTR_CB_RESULT_EX callback (CONC-860), have no bounds-checked decoder available and each have to write their own.

      This request adds a public, bounds-checked decoder so connectors can use one shared implementation.

      Proposed API

      int STDCALL mariadb_net_field_length(unsigned char **pos,
                                           const unsigned char *end,
                                           unsigned int flags,
                                           unsigned long long *len);
      

      Parameters:

      • pos: in/out. Start of the length-encoded integer. Advanced past the prefix on MARIADB_LENENC_OK and MARIADB_LENENC_NULL. Unchanged on error.
      • end: first byte after the valid buffer. Never read.
      • flags: 0 or MARIADB_LENENC_FORBID_NULL. Unknown flag bits return MARIADB_LENENC_ERROR.
      • len: out. Decoded 64-bit value. Set to 0 for MARIADB_LENENC_NULL. Unchanged on error.

      Return values:

      #define MARIADB_LENENC_OK     0  /* length decoded, *pos advanced */
      #define MARIADB_LENENC_NULL   1  /* 0xFB with MARIADB_LENENC_TEXT, *pos advanced by 1 */
      #define MARIADB_LENENC_ERROR  2  /* truncated or invalid prefix, nothing changed */
      

      The function never reads outside [*pos, end). The caller must still compare *len with end - *pos before using it as a payload length, and before narrowing to size_t or ulong.

      Attachments

        Issue Links

          Activity

            People

              georg Georg Richter
              georg Georg Richter
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:

                Git Integration

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