Skip to content

Commit d813415

Browse files
committed
Bug#36005903 mgmapi failure to parse bindadress
Problem: Trying to start ndb_mgmd with --bind-address=localhost fails with error "Illegal bind address". This error is returned from the MgmApi when parsing the bind address to split it into a host and port part. $> ndb_mgmd --bind-address=localhost MySQL Cluster Management Server mysql-8.3.0 ndb-8.3.0 2023-11-13 15:25:05 [MgmtSrvr] ERROR -- Illegal bind address Analysis: The portnumber is parsed using strtol() and the errno value is examined. The empty string cause EINVAL and thus parsing is handled as failure. Solution: Using errno is known to be fragile and is not really neccessary to sufficently parse the number. Remove usage of errno in order to accept the valid bind address "localhost" as well as more or less any string on the form "<hostname>:<number>". Max and min value checks are left in place. Also unrelated fix of missing argument names in doxygen comment. Change-Id: I177164fdc889ec4a1f5568e7064190babee6dd13
1 parent 82e441c commit d813415

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

storage/ndb/src/mgmapi/mgmapi-t.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <mgmapi/mgmapi.h>
2828
#include <mgmapi/mgmapi_debug.h>
2929
#include "mgmapi_internal.h"
30+
#include "mgmcommon/NdbMgm.hpp"
3031

3132
TAPTEST(mgmapi) {
3233
// Check behaviour of error translation functions with NULL handle
@@ -128,5 +129,18 @@ TAPTEST(mgmapi) {
128129
// Destroy handle
129130
ndb_mgm_destroy_handle(&h);
130131

132+
// Check parsing of bind address, with and without port
133+
// Neither bindaddress or port is possible to check, only return code
134+
{
135+
ndb_mgm::handle_ptr handle(ndb_mgm_create_handle());
136+
OK(ndb_mgm_set_bindaddress(handle.get(), "localhost") == 0);
137+
OK(ndb_mgm_set_bindaddress(handle.get(), "localhost:12345") == 0);
138+
// Illegal values
139+
OK(ndb_mgm_set_bindaddress(handle.get(), "localhost:65536") == -1);
140+
OK(ndb_mgm_set_bindaddress(handle.get(), "localhost:-5") == -1);
141+
OK(ndb_mgm_set_bindaddress(handle.get(), "localhost:mysql") == -1);
142+
OK(ndb_mgm_set_bindaddress(handle.get(), "localhost:2147483648") == -1);
143+
OK(ndb_mgm_set_bindaddress(handle.get(), "localhost:-2147483649") == -1);
144+
}
131145
return 1; // OK
132146
}

storage/ndb/src/mgmapi/mgmapi.cpp

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -279,18 +279,17 @@ extern "C" int ndb_mgm_set_connectstring(NdbMgmHandle handle,
279279
extern "C" int ndb_mgm_set_bindaddress(NdbMgmHandle handle, const char *arg) {
280280
DBUG_ENTER("ndb_mgm_set_bindaddress");
281281
free(handle->m_bindaddress);
282+
handle->m_bindaddress = nullptr;
283+
handle->m_bindaddress_port = 0;
282284

283285
if (arg) {
284286
char hostbuf[NI_MAXHOST];
285287
char servbuf[NI_MAXSERV];
286288
if (Ndb_split_string_address_port(arg, hostbuf, sizeof(hostbuf), servbuf,
287289
sizeof(servbuf)) == 0) {
288290
char *endp = nullptr;
289-
errno = 0;
290291
long val = strtol(servbuf, &endp, 10);
291-
292-
if ((errno == ERANGE && (val == LONG_MAX || val == LONG_MIN)) ||
293-
(errno != 0) || (*endp != '\0') || (val > UINT16_MAX) || (val < 0)) {
292+
if (*endp != '\0' || val > UINT16_MAX || val < 0) {
294293
// invalid address
295294
SET_ERROR(handle, NDB_MGM_ILLEGAL_BIND_ADDRESS, "Illegal bind address");
296295
DBUG_RETURN(-1);
@@ -303,9 +302,6 @@ extern "C" int ndb_mgm_set_bindaddress(NdbMgmHandle handle, const char *arg) {
303302
SET_ERROR(handle, NDB_MGM_ILLEGAL_BIND_ADDRESS, "Illegal bind address");
304303
DBUG_RETURN(-1);
305304
}
306-
} else {
307-
handle->m_bindaddress = nullptr;
308-
handle->m_bindaddress_port = 0;
309305
}
310306
if (handle->cfg.ids.size() != 0) {
311307
handle->cfg.bind_address_port = handle->m_bindaddress_port;
@@ -400,11 +396,11 @@ extern "C" const char *ndb_mgm_get_latest_error_msg(const NdbMgmHandle h) {
400396
ndb_mgmd.
401397
Read and return result
402398
403-
@param The mgmapi handle
404-
@param List describing the expected reply
405-
@param Name of the command to call
406-
@param Arguments for the command
407-
@param Any bulk data to send after the command
399+
@param handle The mgmapi handle
400+
@param command_reply List describing the expected reply
401+
@param cmd Name of the command to call
402+
@param cmd_args Arguments for the command
403+
@param cmd_bulk Any bulk data to send after the command
408404
409405
*/
410406
static const Properties *ndb_mgm_call(

0 commit comments

Comments
 (0)