Bug #42268 MYSQL::server_capabilities is 16-bit in the protocol, but 32-bit in the library
Submitted: 22 Jan 2009 13:15 Modified: 27 Feb 2013 13:19
Reporter: Alexander Nozdrin Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: C API (client library) Severity:S2 (Serious)
Version:5.0+ OS:Any
Assigned to: Assigned Account CPU Architecture:Any

[22 Jan 2009 13:15] Alexander Nozdrin
Description:
The MYSQL::server_capabilities attribute is defined as a 32-bit integer:

  unsigned long server_capabilities;

In the client-server protocol it is handled as a 16-bit integer:

  mysql->server_capabilities=uint2korr(end);
  int2store(end, server_capabilites);

The following bitmasks are defined to be identify server capabilities:
#define CLIENT_LONG_PASSWORD    1
#define CLIENT_FOUND_ROWS    2
#define CLIENT_LONG_FLAG    4
#define CLIENT_CONNECT_WITH_DB    8
#define CLIENT_NO_SCHEMA    16
#define CLIENT_COMPRESS        32
#define CLIENT_ODBC        64
#define CLIENT_LOCAL_FILES    128
#define CLIENT_IGNORE_SPACE    256
#define CLIENT_PROTOCOL_41    512
#define CLIENT_INTERACTIVE    1024
#define CLIENT_SSL              2048
#define CLIENT_IGNORE_SIGPIPE   4096
#define CLIENT_TRANSACTIONS    8192
#define CLIENT_RESERVED         16384
#define CLIENT_SECURE_CONNECTION 32768
#define CLIENT_MULTI_STATEMENTS (1UL << 16)
#define CLIENT_MULTI_RESULTS    (1UL << 17)
#define CLIENT_PS_MULTI_RESULTS (1UL << 18)

So, we use 16, 17, 18 bit of 16-bit integer.
The last two attributes were added in scope of WL#4435,
but CLIENT_MULTI_STATEMENTS was added for supporting 4.1 protocol
and exists even in 5.0.

It looks like it works on i386 (x86) architecture, because uint2korr()
does nothing on x86. The problem should appear on SPARC architecture.

How to repeat:
Analyze the code.
[4 May 2009 18:25] Jim Winstead
This is not actually a problem for clients, but some comments need to be added to the code to clarify what CLIENT_* flags are used by the server to signal what it is capable of, and what are only meant to tell the server what the client wants to do. In the case of CLIENT_MULTI_*, they are purely used for signaling from the client to server.

We are out of bits to indicate to the client that the server is capable of something. Rectifying this is going to require a protocol change, and it makes sense to do this as a real protocol upgrade instead of trying to just jam more into the existing one.
[27 Feb 2013 13:19] Erlend Dahl
This was fixed in 5.5.7.

Current protocol supports 32 capability flags - see
http://dev.mysql.com/doc/internals/en/connection-phase.html#packet-Protocol::Handshake