0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-15 22:41:12 +01:00

authd: fix auth->cid type sizes

* long is too small on 32-bit systems, use unsigned long long if we want
  to check for out of range values
* UINT32_MAX is a valid cid, and 0 isn't
* make auth->cid a uint32_t not uint16_t
This commit is contained in:
Simon Arlott 2016-05-01 11:12:34 +01:00
parent a4da4fe574
commit 2392770f4d
No known key found for this signature in database
GPG key ID: C8975F2043CA5D24
3 changed files with 12 additions and 11 deletions

View file

@ -53,7 +53,7 @@ static void
handle_stat(int parc, char *parv[]) handle_stat(int parc, char *parv[])
{ {
authd_stat_handler handler; authd_stat_handler handler;
long lrid; unsigned long long rid;
if(parc < 3) if(parc < 3)
{ {
@ -61,16 +61,16 @@ handle_stat(int parc, char *parv[])
return; return;
} }
if((lrid = strtol(parv[1], NULL, 16)) > UINT32_MAX) if((rid = strtoull(parv[1], NULL, 16)) > UINT32_MAX)
{ {
warn_opers(L_CRIT, "BUG: handle_stat got a rid that was too large: %lx", lrid); warn_opers(L_CRIT, "BUG: handle_stat got a rid that was too large: %s", parv[1]);
return; return;
} }
if (!(handler = authd_stat_handlers[(unsigned char)parv[2][0]])) if (!(handler = authd_stat_handlers[(unsigned char)parv[2][0]]))
return; return;
handler((uint32_t)lrid, parv[2][0]); handler((uint32_t)rid, parv[2][0]);
} }
static void static void

View file

@ -280,10 +280,10 @@ static void
start_auth(const char *cid, const char *l_ip, const char *l_port, const char *c_ip, const char *c_port) start_auth(const char *cid, const char *l_ip, const char *l_port, const char *c_ip, const char *c_port)
{ {
struct auth_client *auth; struct auth_client *auth;
long lcid = strtol(cid, NULL, 16); unsigned long long lcid = strtoull(cid, NULL, 16);
rb_dlink_node *ptr; rb_dlink_node *ptr;
if(lcid >= UINT32_MAX) if(lcid == 0 || lcid > UINT32_MAX)
return; return;
auth = rb_malloc(sizeof(struct auth_client)); auth = rb_malloc(sizeof(struct auth_client));
@ -293,7 +293,7 @@ start_auth(const char *cid, const char *l_ip, const char *l_port, const char *c_
rb_dictionary_add(auth_clients, RB_UINT_TO_POINTER(auth->cid), auth); rb_dictionary_add(auth_clients, RB_UINT_TO_POINTER(auth->cid), auth);
else else
{ {
warn_opers(L_CRIT, "provider: duplicate client added via start_auth: %x", auth->cid); warn_opers(L_CRIT, "provider: duplicate client added via start_auth: %s", cid);
exit(EX_PROVIDER_ERROR); exit(EX_PROVIDER_ERROR);
} }
@ -357,7 +357,7 @@ void
handle_cancel_connection(int parc, char *parv[]) handle_cancel_connection(int parc, char *parv[])
{ {
struct auth_client *auth; struct auth_client *auth;
long lcid; unsigned long long lcid;
if(parc < 2) if(parc < 2)
{ {
@ -365,9 +365,10 @@ handle_cancel_connection(int parc, char *parv[])
exit(EX_PROVIDER_ERROR); exit(EX_PROVIDER_ERROR);
} }
if((lcid = strtol(parv[1], NULL, 16)) > UINT32_MAX) lcid = strtoull(parv[1], NULL, 16);
if(lcid == 0 || lcid > UINT32_MAX)
{ {
warn_opers(L_CRIT, "provider: got a request to cancel a connection that can't exist: %lx", lcid); warn_opers(L_CRIT, "provider: got a request to cancel a connection that can't exist: %s", parv[1]);
exit(EX_PROVIDER_ERROR); exit(EX_PROVIDER_ERROR);
} }

View file

@ -44,7 +44,7 @@ struct auth_client_data
struct auth_client struct auth_client
{ {
uint16_t cid; /* Client ID */ uint32_t cid; /* Client ID */
char l_ip[HOSTIPLEN + 1]; /* Listener IP address */ char l_ip[HOSTIPLEN + 1]; /* Listener IP address */
uint16_t l_port; /* Listener port */ uint16_t l_port; /* Listener port */