Details
-
New Feature
-
Status: Closed (View Workflow)
-
Major
-
Resolution: Fixed
-
3.3, 3.4
-
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. 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.
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 (macros in a public header):
#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 */ |